Fix it for once and all

This commit is contained in:
SmallJoker 2021-05-08 16:53:56 +02:00
parent be261573ba
commit 5e867aa205
3 changed files with 16 additions and 13 deletions

View file

@ -63,10 +63,12 @@ function boat.on_rightclick(self, clicker)
clicker:set_pos(pos) clicker:set_pos(pos)
end) end)
elseif not self.driver then elseif not self.driver then
self.driver = name
clicker:set_attach(self.object, "", clicker:set_attach(self.object, "",
{x = 0.5, y = 1, z = -3}, {x = 0, y = 0, z = 0}) {x = 0.5, y = 1, z = -3}, {x = 0, y = 0, z = 0})
self.driver = name
player_api.player_attached[name] = true player_api.player_attached[name] = true
minetest.after(0.2, function() minetest.after(0.2, function()
player_api.set_animation(clicker, "sit", 30) player_api.set_animation(clicker, "sit", 30)
end) end)
@ -79,10 +81,11 @@ end
function boat.on_detach_child(self, child) function boat.on_detach_child(self, child)
if child and child:get_player_name() == self.driver then if child and child:get_player_name() == self.driver then
player_api.player_attached[child:get_player_name()] = false player_api.player_attached[child:get_player_name()] = false
end
self.driver = nil self.driver = nil
self.auto = false self.auto = false
end end
end
function boat.on_activate(self, staticdata, dtime_s) function boat.on_activate(self, staticdata, dtime_s)

View file

@ -29,15 +29,10 @@ function cart_entity:on_rightclick(clicker)
end end
local player_name = clicker:get_player_name() local player_name = clicker:get_player_name()
if self.driver and player_name == self.driver then if self.driver and player_name == self.driver then
self.driver = nil
carts:manage_attachment(clicker, nil) carts:manage_attachment(clicker, nil)
elseif not self.driver then elseif not self.driver then
self.driver = player_name
carts:manage_attachment(clicker, self.object) carts:manage_attachment(clicker, self.object)
self.driver = player_name
-- player_api does not update the animation
-- when the player is attached, reset to default animation
player_api.set_animation(clicker, "stand")
end end
end end
@ -66,10 +61,11 @@ end
-- 0.5.x and later: When the driver leaves -- 0.5.x and later: When the driver leaves
function cart_entity:on_detach_child(child) function cart_entity:on_detach_child(child)
if child and child:get_player_name() == self.driver then if child and child:get_player_name() == self.driver then
-- Clean up eye height
carts:manage_attachment(child, nil) carts:manage_attachment(child, nil)
end
self.driver = nil self.driver = nil
end end
end
function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
local pos = self.object:get_pos() local pos = self.object:get_pos()

View file

@ -12,7 +12,7 @@ function carts:manage_attachment(player, obj)
end end
local status = obj ~= nil local status = obj ~= nil
local player_name = player:get_player_name() local player_name = player:get_player_name()
if player:get_attach() == obj then if obj and player:get_attach() == obj then
return return
end end
player_api.player_attached[player_name] = status player_api.player_attached[player_name] = status
@ -20,6 +20,10 @@ function carts:manage_attachment(player, obj)
if status then if status then
player:set_attach(obj, "", {x=0, y=-4.5, z=0}, {x=0, y=0, z=0}) player:set_attach(obj, "", {x=0, y=-4.5, z=0}, {x=0, y=0, z=0})
player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0}) player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
-- player_api does not update the animation
-- when the player is attached, reset to default animation
player_api.set_animation(player, "stand")
else else
player:set_detach() player:set_detach()
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0}) player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})