1
0
Fork 0

Update armor stand

This commit is contained in:
Lizzy Fleckenstein 2021-04-17 18:39:38 +02:00
parent 7c7af7d664
commit bbd115fde0
1 changed files with 11 additions and 33 deletions

View File

@ -21,8 +21,8 @@ local function get_stand_object(pos)
return object return object
end end
local function update_entity(pos) local function update_entity(pos, node)
local node = minetest.get_node(pos) local node = node or minetest.get_node(pos)
local object = get_stand_object(pos) local object = get_stand_object(pos)
if object then if object then
if not string.find(node.name, "mcl_armor_stand:") then if not string.find(node.name, "mcl_armor_stand:") then
@ -33,31 +33,7 @@ local function update_entity(pos)
object = minetest.add_entity(pos, "mcl_armor_stand:armor_entity") object = minetest.add_entity(pos, "mcl_armor_stand:armor_entity")
end end
if object then if object then
local texture = "blank.png"
local textures = {}
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local yaw = 0 local yaw = 0
if inv then
for _, element in pairs(elements) do
local stack = inv:get_stack("armor_"..element, 1)
if stack:get_count() == 1 then
local item = stack:get_name() or ""
if minetest.registered_aliases[item] then
item = minetest.registered_aliases[item]
end
local def = stack:get_definition() or {}
local groups = def.groups or {}
if groups["armor_"..element] then
local texture = def.texture or item:gsub("%:", "_")
table.insert(textures, texture..".png")
end
end
end
end
if #textures > 0 then
texture = table.concat(textures, "^")
end
if node.param2 then if node.param2 then
local rot = node.param2 % 4 local rot = node.param2 % 4
if rot == 1 then if rot == 1 then
@ -69,7 +45,7 @@ local function update_entity(pos)
end end
end end
object:set_yaw(yaw) object:set_yaw(yaw)
object:set_properties({textures={texture}}) mcl_armor.update(object)
end end
end end
@ -257,13 +233,15 @@ minetest.register_entity("mcl_armor_stand:armor_entity", {
textures = {"blank.png"}, textures = {"blank.png"},
pos = nil, pos = nil,
timer = 0, timer = 0,
on_activate = function(self) on_activate = function(self, staticdata)
local pos = self.object:get_pos()
self.object:set_armor_groups({immortal=1}) self.object:set_armor_groups({immortal=1})
if pos then local pos = self.object:get_pos()
self.pos = vector.round(pos) self.pos = vector.round(pos)
self.inventory = minetest.get_meta(pos):get_inventory()
update_entity(pos) update_entity(pos)
end end,
update_armor = function(self, info)
self.object:set_properties({textures = {info.texture}})
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
if not self.pos then if not self.pos then