Detach minecart driver if over activator rail

This commit is contained in:
Wuzzy 2020-01-30 22:42:53 +01:00
parent 1d2da1f01a
commit 9f344b4307
1 changed files with 22 additions and 13 deletions

View File

@ -8,6 +8,21 @@ mcl_minecarts.check_float_time = 15
dofile(mcl_minecarts.modpath.."/functions.lua") dofile(mcl_minecarts.modpath.."/functions.lua")
dofile(mcl_minecarts.modpath.."/rails.lua") dofile(mcl_minecarts.modpath.."/rails.lua")
local function detach_driver(self)
if not self._driver then
return
end
mcl_player.player_attached[self._driver] = nil
local player = minetest.get_player_by_name(self._driver)
self._driver = nil
self._start_pos = nil
if player then
player:set_detach()
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
mcl_player.player_set_animation(player, "stand" , 30)
end
end
local function activate_tnt_minecart(self) local function activate_tnt_minecart(self)
if self._boomtimer then if self._boomtimer then
return return
@ -27,6 +42,8 @@ local function activate_tnt_minecart(self)
minetest.sound_play("tnt_ignite", {pos = self.object:get_pos(), gain = 1.0, max_hear_distance = 15}) minetest.sound_play("tnt_ignite", {pos = self.object:get_pos(), gain = 1.0, max_hear_distance = 15})
end end
local activate_normal_minecart = detach_driver
-- Table for item-to-entity mapping. Keys: itemstring, Values: Corresponding entity ID -- Table for item-to-entity mapping. Keys: itemstring, Values: Corresponding entity ID
local entity_mapping = {} local entity_mapping = {}
@ -99,12 +116,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
if self._old_pos then if self._old_pos then
self.object:set_pos(self._old_pos) self.object:set_pos(self._old_pos)
end end
mcl_player.player_attached[self._driver] = nil detach_driver(self)
local player = minetest.get_player_by_name(self._driver)
if player then
player:set_detach()
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
end
end end
-- Disable detector rail -- Disable detector rail
@ -588,7 +600,8 @@ register_minecart(
S("Minecarts can be used for a quick transportion on rails.") .. "\n" .. S("Minecarts can be used for a quick transportion on rails.") .. "\n" ..
S("Minecarts only ride on rails and always follow the tracks. At a T-junction with no straight way ahead, they turn left. The speed is affected by the rail type."), S("Minecarts only ride on rails and always follow the tracks. At a T-junction with no straight way ahead, they turn left. The speed is affected by the rail type."),
S("You can place the minecart on rails. Right-click it to enter it. Punch it to get it moving.") .. "\n" .. S("You can place the minecart on rails. Right-click it to enter it. Punch it to get it moving.") .. "\n" ..
S("To obtain the minecart, punch it while holding down the sneak key."), S("To obtain the minecart, punch it while holding down the sneak key.") .. "\n"
S("If it moves over a powered activator rail, you'll get ejected."),
"mcl_minecarts_minecart.b3d", "mcl_minecarts_minecart.b3d",
{"mcl_minecarts_minecart.png"}, {"mcl_minecarts_minecart.png"},
"mcl_minecarts_minecart_normal.png", "mcl_minecarts_minecart_normal.png",
@ -600,11 +613,7 @@ register_minecart(
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 detach_driver(self)
self._start_pos = nil
clicker:set_detach()
clicker:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
mcl_player.player_set_animation(clicker, "stand" , 30)
elseif not self._driver then elseif not self._driver then
self._driver = player_name self._driver = player_name
self._start_pos = self.object:get_pos() self._start_pos = self.object:get_pos()
@ -619,7 +628,7 @@ register_minecart(
end end
end, name) end, name)
end end
end end, activate_normal_minecart
) )
-- Minecart with Chest -- Minecart with Chest