1
0
mirror of https://github.com/minetest/minetest_game.git synced 2025-06-29 13:20:25 +02:00

Attachments: Proper data cleanup in callbacks (#2865)

This commit is contained in:
SmallJoker
2021-05-11 21:15:47 +02:00
committed by GitHub
parent 642fde44f1
commit 71ea0c65ea
3 changed files with 21 additions and 24 deletions

View File

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