Differences From
Artifact [64df297e83]:
1 +local constants = {
2 + keg_volume = sorcery.liquid.constants.glasses_per_bottle * 600
3 +}
4 +
1 5 local hitbox = {
2 6 type = 'fixed';
3 7 fixed = {
4 8 -0.4, -0.5, -0.5;
5 9 0.4, 0.2, 0.5;
6 10 };
7 11 }
8 12 local kegcaption = function(m)
9 13 local liqid = m:get_string('liquid')
10 14 if liqid ~= '' then
11 15 local liq = sorcery.register.liquid.db[liqid]
12 16 if not liq then log.err('missing entry for liquid',liqid) return end
13 - local measure = liq.measure or function(u)
14 - return string.format('%s drams', u*63.9)
15 - end
16 -
17 17 return {
18 18 title = string.format('%s Keg', sorcery.lib.str.capitalize(liq.name));
19 19 color = sorcery.lib.color(liq.color);
20 - desc = string.format('%s of %s', measure(m:get_int('charge')), liq.name);
20 + desc = string.format('%s of %s', liq.measure(m:get_int('charge')), liq.name);
21 21 };
22 22 else return { title = 'Empty Keg', props = {} } end
23 23 end
24 24 local log = sorcery.logger('keg')
25 25 minetest.register_node('sorcery:keg', {
26 26 description = 'Keg';
27 27 drawtype = 'mesh';
................................................................................
53 53 m:set_string('short_description', cap.title)
54 54 end
55 55 end;
56 56 after_place_node = function(pos, placer, stack, tgt)
57 57 local meta = minetest.get_meta(pos)
58 58 local stackmeta = stack:get_meta()
59 59 meta:from_table(stackmeta:to_table())
60 - end;
61 - on_construct = function(pos)
62 - local m = minetest.get_meta(pos)
63 - m:set_string('infotext', 'Empty Keg')
60 + if not meta:contains('infotext') then
61 + meta:set_string('infotext', 'Empty Keg')
62 + end
64 63 end;
65 64 on_rightclick = function(pos, node, user, stack)
66 65 local m = minetest.get_meta(pos)
67 66 local update = function()
68 67 local c = kegcaption(m)
69 68 local str = c.title
70 69 if c.desc then str = str .. '\n(' .. c.desc .. ')' end
71 70 if c.props then for _,p in pairs(c.props) do -- future-proofing
72 71 str = str .. string.format('\n(%s: %s)', p.title, p.desc)
73 72 end end
74 73 m:set_string('infotext', str)
75 74 end
76 - local noise = function(amt)
77 - minetest.sound_play('default_water_footstep', {
78 - gain = 0.5 + amt / 9.0;
79 - pitch = 1.3 - amt / 12.0;
80 - pos = pos;
81 - }, true)
82 - end
83 75
84 76 if stack:is_empty() then return end
85 77
86 78 local ctr = sorcery.itemclass.get(stack, 'container')
87 79 if (not ctr) or not ctr.hold == 'liquid' then return end
88 80
89 - if ctr.has and
90 - (m:get_string('liquid') == ctr.has or not m:contains('liquid')) then
81 + local liqid = m:get_string('liquid')
82 + if ctr.has and -- add liquid to keg
83 + (liqid == ctr.has or not m:contains('liquid')) then
91 84 if not ctr.empty then log.err(stack:get_name(), 'does not specify its empty counterpart container') return end
92 -
93 85
94 86 local add = ctr.charge * stack:get_count()
95 87 local chg = m:get_int('charge')
88 + if chg + add > constants.keg_volume then
89 + log.act(string.format('%s tried to overfill a %s keg at %s',
90 + user:get_player_name(),
91 + ctr.has, minetest.pos_to_string(pos)))
92 + return
93 + end
96 94 m:set_int('charge', chg + add)
97 95 m:set_string('liquid', ctr.has)
98 - noise(chg + add)
96 + sorcery.liquid.sound_pour(add,chg,pos)
99 97
100 98 local liq = sorcery.register.liquid.db[ctr.has]
101 99 if liq then
102 100 update()
103 - log.act(string.format('%s added %u units of %s to a keg', user:get_player_name(), add, ctr.has))
101 + log.act(string.format('%s added %u units of %s to a keg at %s',
102 + user:get_player_name(), add,
103 + ctr.has, minetest.pos_to_string(pos)))
104 104 else log.err('no liquid entry for',ctr.has) end
105 105
106 106 return ItemStack {
107 107 name = ctr.empty;
108 108 count = stack:get_count();
109 109 }
110 - elseif not ctr.has and m:get_string('liquid') ~= '' then
111 - local reg = sorcery.register.liquid.db[m:get_string('liquid')]
112 - if not reg then log.err('missing definition for liquid', m:get_string('liquid')) return end
110 + elseif not ctr.has and liqid ~= '' then -- take liquid
111 + local liq = sorcery.register.liquid.db[m:get_string('liquid')]
112 + if not liq then log.err('missing definition for liquid', liqid) return end
113 113
114 - local filled = reg.containers[stack:get_name()]
114 + local basin = m:get_int('charge')
115 + local filled, amtleft = sorcery.liquid.fill_from_basin(stack, liqid, basin)
115 116 if filled then
116 - local fs = sorcery.itemclass.get(filled, 'container')
117 - if not fs then log.err(filled,'is named as filled container but does not have the required itemclass definition') return end
118 - local chg = fs.charge * stack:get_count()
119 - local avail = m:get_int('charge')
120 -
121 - if avail >= chg then
122 - local liqid = m:get_string('liquid')
123 - local liq = sorcery.register.liquid.db[liqid]
124 - log.act(string.format('%s removed %u units of %s from a keg', user:get_player_name(), chg, liqid))
125 - if avail == chg then
126 - m:set_string('liquid','')
127 - m:set_int('charge',0)
128 - else m:set_int('charge', avail - chg) end
129 - noise(chg)
130 - update()
117 + local chg = basin - amtleft
118 + log.act(string.format('%s removed %u units of %s from a keg at %s',
119 + user:get_player_name(), chg, liqid,
120 + minetest.pos_to_string(pos)))
121 + if amtleft == 0 then
122 + m:set_string('liquid','')
123 + m:set_int('charge',0)
124 + else m:set_int('charge', amtleft) end
125 + sorcery.liquid.sound_dip(chg,avail,pos)
126 + update()
131 127
132 - -- fancy visuals
133 - local color = sorcery.lib.color(liq.color or {255,255,255})
134 - local spritz = sorcery.lib.image('sorcery_droplet.png')
135 - local drop = sorcery.lib.image('sorcery_drop.png')
136 - spritz = spritz:blit(spritz:multiply(color))
137 - drop = drop:blit (drop:multiply (color))
138 - local facing = minetest.facedir_to_dir(minetest.get_node(pos).param2)
139 - local noz = vector.add(pos, vector.rotate(
140 - vector.new(0.0,0,-0.48),
141 - vector.dir_to_rotation(facing)
142 - ))
143 - local minnoz = vector.offset(noz, -0.03, -0.32, -0.03);
144 - local maxnoz = vector.offset(noz, 0.03, -0.32, 0.03);
128 + -- fancy visuals
129 + local color = sorcery.lib.color(liq.color or {255,255,255})
130 + local spritz = sorcery.lib.image('sorcery_droplet.png')
131 + local drop = sorcery.lib.image('sorcery_drop.png')
132 + spritz = spritz:blit(spritz:multiply(color))
133 + drop = drop:blit (drop:multiply (color))
134 + local facing = minetest.facedir_to_dir(minetest.get_node(pos).param2)
135 + local noz = vector.add(pos, vector.rotate(
136 + vector.new(0.0,0,-0.48),
137 + vector.dir_to_rotation(facing)
138 + ))
139 + local minnoz = vector.offset(noz, -0.03, -0.32, -0.03);
140 + local maxnoz = vector.offset(noz, 0.03, -0.32, 0.03);
141 + minetest.add_particlespawner {
142 + amount = 15 * chg, time = 0.1*chg;
143 + texture = spritz:render();
144 + minpos = minnoz, maxpos = maxnoz;
145 + minvel = vector.new(0,0,0);
146 + maxvel = vector.new(0,-0.1,0);
147 + minacc = vector.new(0,-0.1,0);
148 + maxacc = vector.new(0,-0.13,0);
149 + minsize = 0.4, maxsize = 1;
150 + glow = 14; -- FIXME liquid glow prop
151 + minexptime = 0.5, maxexptime = 0.5;
152 + animation = {
153 + type = 'sheet_2d';
154 + frames_w = 14;
155 + frames_h = 1;
156 + frame_length = 0.5/14;
157 + }
158 + }
159 + minetest.after(0.2, function()
145 160 minetest.add_particlespawner {
146 - amount = 15 * chg, time = 0.4*chg;
147 - texture = spritz:render();
148 - minpos = minnoz, maxpos = maxnoz;
149 - minvel = vector.new(0,0,0);
150 - maxvel = vector.new(0,-0.1,0);
151 - minacc = vector.new(0,-0.1,0);
152 - maxacc = vector.new(0,-0.13,0);
153 - minsize = 0.4, maxsize = 1;
161 + amount = math.random(5,11) * chg, time = 0.13 * chg;
162 + texture = drop:render();
163 + minpos = vector.offset(minnoz, 0,-0.05,0);
164 + maxpos = vector.offset(maxnoz, 0,-0.05,0);
165 + minvel = vector.new(0,-0.1,0);
166 + maxvel = vector.new(0,-0.4,0);
167 + minacc = vector.new(0,-0.15,0);
168 + maxacc = vector.new(0,-0.18,0);
169 + minsize = 0.3, maxsize = 0.5;
154 170 glow = 14; -- FIXME liquid glow prop
155 - minexptime = 0.5, maxexptime = 0.5;
171 + minexptime = 1, maxexptime = 1.5;
156 172 animation = {
157 173 type = 'sheet_2d';
158 - frames_w = 14;
174 + frames_w = 10;
159 175 frames_h = 1;
160 - frame_length = 0.5/14;
176 + frame_length = 1.5/10;
161 177 }
162 178 }
163 - minetest.after(0.2, function()
164 - minetest.add_particlespawner {
165 - amount = math.random(5,11) * chg, time = 0.45 * chg;
166 - texture = drop:render();
167 - minpos = vector.offset(minnoz, 0,-0.05,0);
168 - maxpos = vector.offset(maxnoz, 0,-0.05,0);
169 - minvel = vector.new(0,-0.1,0);
170 - maxvel = vector.new(0,-0.4,0);
171 - minacc = vector.new(0,-0.15,0);
172 - maxacc = vector.new(0,-0.18,0);
173 - minsize = 0.3, maxsize = 0.5;
174 - glow = 14; -- FIXME liquid glow prop
175 - minexptime = 1, maxexptime = 1.5;
176 - animation = {
177 - type = 'sheet_2d';
178 - frames_w = 10;
179 - frames_h = 1;
180 - frame_length = 1.5/10;
181 - }
182 - }
183 - end)
179 + end)
184 180
185 - return ItemStack {
186 - name = filled;
187 - count = stack:get_count();
188 - }
189 - end
181 + return filled
190 182 end
191 -
192 183 end
193 184 end;
194 185 })
195 186
196 187 minetest.register_craft {
197 188 output = "sorcery:keg";
198 189 recipe = {
199 - {'', 'basic_materials:steel_bar', 'screwdriver:screwdriver'};
200 - {'sorcery:screw_bronze', 'default:bronze_ingot', 'sorcery:screw_bronze'};
190 + {'','screwdriver:screwdriver',''};
191 + {'sorcery:screw_bronze', 'sorcery:tap', 'sorcery:screw_bronze'};
201 192 {'', 'xdecor:barrel', ''};
202 193 };
203 194 replacements = {
204 195 {'screwdriver:screwdriver', 'screwdriver:screwdriver'};
205 196 };
206 197 }