summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorh-v-smacker <hans-von-smacker+github@gmail.com>2018-11-20 00:29:22 +0300
committerh-v-smacker <hans-von-smacker+github@gmail.com>2018-11-20 00:29:22 +0300
commit720e99438aaae00c4e0ae9fe07fd823196710080 (patch)
treed06f4eecead94819d1fdc3d9b47a45333e310bae
parent7eed764e9ccd126be28307091e2472a9b728a3b6 (diff)
shelf protection
-rw-r--r--nodes_furniture.lua73
1 files changed, 43 insertions, 30 deletions
diff --git a/nodes_furniture.lua b/nodes_furniture.lua
index b7ae080..dff953c 100644
--- a/nodes_furniture.lua
+++ b/nodes_furniture.lua
@@ -261,38 +261,51 @@ minetest.register_node("cottages:shelf", {
},
on_construct = function(pos)
-
- local meta = minetest.get_meta(pos);
-
- meta:set_string("formspec",
- "size[8,8]"..
- "list[context;main;0,0;8,3;]"..
- "list[current_player;main;0,4;8,4;]")
- meta:set_string("infotext", S("open storage shelf"))
- local inv = meta:get_inventory();
- inv:set_size("main", 24);
- 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_put = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta( pos );
- meta:set_string('infotext', S('open storage shelf (in use)'));
- end,
- on_metadata_inventory_take = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta( pos );
- local inv = meta:get_inventory();
- if( inv:is_empty("main")) then
- meta:set_string('infotext', S('open storage shelf (empty)'));
- end
- end,
+ local meta = minetest.get_meta(pos);
+ meta:set_string("formspec",
+ "size[8,8]"..
+ "list[context;main;0,0;8,3;]"..
+ "list[current_player;main;0,4;8,4;]")
+ meta:set_string("infotext", S("open storage shelf"))
+ local inv = meta:get_inventory();
+ inv:set_size("main", 24);
+ end,
+
+ can_dig = function(pos, player)
+ if minetest.is_protected(pos, player:get_player_name()) then
+ return false
+ end
+ local meta = minetest.get_meta( pos );
+ local inv = meta:get_inventory();
+ return inv:is_empty("main");
+ end,
+
+ allow_metadata_inventory_put = function(pos, listname, index, stack, player)
+ if minetest.is_protected(pos, player:get_player_name()) then
+ return 0
+ end
+ return stack:get_count()
+ end,
+ allow_metadata_inventory_take = function(pos, listname, index, stack, player)
+ if minetest.is_protected(pos, player:get_player_name()) then
+ return 0
+ end
+ return stack:get_count()
+ end,
+
+ on_metadata_inventory_put = function(pos, listname, index, stack, player)
+ local meta = minetest.get_meta( pos );
+ meta:set_string('infotext', S('Open storage shelf (in use)'));
+ end,
+ on_metadata_inventory_take = function(pos, listname, index, stack, player)
+ local meta = minetest.get_meta( pos );
+ local inv = meta:get_inventory();
+ if( inv:is_empty("main")) then
+ meta:set_string('infotext', S('Open storage shelf (empty)'));
+ end
+ end,
is_ground_content = false,
-
})
-- so that the smoke from a furnace can get out of a building