From 3e419ffb38df3f802ed30c5e114b8b3e8b7a6c1f Mon Sep 17 00:00:00 2001 From: darkrose Date: Sun, 3 Jun 2012 20:37:55 +1000 Subject: Add InvRef:is_empty(listname) and make chests/furnaces not diggable if not empty in minimal game --- games/minimal/mods/default/init.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'games/minimal/mods/default/init.lua') diff --git a/games/minimal/mods/default/init.lua b/games/minimal/mods/default/init.lua index 4468d1e0e..1ffe24837 100644 --- a/games/minimal/mods/default/init.lua +++ b/games/minimal/mods/default/init.lua @@ -1147,6 +1147,11 @@ minetest.register_node("default:chest", { local inv = meta:get_inventory() inv:set_size("main", 8*4) end, + can_dig = function(pos,player) + local meta = minetest.env: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().. @@ -1200,6 +1205,11 @@ minetest.register_node("default:chest_locked", { local inv = meta:get_inventory() inv:set_size("main", 8*4) end, + can_dig = function(pos,player) + local meta = minetest.env: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) local meta = minetest.env:get_meta(pos) @@ -1270,6 +1280,18 @@ minetest.register_node("default:furnace", { inv:set_size("src", 1) inv:set_size("dst", 4) end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, }) minetest.register_node("default:furnace_active", { @@ -1291,6 +1313,18 @@ minetest.register_node("default:furnace_active", { inv:set_size("src", 1) inv:set_size("dst", 4) end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, }) function hacky_swap_node(pos,name) -- cgit v1.2.3