From ea08fee9ba572287f4aad42b0afa07a7ace7369b Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 6 Apr 2021 16:38:23 +0200 Subject: [PATCH] Make the dragon stay within a 50 blocks range of the portal --- mods/ENTITIES/mobs_mc/ender_dragon.lua | 18 +++++++++++++++--- mods/ITEMS/mcl_end/end_crystal.lua | 2 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index 50aaacd4b..fbdaf2bc9 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -61,14 +61,26 @@ mobs:register_mob("mobs_mc:enderdragon", { ignores_nametag = true, do_custom = function(self) mcl_bossbars.update_boss(self, "Ender Dragon", "light_purple") + 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(3, 11, 3)) + 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, on_die = function(self, pos) if self._portal_pos then - local portal_pos = minetest.string_to_pos(self._portal_pos) - mcl_structures.call_struct(portal_pos, "end_exit_portal_open") + mcl_structures.call_struct(self._portal_pos, "end_exit_portal_open") if self._initial then mcl_experience.throw_experience(pos, 11500) -- 500 + 11500 = 12000 - minetest.set_node(vector.add(portal_pos, vector.new(3, 5, 3)), {name = mobs_mc.items.dragon_egg}) + minetest.set_node(vector.add(self._portal_pos, vector.new(3, 5, 3)), {name = mobs_mc.items.dragon_egg}) end end end, diff --git a/mods/ITEMS/mcl_end/end_crystal.lua b/mods/ITEMS/mcl_end/end_crystal.lua index 63a37d3c6..772776a1c 100644 --- a/mods/ITEMS/mcl_end/end_crystal.lua +++ b/mods/ITEMS/mcl_end/end_crystal.lua @@ -60,7 +60,7 @@ local function spawn_crystal(pos) end local portal_pos = vector.add(portal_center, vector.new(-3, -1, -3)) mcl_structures.call_struct(portal_pos, "end_exit_portal") - minetest.add_entity(vector.add(portal_pos, vector.new(3, 11, 3)), "mobs_mc:enderdragon"):get_luaentity()._portal_pos = minetest.pos_to_string(portal_pos) + minetest.add_entity(vector.add(portal_pos, vector.new(3, 11, 3)), "mobs_mc:enderdragon"):get_luaentity()._portal_pos = portal_pos end minetest.register_entity("mcl_end:crystal", { diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 237579dbe..e9d9368ad 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1253,7 +1253,7 @@ end local function generate_end_exit_portal(pos) local dragon_entity = minetest.add_entity(vector.add(pos, vector.new(3, 11, 3)), "mobs_mc:enderdragon"):get_luaentity() dragon_entity._initial = true - dragon_entity._portal_pos = minetest.pos_to_string(pos) + dragon_entity._portal_pos = pos mcl_structures.call_struct(pos, "end_exit_portal") end