Remove banner when not attached

This commit is contained in:
cora 2022-11-09 19:53:50 +01:00
parent 608da950e4
commit 358250012f

View File

@ -73,10 +73,12 @@ local oban_layers = {
local oban_def = table.copy(minetest.registered_entities["mcl_banners:standing_banner"]) local oban_def = table.copy(minetest.registered_entities["mcl_banners:standing_banner"])
oban_def.visual_size = { x=1, y=1 } oban_def.visual_size = { x=1, y=1 }
oban_def.on_rightclick = function(self) local old_step = oban_def.on_step
minetest.log(dump(self._base_color)) oban_def.on_step = function(self,dtime)
minetest.log(dump(self._layers)) if not self.object:get_attach() then return self.object:remove() end
if old_step then return old_step(self.dtime) end
end end
minetest.register_entity(":mcl_raids:ominous_banner",oban_def) minetest.register_entity(":mcl_raids:ominous_banner",oban_def)
function mcl_raids.drop_obanner(pos) function mcl_raids.drop_obanner(pos)
@ -93,11 +95,6 @@ function mcl_raids.promote_to_raidcaptain(c) -- object
l._banner = minetest.add_entity(pos,"mcl_raids:ominous_banner") l._banner = minetest.add_entity(pos,"mcl_raids:ominous_banner")
l._banner:set_properties({textures = {mcl_banners.make_banner_texture("unicolor_white", oban_layers)}}) l._banner:set_properties({textures = {mcl_banners.make_banner_texture("unicolor_white", oban_layers)}})
l._banner:set_attach(c,"",vector.new(-1,5.5,0),vector.new(0,0,0),true) l._banner:set_attach(c,"",vector.new(-1,5.5,0),vector.new(0,0,0),true)
local bl = l._banner:get_luaentity()
bl.parent = c
bl.on_step = function(self,dtime)
if not self.parent or not self.parent:get_pos() then return self.object:remove() end
end
l._raidcaptain = true l._raidcaptain = true
local old_ondie = l.on_die local old_ondie = l.on_die
l.on_die = function(self, pos, cmi_cause) l.on_die = function(self, pos, cmi_cause)