Merge pull request 'Create the Jockey api and use it on Skel/Spid' (#3494) from jockey_api into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3494 Reviewed-by: PrairieWind <prairiewind@noreply.git.minetest.land>
This commit is contained in:
commit
85457cd3bf
@ -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
|
||||
|
@ -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,7 +365,6 @@ 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
|
||||
@ -384,7 +388,6 @@ function mob_class:check_head_swivel(dtime)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif not self._locked_object and math.abs(oldr.y) > 3 and math.abs(oldr.x) < 3 then
|
||||
final_rotation = vector.multiply(oldr, 0.9)
|
||||
else
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
if math.random(100) == 1 then
|
||||
self:jock_to("mobs_mc:spider", 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
|
||||
end,
|
||||
ignited_by_sunlight = true,
|
||||
view_range = 16,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user