From 4efa74bb8ff6738c6e9cd3093b5fa089a2f0a210 Mon Sep 17 00:00:00 2001 From: Piratux <58703216+Piratux@users.noreply.github.com> Date: Sat, 20 May 2023 16:18:50 +0300 Subject: [PATCH] Fix teleporter not working when tiles are placed over it --- maps/journey/functions.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/maps/journey/functions.lua b/maps/journey/functions.lua index 00e73d63..5b430f06 100644 --- a/maps/journey/functions.lua +++ b/maps/journey/functions.lua @@ -1191,10 +1191,23 @@ end function Public.teleporters(journey, player) if not player.character then return end if not player.character.valid then return end - local surface = player.surface - if surface.get_tile(player.position).name ~= Constants.teleporter_tile then return end + local surface = player.surface + + -- This check disables teleporter if players place stone-brick or other tiles on top + -- if surface.get_tile(player.position).name ~= Constants.teleporter_tile then return end + + -- Check if player entered teleporter + -- NOTE: We assume that teleporters always get placed at "Constants.mothership_teleporter_position" position + if not ( + math.abs(player.position.x - Constants.mothership_teleporter_position.x) <= 1 and + math.abs(player.position.y - Constants.mothership_teleporter_position.y) <= 1 + ) + then + return + end + local base_position = {0,0} - if surface.index == 1 then + if surface.index == 1 then drop_player_items(player) local position = game.surfaces.mothership.find_non_colliding_position("character", base_position, 32, 0.5) if position then @@ -1213,7 +1226,7 @@ function Public.teleporters(journey, player) else player.teleport(base_position, game.surfaces.nauvis) end - + journey.characters_in_mothership = journey.characters_in_mothership - 1 return end