Change to make punch remove the plant first (#18)
This fixes item loss when the pot loses its node underneath and is converted to dropped items.
This commit is contained in:
parent
2535483e85
commit
1bf935c33d
24
init.lua
24
init.lua
@ -68,7 +68,13 @@ function minetest.get_node_drops(node, toolname)
|
|||||||
if node_name then
|
if node_name then
|
||||||
local flower_item = flower_items_by_pot[node_name]
|
local flower_item = flower_items_by_pot[node_name]
|
||||||
if flower_item then
|
if flower_item then
|
||||||
return old_get_node_drops(flower_item, toolname)
|
local drops = old_get_node_drops(flower_item, toolname)
|
||||||
|
if drops then
|
||||||
|
table.insert(drops, "flowerpot:empty")
|
||||||
|
return drops
|
||||||
|
else
|
||||||
|
return { "flowerpot:empty" }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -123,7 +129,21 @@ function flowerpot.register_node(nodename)
|
|||||||
groups = {attached_node = 1, oddly_breakable_by_hand = 1, snappy = 3, not_in_creative_inventory = 1},
|
groups = {attached_node = 1, oddly_breakable_by_hand = 1, snappy = 3, not_in_creative_inventory = 1},
|
||||||
flowerpot_plantname = nodename,
|
flowerpot_plantname = nodename,
|
||||||
node_dig_prediction = "flowerpot:empty",
|
node_dig_prediction = "flowerpot:empty",
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
|
if not (puncher and puncher:is_player()) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if minetest.is_protected(pos, puncher:get_player_name()) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local toolname = puncher:get_wielded_item()
|
||||||
|
if node.name then
|
||||||
|
local flower_item = flower_items_by_pot[node.name]
|
||||||
|
if flower_item then
|
||||||
|
local drops = old_get_node_drops(flower_item, toolname)
|
||||||
|
minetest.handle_node_drops(pos, drops, puncher)
|
||||||
|
end
|
||||||
|
end
|
||||||
minetest.swap_node(pos, {name = "flowerpot:empty"})
|
minetest.swap_node(pos, {name = "flowerpot:empty"})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user