1
0
mirror of https://github.com/minetest/minetest_game.git synced 2024-12-23 07:10:19 +01:00

Make TNT a bit more fun.

But not too much.

TNT is a bit underwhelming at the moment. We can make it a bit
more interesting by ejecting not just one or two itemstacks,
but a bunch of them. This code splits up the drops into
separate itemstacks that are 2-5 items together, which
results in generally roughly 10 itemstacks being ejected.

Since now we have multiple ejecta, it makes sense to tune
the ejecta velocities a bit better to get the appearance of
an actual explosion better. The items will not all start
with the same vertical velocity, since that would look
like fireworks. Instead we give them all a different vertical
speed.
This commit is contained in:
Auke Kok 2016-01-24 23:27:50 -08:00 committed by paramat
parent 12d5ca2f48
commit 8cd049c224

View File

@ -49,23 +49,20 @@ local function eject_drops(drops, pos, radius)
local drop_pos = vector.new(pos) local drop_pos = vector.new(pos)
for _, item in pairs(drops) do for _, item in pairs(drops) do
local count = item:get_count() local count = item:get_count()
local max = item:get_stack_max()
if count > max then
item:set_count(max)
end
while count > 0 do while count > 0 do
if count < max then local take = math.min(math.random(2,5),
item:set_count(count) item:get_count(),
end item:get_stack_max())
rand_pos(pos, drop_pos, radius) rand_pos(pos, drop_pos, radius)
local obj = minetest.add_item(drop_pos, item) local obj = minetest.add_item(drop_pos, item:get_name() .. " " .. take)
if obj then if obj then
obj:get_luaentity().collect = true obj:get_luaentity().collect = true
obj:setacceleration({x=0, y=-10, z=0}) obj:setacceleration({x=0, y=-10, z=0})
obj:setvelocity({x=math.random(-3, 3), y=10, obj:setvelocity({x=math.random(-3, 3),
y=math.random(0, 10),
z=math.random(-3, 3)}) z=math.random(-3, 3)})
end end
count = count - max count = count - take
end end
end end
end end