Armor stand: Improve TNT effects, closes #55

This commit is contained in:
stujones11 2017-03-08 19:36:30 +00:00
parent 8b8a554ff7
commit ca79d39688
2 changed files with 29 additions and 34 deletions

@ -363,6 +363,13 @@ armor.get_valid_player = function(self, player, msg)
return name, player_inv, armor_inv, pos return name, player_inv, armor_inv, pos
end end
armor.drop_armor = function(pos, stack)
local obj = minetest.add_item(pos, stack)
if obj then
obj:setvelocity({x=math.random(-1, 1), y=5, z=math.random(-1, 1)})
end
end
-- Register Player Model -- Register Player Model
default.player_register_model("3d_armor_character.b3d", { default.player_register_model("3d_armor_character.b3d", {
@ -505,12 +512,6 @@ minetest.register_on_joinplayer(function(player)
end) end)
if ARMOR_DROP == true or ARMOR_DESTROY == true then if ARMOR_DROP == true or ARMOR_DESTROY == true then
armor.drop_armor = function(pos, stack)
local obj = minetest.add_item(pos, stack)
if obj then
obj:setvelocity({x=math.random(-1, 1), y=5, z=math.random(-1, 1)})
end
end
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]") local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
if not name then if not name then

@ -16,6 +16,18 @@ local armor_stand_formspec = "size[8,7]" ..
local elements = {"head", "torso", "legs", "feet"} local elements = {"head", "torso", "legs", "feet"}
local function drop_armor(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
for _, element in pairs(elements) do
local stack = inv:get_stack("armor_"..element, 1)
if stack and stack:get_count() > 0 then
armor.drop_armor(pos, stack)
inv:set_stack("armor_"..element, 1, nil)
end
end
end
local function get_stand_object(pos) local function get_stand_object(pos)
local object = nil local object = nil
local objects = minetest.get_objects_inside_radius(pos, 0.5) or {} local objects = minetest.get_objects_inside_radius(pos, 0.5) or {}
@ -192,13 +204,9 @@ minetest.register_node("3d_armor_stand:armor_stand", {
remove_hidden_node(pos) remove_hidden_node(pos)
end, end,
on_blast = function(pos) on_blast = function(pos)
local object = get_stand_object(pos) drop_armor(pos)
if object then armor.drop_armor(pos, "3d_armor_stand:armor_stand")
object:remove() minetest.remove_node(pos)
end
minetest.after(1, function(pos)
update_entity(pos)
end, pos)
end, end,
}) })
@ -280,13 +288,7 @@ minetest.register_node("3d_armor_stand:locked_armor_stand", {
remove_hidden_node(pos) remove_hidden_node(pos)
end, end,
on_blast = function(pos) on_blast = function(pos)
local object = get_stand_object(pos) -- Not affected by TNT
if object then
object:remove()
end
minetest.after(1, function(pos)
update_entity(pos)
end, pos)
end, end,
}) })
@ -306,22 +308,14 @@ minetest.register_entity("3d_armor_stand:armor_entity", {
update_entity(pos) update_entity(pos)
end end
end, end,
on_step = function(self, dtime) on_blast = function(self, damage)
if not self.pos then local drops = {}
return local node = minetest.get_node(self.pos)
end if node.name == "3d_armor_stand:armor_stand" then
self.timer = self.timer + dtime drop_armor(self.pos)
if self.timer > 1 then
self.timer = 0
local pos = self.object:getpos()
if pos then
if vector.equals(vector.round(pos), self.pos) then
return
end
end
update_entity(self.pos)
self.object:remove() self.object:remove()
end end
return false, false, drops
end, end,
}) })