mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-23 00:19:32 +01:00
Make hopper drop contents after digging
This commit is contained in:
parent
eb128cb4c1
commit
c7333c0b82
1 changed files with 24 additions and 6 deletions
|
@ -42,10 +42,19 @@ minetest.register_node("hopper:hopper", {
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 5)
|
inv:set_size("main", 5)
|
||||||
end,
|
end,
|
||||||
can_dig = function(pos,player)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos)
|
||||||
|
local meta2 = meta
|
||||||
|
meta:from_table(oldmetadata)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
return inv:is_empty("main")
|
for i=1,inv:get_size("main") do
|
||||||
|
local stack = inv:get_stack("main", i)
|
||||||
|
if not stack:is_empty() then
|
||||||
|
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||||
|
minetest.add_item(p, stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
meta:from_table(meta2:to_table())
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
minetest.log("action", player:get_player_name()..
|
minetest.log("action", player:get_player_name()..
|
||||||
|
@ -93,10 +102,19 @@ minetest.register_node("hopper:hopper_side", {
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 5)
|
inv:set_size("main", 5)
|
||||||
end,
|
end,
|
||||||
can_dig = function(pos,player)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos)
|
||||||
|
local meta2 = meta
|
||||||
|
meta:from_table(oldmetadata)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
return inv:is_empty("main")
|
for i=1,inv:get_size("main") do
|
||||||
|
local stack = inv:get_stack("main", i)
|
||||||
|
if not stack:is_empty() then
|
||||||
|
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
||||||
|
minetest.add_item(p, stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
meta:from_table(meta2:to_table())
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
minetest.log("action", player:get_player_name()..
|
minetest.log("action", player:get_player_name()..
|
||||||
|
|
Loading…
Reference in a new issue