From d6c33da3554051b3e326d3b78ef3012f3746fb3a Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sat, 16 Apr 2016 12:00:17 -0700 Subject: [PATCH] TNT: Damage mobs, knock back players We apply punch damage to mobs caught in the blast radius, as this code previously only hurt players. We "move" players back 1 node if they're caught in the blast, and slightly up. We can't "eject" players due to missing API code to support that, unfortunately. --- mods/tnt/init.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index f8b59ab2..b48a56b9 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -135,16 +135,29 @@ local function entity_physics(pos, radius) local objs = minetest.get_objects_inside_radius(pos, radius) for _, obj in pairs(objs) do local obj_pos = obj:getpos() - local obj_vel = obj:getvelocity() local dist = math.max(1, vector.distance(pos, obj_pos)) - if obj_vel ~= nil then + local damage = (4 / dist) * radius + if obj:is_player() then + -- currently the engine has no method to set + -- player velocity. See #2960 + -- instead, we knock the player back 1.0 node, and slightly upwards + local dir = vector.normalize(vector.subtract(obj_pos, pos)) + local moveoff = vector.multiply(dir, dist + 1.0) + local newpos = vector.add(pos, moveoff) + local newpos = vector.add(newpos, {x = 0, y = 0.2, z = 0}) + obj:setpos(newpos) + + obj:set_hp(obj:get_hp() - damage) + else + local obj_vel = obj:getvelocity() obj:setvelocity(calc_velocity(pos, obj_pos, obj_vel, radius * 10)) + obj:punch(obj, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = damage}, + }, nil) end - - local damage = (4 / dist) * radius - obj:set_hp(obj:get_hp() - damage) end end -- 2.25.1