1
0
Fork 0

Beams heal the dragon

This commit is contained in:
cora 2022-09-12 23:03:08 +02:00 committed by Gitea
parent b7b19c0602
commit d26793195f
1 changed files with 53 additions and 28 deletions

View File

@ -4,6 +4,50 @@
local S = minetest.get_translator("mobs_mc") local S = minetest.get_translator("mobs_mc")
local BEAM_CHECK_FREQUENCY = 2
local POS_CHECK_FREQUENCY = 15
local HEAL_AMMOUNT = 37
local function heal(self)
local o = self.object
self.health = math.min(self.hp_max,self.health + HEAL_AMMOUNT)
end
local function check_beam(self)
for _, obj in ipairs(minetest.get_objects_inside_radius(self.object:get_pos(), 80)) do
local luaentity = obj:get_luaentity()
if luaentity and luaentity.name == "mcl_end:crystal" then
if luaentity.beam then
if luaentity.beam == self.beam then
heal(self)
break
end
else
if self.beam then
self.beam:remove()
end
minetest.add_entity(self.object:get_pos(), "mcl_end:crystal_beam"):get_luaentity():init(self.object, obj)
break
end
end
end
end
local function check_pos(self)
if self._portal_pos then
-- migrate old format
if type(self._portal_pos) == "string" then
self._portal_pos = minetest.string_to_pos(self._portal_pos)
end
local portal_center = vector.add(self._portal_pos, vector.new(0, 11, 0))
local pos = self.object:get_pos()
if vector.distance(pos, portal_center) > 50 then
self.object:set_pos(self._last_good_pos or portal_center)
else
self._last_good_pos = pos
end
end
end
mcl_mobs:register_mob("mobs_mc:enderdragon", { mcl_mobs:register_mob("mobs_mc:enderdragon", {
description = S("Ender Dragon"), description = S("Ender Dragon"),
type = "monster", type = "monster",
@ -61,37 +105,18 @@ mcl_mobs:register_mob("mobs_mc:enderdragon", {
run_start = 0, run_end = 20, run_start = 0, run_end = 20,
}, },
ignores_nametag = true, ignores_nametag = true,
do_custom = function(self) do_custom = function(self,dtime)
mcl_bossbars.update_boss(self.object, "Ender Dragon", "light_purple") mcl_bossbars.update_boss(self.object, "Ender Dragon", "light_purple")
for _, obj in ipairs(minetest.get_objects_inside_radius(self.object:get_pos(), 80)) do if self._pos_timer == nil or self._pos_timer > POS_CHECK_FREQUENCY then
local luaentity = obj:get_luaentity() self._pos_timer = 0
if luaentity and luaentity.name == "mcl_end:crystal" then check_pos(self)
if luaentity.beam then
if luaentity.beam == self.beam then
break
end
else
if self.beam then
self.beam:remove()
end
minetest.add_entity(self.object:get_pos(), "mcl_end:crystal_beam"):get_luaentity():init(self.object, obj)
break
end
end
end
if self._portal_pos then
-- migrate old format
if type(self._portal_pos) == "string" then
self._portal_pos = minetest.string_to_pos(self._portal_pos)
end
local portal_center = vector.add(self._portal_pos, vector.new(0, 11, 0))
local pos = self.object:get_pos()
if vector.distance(pos, portal_center) > 50 then
self.object:set_pos(self._last_good_pos or portal_center)
else
self._last_good_pos = pos
end end
if self._beam_timer == nil or self._beam_timer > BEAM_CHECK_FREQUENCY then
self._beam_timer = 0
check_beam(self)
end end
self._beam_timer = self._beam_timer + dtime
self._pos_timer = self._pos_timer + dtime
end, end,
on_die = function(self, pos, cmi_cause) on_die = function(self, pos, cmi_cause)
if self._portal_pos then if self._portal_pos then