From 44d3f2576709662251bb65e747195483ec75bf22 Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 26 Feb 2021 00:26:27 +0400 Subject: [PATCH] Leave minecart by Pressing Sneak, https://git.minetest.land/MineClone2/MineClone2/issues/567 --- mods/ENTITIES/mcl_minecarts/init.lua | 32 ++++++++++--------- .../mcl_minecarts/locale/mcl_minecarts.ru.tr | 1 + .../mcl_minecarts/locale/template.txt | 1 + 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index 7bea3bd46b..6ad3ff28c8 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -175,6 +175,19 @@ 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) + local ctrl, player = nil, nil + if self._driver then + player = minetest.get_player_by_name(self._driver) + if player then + ctrl = player:get_player_control() + -- player detach + if ctrl.sneak then + detach_driver(self) + return + end + end + end + local vel = self.object:get_velocity() local update = {} if self._last_float_check == nil then @@ -190,18 +203,14 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o node = minetest.get_node(rou_pos) local g = minetest.get_item_group(node.name, "connect_to_raillike") if g ~= self._railtype and self._railtype ~= nil then - local player -- Detach driver - if self._driver then + if player then if self._old_pos then self.object:set_pos(self._old_pos) end mcl_player.player_attached[self._driver] = nil - 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 + player:set_detach() + player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0}) end -- Explode if already ignited @@ -337,14 +346,6 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o end end - local ctrl, player = nil, nil - if self._driver then - player = minetest.get_player_by_name(self._driver) - if player then - ctrl = player:get_player_control() - end - end - -- Stop cart if velocity vector flips if self._old_vel and self._old_vel.y == 0 and (self._old_vel.x * vel.x < 0 or self._old_vel.z * vel.z < 0) then @@ -643,6 +644,7 @@ register_minecart( if player then mcl_player.player_set_animation(player, "sit" , 30) player:set_eye_offset({x=0, y=-5.5, z=0},{x=0, y=-4, z=0}) + mcl_tmp_message.message(clicker, S("Sneak to dismount")) end end, name) end diff --git a/mods/ENTITIES/mcl_minecarts/locale/mcl_minecarts.ru.tr b/mods/ENTITIES/mcl_minecarts/locale/mcl_minecarts.ru.tr index e8f914128f..6189bac843 100644 --- a/mods/ENTITIES/mcl_minecarts/locale/mcl_minecarts.ru.tr +++ b/mods/ENTITIES/mcl_minecarts/locale/mcl_minecarts.ru.tr @@ -33,3 +33,4 @@ Activates minecarts when powered=Активирует особые вагоне Emits redstone power when a minecart is detected=Испускает энергию редстоуна при обнаружении вагонетки Vehicle for fast travel on rails=Быстрый железнодорожный транспорт Can be ignited by tools or powered activator rail=Можно воспламенить с помощью инструмента или подключенного рельсового активатора +Sneak to dismount=Нажмите [Красться] для высадки diff --git a/mods/ENTITIES/mcl_minecarts/locale/template.txt b/mods/ENTITIES/mcl_minecarts/locale/template.txt index 2541895421..dff98587c7 100644 --- a/mods/ENTITIES/mcl_minecarts/locale/template.txt +++ b/mods/ENTITIES/mcl_minecarts/locale/template.txt @@ -33,3 +33,4 @@ Activates minecarts when powered= Emits redstone power when a minecart is detected= Vehicle for fast travel on rails= Can be ignited by tools or powered activator rail= +Sneak to dismount=