Tweak hog steering

* mods/ENTITIES/mcl_mobs/api.lua (on_step): Call
expel_underwater_drivers when not should_drive.

* mods/ENTITIES/mcl_mobs/mount.lua (expel_underwater_drivers):
New function.

* mods/ENTITIES/mobs_mc/pig.lua (on_rightclick): Configure
suitable attachment offsets before attaching riders.
This commit is contained in:
Po Lu 2024-09-02 14:28:25 +08:00 committed by cora
parent 33400b5d21
commit ee0e808d1f
3 changed files with 26 additions and 3 deletions

View File

@ -461,6 +461,9 @@ function mob_class:on_step(dtime, moveresult)
self:check_breeding()
self:check_aggro(dtime)
-- Expel drivers riding submerged mobs.
self:expel_underwater_drivers ()
end
if self.do_custom then

View File

@ -132,6 +132,19 @@ function mob_class:should_drive ()
end
end
function mob_class:expel_underwater_drivers ()
-- Detach the driver if submerged.
if self.driver then
local headin = minetest.registered_nodes[self.head_in]
if headin.groups.water then
force_detach (self.driver)
self:roam ()
return
end
end
end
function mob_class:drive(moving_anim, stand_anim, can_fly, dtime, moveresult)
if self.steer_class == "controls" then
self:drive_controls (moving_anim, stand_anim, can_fly, dtime, moveresult)

View File

@ -67,7 +67,6 @@ mcl_mobs.register_mob("mobs_mc:pig", {
return true
end,
on_die = function(self)
-- drop saddle when horse is killed while riding
-- also detach from horse properly
if self.driver then
@ -148,9 +147,17 @@ mcl_mobs.register_mob("mobs_mc:pig", {
return
elseif not self.driver and self.saddle == "yes" then
-- Ride pig if it has a saddle
-- Initialize attachment properties.
if not self.v3 then
local vsize = self.object:get_properties ().visual_size
self.driver_attach_at = {x = 0.0, y = 6.5, z = -3.75}
self.driver_eye_offset = {x = 0, y = 3, z = 0}
self.driver_scale = {x = 1/vsize.x, y = 1/vsize.y}
self.v3 = 0
end
self:attach(clicker)
-- Ride pig if it has a saddle
self:attach (clicker)
return
end
end,