mirror of
https://github.com/mt-mods/homedecor_modpack.git
synced 2024-12-23 08:20:21 +01:00
simplify trash can code and limit the inventory size to the displayed one
This commit is contained in:
parent
8a91865d82
commit
a6ffd1f3c6
@ -30,39 +30,18 @@ homedecor.register("trash_can_green_open", {
|
|||||||
on_punch = function(pos, node, puncher, pointed_thing)
|
on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
minetest.set_node(pos, {name = "homedecor:trash_can_green", param2 = node.param2})
|
minetest.set_node(pos, {name = "homedecor:trash_can_green", param2 = node.param2})
|
||||||
end,
|
end,
|
||||||
on_construct = function(pos)
|
infotext="Trash Can",
|
||||||
local meta = minetest.get_meta(pos)
|
inventory= {
|
||||||
meta:set_string("formspec",
|
size = 9,
|
||||||
"size[8,9]".. default.gui_bg .. default.gui_bg_img .. default.gui_slots ..
|
formspec = "size[8,9]" .. default.gui_bg .. default.gui_bg_img .. default.gui_slots ..
|
||||||
"button[2.5,3.8;3,1;empty;Empty Trash]"..
|
"button[2.5,3.8;3,1;empty;Empty Trash]"..
|
||||||
"list[current_name;main;2.5,0.5;3,3;]"..
|
"list[context;main;2.5,0.5;3,3;]"..
|
||||||
"list[current_player;main;0,5;8,4;]")
|
"list[current_player;main;0,5;8,4;]",
|
||||||
meta:set_string("infotext", "Trash Can")
|
},
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 8*4)
|
|
||||||
end,
|
|
||||||
can_dig = function(pos,player)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return inv:is_empty("main")
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff in trash can at "..minetest.pos_to_string(pos))
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff in trash can at "..minetest.pos_to_string(pos))
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" takes stuff from trash can at "..minetest.pos_to_string(pos))
|
|
||||||
end,
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
if fields.empty then
|
if fields.empty then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
meta:get_inventory():set_list("main", {})
|
||||||
inv:set_list("main", {})
|
|
||||||
minetest.sound_play("homedecor_trash_all", {to_player=sender:get_player_name(), gain = 1.0})
|
minetest.sound_play("homedecor_trash_all", {to_player=sender:get_player_name(), gain = 1.0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user