1
0
zrcadlo https://github.com/luanti-org/minetest_game.git synchronizováno 2026-01-08 02:15:20 +01:00

TNT: Add on_blast to all nodes with an inventory

Adds a minor helper function that allows efficient retrieval of
several inventories from a node inventory. We use this helper to
quickly retrieve the items in chests, vessel shelves, book shelves
and furnaces, and return these with the nodes itself to the TNT caller.

The TNT caller then performs the entity physics, and we don't need
to do anything else.

We disable TNT doing anything with bones.

We expose a bug in the code that drops the items - metadata was lost
entirely. This patch corrects that by properly copying the metadata
and creating the drops list inclusive metadata.
Tento commit je obsažen v:
Auke Kok
2016-04-15 19:21:45 -07:00
odevzdal paramat
rodič f32a3ff57c
revize 54b87e955d
7 změnil soubory, kde provedl 67 přidání a 1 odebrání

Zobrazit soubor

@@ -110,6 +110,21 @@ minetest.register_abm({
})
--
-- optimized helper to put all items in an inventory into a drops list
--
function default.get_inventory_drops(pos, inventory, drops)
local inv = minetest.get_meta(pos):get_inventory()
local n = #drops
for i = 1, inv:get_size(inventory) do
local stack = inv:get_stack(inventory, i)
if stack:get_count() > 0 then
drops[n+1] = stack:to_table()
n = n + 1
end
end
end
--
-- Papyrus and cactus growing
--

Zobrazit soubor

@@ -260,6 +260,15 @@ minetest.register_node("default:furnace", {
local timer = minetest.get_node_timer(pos)
timer:start(1.0)
end,
on_blast = function(pos)
local drops = {}
default.get_inventory_drops(pos, "src", drops)
default.get_inventory_drops(pos, "fuel", drops)
default.get_inventory_drops(pos, "dst", drops)
drops[#drops+1] = "default:furnace"
minetest.remove_node(pos)
return drops
end,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,

Zobrazit soubor

@@ -1474,6 +1474,13 @@ minetest.register_node("default:chest", {
" takes " .. stack:get_name() ..
" from chest at " .. minetest.pos_to_string(pos))
end,
on_blast = function(pos)
local drops = {}
default.get_inventory_drops(pos, "main", drops)
drops[#drops+1] = "default:chest"
minetest.remove_node(pos)
return drops
end,
})
minetest.register_node("default:chest_locked", {
@@ -1597,6 +1604,13 @@ minetest.register_node("default:bookshelf", {
minetest.log("action", player:get_player_name() ..
" takes stuff from bookshelf at " .. minetest.pos_to_string(pos))
end,
on_blast = function(pos)
local drops = {}
default.get_inventory_drops(pos, "books", drops)
drops[#drops+1] = "default:bookshelf"
minetest.remove_node(pos)
return drops
end,
})
local function register_sign(material, desc, def)