Inhibit minecart pickup after detaching driver

When a minecart drives over an activator rail, it detaches its driver.
In cases where the “driver” is a mob or a boat, the mob or boat can get
picked up again immediately, which is likely to be unintended behaviour.

By inhibiting minecart pickup for a second when detaching a mob or boat
from a minecart, activator rails behave as expected: Minecart drivers
are detached and not picked up immediately if they are a mob or boat.
This commit is contained in:
Nils Dagsson Moskopp 2021-07-21 19:33:38 +02:00
parent c593036b61
commit cf3c335c37
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
1 changed files with 7 additions and 1 deletions

View File

@ -13,6 +13,7 @@ local function detach_driver(self)
return
end
if not self._driver:is_player() then
self._pickup_inhibit_timer = 1
self._driver:set_detach()
self._driver = nil
return
@ -81,6 +82,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
_old_pos = nil,
_old_vel = {x=0, y=0, z=0},
_old_switch = 0,
_pickup_inhibit_timer = 0, -- how many seconds are mobs and boats not picked up after detaching?
_railtype = nil,
}
@ -181,8 +183,12 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
cart.on_activate_by_rail = on_activate_by_rail
function cart:on_step(dtime)
if self._pickup_inhibit_timer > 0 then
self._pickup_inhibit_timer = self._pickup_inhibit_timer - dtime
end
local entity_name = self.object:get_luaentity().name
if entity_name == "mcl_minecarts:minecart" then
if entity_name == "mcl_minecarts:minecart" and self._pickup_inhibit_timer <= 0 then
for _, obj in ipairs(minetest.get_objects_inside_radius(self.object:get_pos(), 1.3)) do
local entity = obj:get_luaentity()
if not self._driver and entity and ( entity._cmi_is_mob or entity.name == "mcl_boats:boat" ) and not obj:get_attach() then