1
0
mirror of https://github.com/Sokomine/chesttools.git synced 2025-01-09 17:40:37 +01:00

define on_blast behavior to prevent destruction of chest contents in an explosion

This commit is contained in:
flux 2023-05-10 13:28:05 -07:00
parent 435b8cdda5
commit c20c1fbdc9
No known key found for this signature in database
GPG Key ID: 9333B27816848A15
2 changed files with 25 additions and 1 deletions

View File

@ -4,6 +4,8 @@
-- 27.07.18 Added support for shared locked chests and moved to set_node
-- with inventory copying for cleaner operation.
-- 05.10.14 Fixed bug in protection/access
local f = string.format
chesttools = {}
@ -607,6 +609,25 @@ chesttools.register_chest = function(node_name, desc, name, paramtype2, palette,
end
return nil;
end,
on_blast = function(pos, intensity)
if minetest.settings:get("chesttools:on_blast_behavior") == "drop" then
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local inv = meta:get_inventory()
local drops = {node_name}
for _, drop in ipairs(inv:get_list("main")) do
if not drop:is_empty() then
table.insert(drops, drop)
end
end
minetest.remove_node(pos)
minetest.log(f("[chesttools] %s's chest @ %s destroyed in explosion, dropped %s",
owner, minetest.pos_to_string(pos), minetest.write_json(drops)
))
return drops
end
end,
})
end
@ -642,4 +663,3 @@ minetest.register_craft({
type = 'shapeless',
recipe = { 'default:steel_ingot', 'chesttools:shared_chest' },
})

4
settingtypes.txt Normal file
View File

@ -0,0 +1,4 @@
# what to do if the chest is exposed to an explosion.
# none (default) means nothing happens - the chest remains intact
# drop means that the chest and its contents will be dropped on the ground.
chesttools:on_blast_behavior (behavior when exploded) enum none none,drop