mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-22 15:00:18 +01:00
Log bucket liquid placement (#3108)
This commit is contained in:
parent
a43a6bcdef
commit
0639681f9b
@ -33,6 +33,11 @@ local function check_protection(pos, name, text)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function log_action(pos, name, action)
|
||||||
|
minetest.log("action", (name ~= "" and name or "A mod")
|
||||||
|
.. " " .. action .. " at " .. minetest.pos_to_string(pos) .. " with a bucket")
|
||||||
|
end
|
||||||
|
|
||||||
-- Register a new liquid
|
-- Register a new liquid
|
||||||
-- source = name of the source node
|
-- source = name of the source node
|
||||||
-- flowing = name of the flowing node
|
-- flowing = name of the flowing node
|
||||||
@ -101,13 +106,13 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if check_protection(lpos, user
|
local pname = user and user:get_player_name() or ""
|
||||||
and user:get_player_name()
|
if check_protection(lpos, pname, "place "..source) then
|
||||||
or "", "place "..source) then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.set_node(lpos, {name = source})
|
minetest.set_node(lpos, {name = source})
|
||||||
|
log_action(lpos, pname, "placed " .. source)
|
||||||
return ItemStack("bucket:bucket_empty")
|
return ItemStack("bucket:bucket_empty")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -128,16 +133,16 @@ minetest.register_craftitem("bucket:bucket_empty", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Check if pointing to a liquid source
|
-- Check if pointing to a liquid source
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
local pos = pointed_thing.under
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
local liquiddef = bucket.liquids[node.name]
|
local liquiddef = bucket.liquids[node.name]
|
||||||
local item_count = user:get_wielded_item():get_count()
|
local item_count = user:get_wielded_item():get_count()
|
||||||
|
|
||||||
if liquiddef ~= nil
|
if liquiddef ~= nil
|
||||||
and liquiddef.itemname ~= nil
|
and liquiddef.itemname ~= nil
|
||||||
and node.name == liquiddef.source then
|
and node.name == liquiddef.source then
|
||||||
if check_protection(pointed_thing.under,
|
local pname = user:get_player_name()
|
||||||
user:get_player_name(),
|
if check_protection(pos, pname, "take ".. node.name) then
|
||||||
"take ".. node.name) then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -152,9 +157,9 @@ minetest.register_craftitem("bucket:bucket_empty", {
|
|||||||
if inv:room_for_item("main", {name=liquiddef.itemname}) then
|
if inv:room_for_item("main", {name=liquiddef.itemname}) then
|
||||||
inv:add_item("main", liquiddef.itemname)
|
inv:add_item("main", liquiddef.itemname)
|
||||||
else
|
else
|
||||||
local pos = user:get_pos()
|
local upos = user:get_pos()
|
||||||
pos.y = math.floor(pos.y + 0.5)
|
upos.y = math.floor(upos.y + 0.5)
|
||||||
minetest.add_item(pos, liquiddef.itemname)
|
minetest.add_item(upos, liquiddef.itemname)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set to return empty buckets minus 1
|
-- set to return empty buckets minus 1
|
||||||
@ -166,10 +171,13 @@ minetest.register_craftitem("bucket:bucket_empty", {
|
|||||||
local source_neighbor = false
|
local source_neighbor = false
|
||||||
if liquiddef.force_renew then
|
if liquiddef.force_renew then
|
||||||
source_neighbor =
|
source_neighbor =
|
||||||
minetest.find_node_near(pointed_thing.under, 1, liquiddef.source)
|
minetest.find_node_near(pos, 1, liquiddef.source)
|
||||||
end
|
end
|
||||||
if not (source_neighbor and liquiddef.force_renew) then
|
if source_neighbor and liquiddef.force_renew then
|
||||||
minetest.add_node(pointed_thing.under, {name = "air"})
|
log_action(pos, pname, "picked up " .. liquiddef.source .. " (force renewed)")
|
||||||
|
else
|
||||||
|
minetest.add_node(pos, {name = "air"})
|
||||||
|
log_action(pos, pname, "picked up " .. liquiddef.source)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ItemStack(giving_back)
|
return ItemStack(giving_back)
|
||||||
@ -177,7 +185,7 @@ minetest.register_craftitem("bucket:bucket_empty", {
|
|||||||
-- non-liquid nodes will have their on_punch triggered
|
-- non-liquid nodes will have their on_punch triggered
|
||||||
local node_def = minetest.registered_nodes[node.name]
|
local node_def = minetest.registered_nodes[node.name]
|
||||||
if node_def then
|
if node_def then
|
||||||
node_def.on_punch(pointed_thing.under, node, user, pointed_thing)
|
node_def.on_punch(pos, node, user, pointed_thing)
|
||||||
end
|
end
|
||||||
return user:get_wielded_item()
|
return user:get_wielded_item()
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user