Prevent digging when there's items inside
This commit is contained in:
parent
9e8a1967f2
commit
2c442710d4
@ -1,4 +1,10 @@
|
|||||||
|
|
||||||
|
local function can_dig(pos, player)
|
||||||
|
local meta = minetest.get_meta(pos);
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:is_empty("in") and inv:is_empty("out")
|
||||||
|
end
|
||||||
|
|
||||||
local function item_in_group(stack, grp)
|
local function item_in_group(stack, grp)
|
||||||
return minetest.get_item_group(stack:get_name(), grp) > 0
|
return minetest.get_item_group(stack:get_name(), grp) > 0
|
||||||
end
|
end
|
||||||
@ -14,6 +20,8 @@ function elepm.register_storage(nodename, nodedef)
|
|||||||
nodedef.groups["ele_storage"] = 1
|
nodedef.groups["ele_storage"] = 1
|
||||||
nodedef.groups["ele_provider"] = 1
|
nodedef.groups["ele_provider"] = 1
|
||||||
|
|
||||||
|
nodedef.can_dig = can_dig
|
||||||
|
|
||||||
nodedef.on_timer = function (pos, elapsed)
|
nodedef.on_timer = function (pos, elapsed)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local refresh = false
|
local refresh = false
|
||||||
@ -27,7 +35,8 @@ function elepm.register_storage(nodename, nodedef)
|
|||||||
|
|
||||||
ele.helpers.swap_node(pos, nodename .. "_" .. level)
|
ele.helpers.swap_node(pos, nodename .. "_" .. level)
|
||||||
meta:set_string("formspec", ele.formspec.get_storage_formspec(rounded))
|
meta:set_string("formspec", ele.formspec.get_storage_formspec(rounded))
|
||||||
meta:set_string("infotext", ("%s Active"):format(nodedef.description) .. "\n" .. ele.capacity_text(capacity, storage))
|
meta:set_string("infotext", ("%s Active"):format(nodedef.description) .. "\n" ..
|
||||||
|
ele.capacity_text(capacity, storage))
|
||||||
|
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
|
@ -39,6 +39,12 @@
|
|||||||
Intended use: to set textures or light output.
|
Intended use: to set textures or light output.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local function can_dig(pos, player)
|
||||||
|
local meta = minetest.get_meta(pos);
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:is_empty("dst") and inv:is_empty("src")
|
||||||
|
end
|
||||||
|
|
||||||
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
if minetest.is_protected(pos, player:get_player_name()) then
|
||||||
return 0
|
return 0
|
||||||
@ -143,6 +149,11 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
nodedef.preserve_metadata = preserve_metadata
|
nodedef.preserve_metadata = preserve_metadata
|
||||||
nodedef.after_place_node = retrieve_metadata
|
nodedef.after_place_node = retrieve_metadata
|
||||||
|
|
||||||
|
-- Prevent digging when there's items inside
|
||||||
|
if not nodedef.can_dig then
|
||||||
|
nodedef.can_dig = can_dig
|
||||||
|
end
|
||||||
|
|
||||||
-- Finally, register the damn thing already
|
-- Finally, register the damn thing already
|
||||||
minetest.register_node(nodename, nodedef)
|
minetest.register_node(nodename, nodedef)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user