1
0
mirror of https://github.com/minetest/minetest_game.git synced 2025-06-28 12:46:02 +02:00

Generalize TNT item loss probability and apply it to more items

This commit is contained in:
sfan5
2025-02-16 17:13:40 +01:00
parent d38b8e6657
commit 692ac2d062
3 changed files with 30 additions and 11 deletions

View File

@ -12,12 +12,6 @@ if enable_tnt == nil then
enable_tnt = minetest.is_singleplayer()
end
-- loss probabilities array (one in X will be lost)
local loss_prob = {}
loss_prob["default:cobble"] = 3
loss_prob["default:dirt"] = 4
local tnt_radius = tonumber(minetest.settings:get("tnt_radius") or 3)
-- Fill a list with data for content IDs, after all nodes are registered
@ -27,7 +21,7 @@ minetest.register_on_mods_loaded(function()
cid_data[minetest.get_content_id(name)] = {
name = name,
drops = def.drops,
flammable = def.groups.flammable,
flammable = def.groups and (def.groups.flammable or 0) ~= 0,
on_blast = def.on_blast,
}
end
@ -76,11 +70,14 @@ end
local function add_drop(drops, item)
item = ItemStack(item)
local name = item:get_name()
if loss_prob[name] ~= nil and math.random(1, loss_prob[name]) == 1 then
-- Note that this needs to be set on the dropped item, not the node.
-- Value represents "one in X will be lost"
local lost = item:get_definition()._tnt_loss or 0
if lost > 0 and (lost == 1 or math.random(1, lost) == 1) then
return
end
local name = item:get_name()
local drop = drops[name]
if drop == nil then
drops[name] = item