From e48dabc8be50a93377037e10b0b90f95342eda16 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Sun, 26 Feb 2023 16:49:21 -0800 Subject: [PATCH] Create the Jockey api and use it on Skel/Spid --- mods/ENTITIES/mcl_mobs/api.lua | 19 ++++++++++ mods/ENTITIES/mcl_mobs/effects.lua | 47 +++++++++++++----------- mods/ENTITIES/mcl_mobs/physics.lua | 6 +++ mods/ENTITIES/mobs_mc/skeleton+stray.lua | 20 ++-------- mods/ENTITIES/mobs_mc/spider.lua | 3 -- 5 files changed, 54 insertions(+), 41 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 35f56abcd..52d765349 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -75,6 +75,15 @@ function mob_class:update_tag() --update nametag and/or the debug box }) end +function mob_class:jock_to(mob, reletive_pos, rot) + self.jockey = mob + local jock = minetest.add_entity(self.object:get_pos(), mob) + if not jock then return end + jock:get_luaentity().docile_by_day = false + jock:get_luaentity().riden_by_jock = true + self.object:set_attach(jock, "", reletive_pos, rot) +end + function mob_class:get_staticdata() for _,p in pairs(minetest.get_connected_players()) do @@ -268,6 +277,13 @@ function mob_class:mob_activate(staticdata, def, dtime) self._current_animation = nil self:set_animation( "stand") + + if self.riden_by_jock then --- Keep this function before self.on_spawn() is run. + self.object:remove() + return + end + + if self.on_spawn and not self.on_spawn_run then if self.on_spawn(self) then self.on_spawn_run = true @@ -284,6 +300,9 @@ function mob_class:mob_activate(staticdata, def, dtime) self._run_armor_init = true end + + + if def.after_activate then def.after_activate(self, staticdata, def, dtime) end diff --git a/mods/ENTITIES/mcl_mobs/effects.lua b/mods/ENTITIES/mcl_mobs/effects.lua index a8b761d47..699993979 100644 --- a/mods/ENTITIES/mcl_mobs/effects.lua +++ b/mods/ENTITIES/mcl_mobs/effects.lua @@ -241,13 +241,17 @@ function mob_class:set_animation(anim, fixed_frame) if not self.animation or not anim then return end + + if self.jockey and self.object:get_attach() then + anim = "jockey" + elseif not self.object:get_attach() then + self.jockey = nil + end + if self.state == "die" and anim ~= "die" and anim ~= "stand" then return end - if self.jockey then - anim = "jockey" - end if self:flight_check() and self.fly and anim == "walk" then anim = "fly" end @@ -341,6 +345,7 @@ end function mob_class:check_head_swivel(dtime) if not self.head_swivel or type(self.head_swivel) ~= "string" then return end + who_are_you_looking_at (self) local final_rotation = vector.new(0,0,0) @@ -360,28 +365,26 @@ function mob_class:check_head_swivel(dtime) self_rot = self.object:get_attach():get_rotation() end - if self.rot then - local player_pos = self._locked_object:get_pos() - local direction_player = vector.direction(vector.add(self.object:get_pos(), vector.new(0, self.head_eye_height*.7, 0)), vector.add(player_pos, vector.new(0, _locked_object_eye_height, 0))) - local mob_yaw = math.deg(-(-(self_rot.y)-(-minetest.dir_to_yaw(direction_player))))+self.head_yaw_offset - local mob_pitch = math.deg(-dir_to_pitch(direction_player))*self.head_pitch_multiplier + local player_pos = self._locked_object:get_pos() + local direction_player = vector.direction(vector.add(self.object:get_pos(), vector.new(0, self.head_eye_height*.7, 0)), vector.add(player_pos, vector.new(0, _locked_object_eye_height, 0))) + local mob_yaw = math.deg(-(-(self_rot.y)-(-minetest.dir_to_yaw(direction_player))))+self.head_yaw_offset + local mob_pitch = math.deg(-dir_to_pitch(direction_player))*self.head_pitch_multiplier - if (mob_yaw < -60 or mob_yaw > 60) and not (self.attack and self.state == "attack" and not self.runaway) then - final_rotation = vector.multiply(oldr, 0.9) - elseif self.attack and self.state == "attack" and not self.runaway then - if self.head_yaw == "y" then - final_rotation = vector.new(mob_pitch, mob_yaw, 0) - elseif self.head_yaw == "z" then - final_rotation = vector.new(mob_pitch, 0, -mob_yaw) - end + if (mob_yaw < -60 or mob_yaw > 60) and not (self.attack and self.state == "attack" and not self.runaway) then + final_rotation = vector.multiply(oldr, 0.9) + elseif self.attack and self.state == "attack" and not self.runaway then + if self.head_yaw == "y" then + final_rotation = vector.new(mob_pitch, mob_yaw, 0) + elseif self.head_yaw == "z" then + final_rotation = vector.new(mob_pitch, 0, -mob_yaw) + end - else + else - if self.head_yaw == "y" then - final_rotation = vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, ((mob_yaw-oldr.y)*.3)+oldr.y, 0) - elseif self.head_yaw == "z" then - final_rotation = vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, 0, -(((mob_yaw-oldr.y)*.3)+oldr.y)*3) - end + if self.head_yaw == "y" then + final_rotation = vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, ((mob_yaw-oldr.y)*.3)+oldr.y, 0) + elseif self.head_yaw == "z" then + final_rotation = vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, 0, -(((mob_yaw-oldr.y)*.3)+oldr.y)*3) end end end diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 7d8f2b3ce..05a7780d8 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -510,6 +510,12 @@ function mob_class:check_for_death(cause, cmi_cause) end end + if self.jockey or self.riden_by_jock then + self.riden_by_jock = nil + self.jockey = nil + end + + local collisionbox if self.collisionbox then collisionbox = table.copy(self.collisionbox) diff --git a/mods/ENTITIES/mobs_mc/skeleton+stray.lua b/mods/ENTITIES/mobs_mc/skeleton+stray.lua index ca2fe25fa..900e7ae40 100644 --- a/mods/ENTITIES/mobs_mc/skeleton+stray.lua +++ b/mods/ENTITIES/mobs_mc/skeleton+stray.lua @@ -89,23 +89,11 @@ local skeleton = { die_speed = 15, die_loop = false, }, - jock = "mobs_mc:spider", on_spawn = function(self) - minetest.after(1,function() - if self and self.object then - if math.random(100) == 1 or self.jockey == true then -- 1% like from MCwiki - self.jockey = true - local jock = minetest.add_entity(self.object:get_pos(), "mobs_mc:spider") - jock:get_luaentity().docile_by_day = false - self.object:set_attach(jock, "", vector.new(0,0,0), vector.new(0,0,0)) - end - self.jockey = false - return true - end - end) - end, - on_detach=function(self, parent) - self.jockey = false + if math.random(100) == 1 then + self:jock_to("mobs_mc:spider", reletive_pos, rot) + end + return true end, ignited_by_sunlight = true, view_range = 16, diff --git a/mods/ENTITIES/mobs_mc/spider.lua b/mods/ENTITIES/mobs_mc/spider.lua index 403edba6d..d5d67e6b9 100644 --- a/mods/ENTITIES/mobs_mc/spider.lua +++ b/mods/ENTITIES/mobs_mc/spider.lua @@ -62,9 +62,6 @@ local spider = { self.object:get_children()[1]:set_detach() end end, - detach_child=function(self, child) - child:get_luaentity().jockey = false - end, head_swivel = "Head_Control", bone_eye_height = 1, curiosity = 10,