Skip to content

Commit 4ea001f

Browse files
committedDec 14, 2013
Shorten lines in bucket and support nil placers
1 parent e8bcfdc commit 4ea001f

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed
 

‎mods/bucket/init.lua

+30-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bucket.liquids = {}
2020

2121
local function check_protection(pos, name, text)
2222
if minetest.is_protected(pos, name) then
23-
minetest.log("action", name
23+
minetest.log("action", (name ~= "" and name or "A mod")
2424
.. " tried to " .. text
2525
.. " at protected position "
2626
.. minetest.pos_to_string(pos)
@@ -62,19 +62,25 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
6262
if user and not user:get_player_control().sneak then
6363
local n = minetest.get_node(pointed_thing.under)
6464
local nn = n.name
65-
if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then
66-
return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, user, itemstack) or itemstack
65+
local ndef = minetest.registered_nodes[nn]
66+
if ndef and ndef.on_rightclick then
67+
return ndef.on_rightclick(
68+
pointed_thing.under,
69+
n, user,
70+
itemstack) or itemstack
6771
end
6872
end
6973

7074
local place_liquid = function(pos, node, source, flowing, fullness)
7175
if check_protection(pos,
72-
user:get_player_name(),
76+
user and user:get_player_name() or "",
7377
"place "..source) then
7478
return
7579
end
76-
if math.floor(fullness/128) == 1 or (not minetest.setting_getbool("liquid_finite")) then
77-
minetest.add_node(pos, {name=source, param2=fullness})
80+
if math.floor(fullness/128) == 1 or
81+
not minetest.setting_getbool("liquid_finite") then
82+
minetest.add_node(pos, {name=source,
83+
param2=fullness})
7884
return
7985
elseif node.name == flowing then
8086
fullness = fullness + node.param2
@@ -83,9 +89,11 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
8389
end
8490

8591
if fullness >= LIQUID_MAX then
86-
minetest.add_node(pos, {name=source, param2=LIQUID_MAX})
92+
minetest.add_node(pos, {name=source,
93+
param2=LIQUID_MAX})
8794
else
88-
minetest.add_node(pos, {name=flowing, param2=fullness})
95+
minetest.add_node(pos, {name=flowing,
96+
param2=fullness})
8997
end
9098
end
9199

@@ -96,13 +104,16 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
96104

97105
if minetest.registered_nodes[node.name].buildable_to then
98106
-- buildable; replace the node
99-
place_liquid(pointed_thing.under, node, source, flowing, fullness)
107+
place_liquid(pointed_thing.under, node,
108+
source, flowing, fullness)
100109
else
101110
-- not buildable to; place the liquid above
102111
-- check if the node above can be replaced
103112
local node = minetest.get_node(pointed_thing.above)
104113
if minetest.registered_nodes[node.name].buildable_to then
105-
place_liquid(pointed_thing.above, node, source, flowing, fullness)
114+
place_liquid(pointed_thing.above,
115+
node, source,
116+
flowing, fullness)
106117
else
107118
-- do not remove the bucket with the liquid
108119
return
@@ -127,9 +138,10 @@ minetest.register_craftitem("bucket:bucket_empty", {
127138
-- Check if pointing to a liquid source
128139
node = minetest.get_node(pointed_thing.under)
129140
liquiddef = bucket.liquids[node.name]
130-
if liquiddef ~= nil and liquiddef.itemname ~= nil and (node.name == liquiddef.source or
131-
(node.name == liquiddef.flowing and minetest.setting_getbool("liquid_finite"))) then
132-
141+
if liquiddef ~= nil and liquiddef.itemname ~= nil and
142+
(node.name == liquiddef.source or
143+
(node.name == liquiddef.flowing and
144+
minetest.setting_getbool("liquid_finite"))) then
133145
if check_protection(pointed_thing.under,
134146
user:get_player_name(),
135147
"take ".. node.name) then
@@ -138,8 +150,11 @@ minetest.register_craftitem("bucket:bucket_empty", {
138150

139151
minetest.add_node(pointed_thing.under, {name="air"})
140152

141-
if node.name == liquiddef.source then node.param2 = LIQUID_MAX end
142-
return ItemStack({name = liquiddef.itemname, metadata = tostring(node.param2)})
153+
if node.name == liquiddef.source then
154+
node.param2 = LIQUID_MAX
155+
end
156+
return ItemStack({name = liquiddef.itemname,
157+
metadata = tostring(node.param2)})
143158
end
144159
end,
145160
})

0 commit comments

Comments
 (0)
Please sign in to comment.