Bucket: Correct liquid placing in protected areas
- Placing liquid inside a protected area no longer returns an empty bucket - Remove on_place function, tidy up code, return proper itemstack - Shorten code (changes from HybridDog/patch-35)
This commit is contained in:
parent
80d49095f5
commit
21b457c9e1
@ -52,6 +52,7 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
|
|||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
liquids_pointable = true,
|
liquids_pointable = true,
|
||||||
groups = groups,
|
groups = groups,
|
||||||
|
|
||||||
on_place = function(itemstack, user, pointed_thing)
|
on_place = function(itemstack, user, pointed_thing)
|
||||||
-- Must be pointing to node
|
-- Must be pointing to node
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
@ -59,47 +60,49 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
|
|||||||
end
|
end
|
||||||
|
|
||||||
local node = minetest.get_node_or_nil(pointed_thing.under)
|
local node = minetest.get_node_or_nil(pointed_thing.under)
|
||||||
local ndef
|
if not node then
|
||||||
if node then
|
return
|
||||||
ndef = minetest.registered_nodes[node.name]
|
|
||||||
end
|
end
|
||||||
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
|
if not ndef then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Call on_rightclick if the pointed node defines it
|
-- Call on_rightclick if the pointed node defines it
|
||||||
if ndef and ndef.on_rightclick and
|
if ndef.on_rightclick and
|
||||||
user and not user:get_player_control().sneak then
|
user and not user:get_player_control().sneak then
|
||||||
return ndef.on_rightclick(
|
return ndef.on_rightclick(
|
||||||
pointed_thing.under,
|
pointed_thing.under,
|
||||||
node, user,
|
node, user,
|
||||||
itemstack) or itemstack
|
itemstack)
|
||||||
end
|
end
|
||||||
|
|
||||||
local place_liquid = function(pos, node, source, flowing)
|
local lpos
|
||||||
if check_protection(pos,
|
|
||||||
user and user:get_player_name() or "",
|
|
||||||
"place "..source) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
minetest.add_node(pos, {name=source})
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check if pointing to a buildable node
|
-- Check if pointing to a buildable node
|
||||||
if ndef and ndef.buildable_to then
|
if ndef.buildable_to then
|
||||||
-- buildable; replace the node
|
-- buildable; replace the node
|
||||||
place_liquid(pointed_thing.under, node,
|
lpos = pointed_thing.under
|
||||||
source, flowing)
|
|
||||||
else
|
else
|
||||||
-- not buildable to; place the liquid above
|
-- not buildable to; place the liquid above
|
||||||
-- check if the node above can be replaced
|
-- check if the node above can be replaced
|
||||||
local node = minetest.get_node_or_nil(pointed_thing.above)
|
lpos = pointed_thing.above
|
||||||
if node and minetest.registered_nodes[node.name].buildable_to then
|
local node = minetest.get_node_or_nil(lpos)
|
||||||
place_liquid(pointed_thing.above,
|
if not node
|
||||||
node, source,
|
or not minetest.registered_nodes[node.name].buildable_to then
|
||||||
flowing)
|
|
||||||
else
|
|
||||||
-- do not remove the bucket with the liquid
|
-- do not remove the bucket with the liquid
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return {name="bucket:bucket_empty"}
|
|
||||||
|
if check_protection(lpos, user
|
||||||
|
and user:get_player_name()
|
||||||
|
or "", "place "..source) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.set_node(lpos, {name = source})
|
||||||
|
return ItemStack("bucket:bucket_empty")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user