forked from VoxeLibre/VoxeLibre
Merge pull request 'Create the Jockey api and use it on Skel/Spid' (#3494) from jockey_api into master
Reviewed-on: MineClone2/MineClone2#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
|
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()
|
function mob_class:get_staticdata()
|
||||||
|
|
||||||
for _,p in pairs(minetest.get_connected_players()) do
|
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._current_animation = nil
|
||||||
self:set_animation( "stand")
|
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 and not self.on_spawn_run then
|
||||||
if self.on_spawn(self) then
|
if self.on_spawn(self) then
|
||||||
self.on_spawn_run = true
|
self.on_spawn_run = true
|
||||||
|
@ -284,6 +300,9 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
||||||
self._run_armor_init = true
|
self._run_armor_init = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if def.after_activate then
|
if def.after_activate then
|
||||||
def.after_activate(self, staticdata, def, dtime)
|
def.after_activate(self, staticdata, def, dtime)
|
||||||
end
|
end
|
||||||
|
|
|
@ -241,13 +241,17 @@ function mob_class:set_animation(anim, fixed_frame)
|
||||||
if not self.animation or not anim then
|
if not self.animation or not anim then
|
||||||
return
|
return
|
||||||
end
|
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
|
if self.state == "die" and anim ~= "die" and anim ~= "stand" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.jockey then
|
|
||||||
anim = "jockey"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
if self:flight_check() and self.fly and anim == "walk" then anim = "fly" 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)
|
function mob_class:check_head_swivel(dtime)
|
||||||
if not self.head_swivel or type(self.head_swivel) ~= "string" then return end
|
if not self.head_swivel or type(self.head_swivel) ~= "string" then return end
|
||||||
|
|
||||||
|
|
||||||
who_are_you_looking_at (self)
|
who_are_you_looking_at (self)
|
||||||
|
|
||||||
local final_rotation = vector.new(0,0,0)
|
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()
|
self_rot = self.object:get_attach():get_rotation()
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.rot then
|
|
||||||
local player_pos = self._locked_object:get_pos()
|
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 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_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
|
||||||
end
|
end
|
||||||
end
|
|
||||||
elseif not self._locked_object and math.abs(oldr.y) > 3 and math.abs(oldr.x) < 3 then
|
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)
|
final_rotation = vector.multiply(oldr, 0.9)
|
||||||
else
|
else
|
||||||
|
|
|
@ -510,6 +510,12 @@ function mob_class:check_for_death(cause, cmi_cause)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.jockey or self.riden_by_jock then
|
||||||
|
self.riden_by_jock = nil
|
||||||
|
self.jockey = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local collisionbox
|
local collisionbox
|
||||||
if self.collisionbox then
|
if self.collisionbox then
|
||||||
collisionbox = table.copy(self.collisionbox)
|
collisionbox = table.copy(self.collisionbox)
|
||||||
|
|
|
@ -89,23 +89,11 @@ local skeleton = {
|
||||||
die_speed = 15,
|
die_speed = 15,
|
||||||
die_loop = false,
|
die_loop = false,
|
||||||
},
|
},
|
||||||
jock = "mobs_mc:spider",
|
|
||||||
on_spawn = function(self)
|
on_spawn = function(self)
|
||||||
minetest.after(1,function()
|
if math.random(100) == 1 then
|
||||||
if self and self.object then
|
self:jock_to("mobs_mc:spider", vector.new(0,0,0), vector.new(0,0,0))
|
||||||
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
|
end
|
||||||
self.jockey = false
|
|
||||||
return true
|
return true
|
||||||
end
|
|
||||||
end)
|
|
||||||
end,
|
|
||||||
on_detach=function(self, parent)
|
|
||||||
self.jockey = false
|
|
||||||
end,
|
end,
|
||||||
ignited_by_sunlight = true,
|
ignited_by_sunlight = true,
|
||||||
view_range = 16,
|
view_range = 16,
|
||||||
|
|
|
@ -62,9 +62,6 @@ local spider = {
|
||||||
self.object:get_children()[1]:set_detach()
|
self.object:get_children()[1]:set_detach()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
detach_child=function(self, child)
|
|
||||||
child:get_luaentity().jockey = false
|
|
||||||
end,
|
|
||||||
head_swivel = "Head_Control",
|
head_swivel = "Head_Control",
|
||||||
bone_eye_height = 1,
|
bone_eye_height = 1,
|
||||||
curiosity = 10,
|
curiosity = 10,
|
||||||
|
|
Loading…
Reference in New Issue