Attachments: Proper data cleanup in callbacks

This commit is contained in:
SmallJoker 2021-04-11 17:51:14 +02:00
parent 0a90bd8a0e
commit be261573ba
3 changed files with 7 additions and 13 deletions

View File

@ -53,10 +53,9 @@ function boat.on_rightclick(self, clicker)
end
local name = clicker:get_player_name()
if self.driver and name == self.driver then
self.driver = nil
self.auto = false
-- Cleanup happens in boat.on_detach_child
clicker:set_detach()
player_api.player_attached[name] = false
player_api.set_animation(clicker, "stand" , 30)
local pos = clicker:get_pos()
pos = {x = pos.x, y = pos.y + 0.2, z = pos.z}
@ -64,14 +63,6 @@ function boat.on_rightclick(self, clicker)
clicker:set_pos(pos)
end)
elseif not self.driver then
local attach = clicker:get_attach()
if attach and attach:get_luaentity() then
local luaentity = attach:get_luaentity()
if luaentity.driver then
luaentity.driver = nil
end
clicker:set_detach()
end
self.driver = name
clicker:set_attach(self.object, "",
{x = 0.5, y = 1, z = -3}, {x = 0, y = 0, z = 0})
@ -86,6 +77,9 @@ end
-- If driver leaves server while driving boat
function boat.on_detach_child(self, child)
if child and child:get_player_name() == self.driver then
player_api.player_attached[child:get_player_name()] = false
end
self.driver = nil
self.auto = false
end

View File

@ -66,9 +66,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
carts:manage_attachment(child, nil)
end
self.driver = nil
end
function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)

View File

@ -12,7 +12,7 @@ function carts:manage_attachment(player, obj)
end
local status = obj ~= nil
local player_name = player:get_player_name()
if player_api.player_attached[player_name] == status then
if player:get_attach() == obj then
return
end
player_api.player_attached[player_name] = status