From 0c29788a3114bfcee883bafd9a1ffccbed9472e4 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 8 Oct 2021 18:59:14 +0200 Subject: [PATCH] Fixes the behavior of backwards portals Fixes a bug where backwards portals only rotated the player Fixes the rotation being wrong when teleporting from a backwards portal --- .../stargate/container/BlockLocation.java | 5 ++--- .../stargate/listener/PlayerEventListener.java | 2 +- .../listener/VehicleEventListener.java | 4 ++-- .../net/knarcraft/stargate/portal/Portal.java | 18 ++++++++---------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/knarcraft/stargate/container/BlockLocation.java b/src/main/java/net/knarcraft/stargate/container/BlockLocation.java index 36f3386..0d7fcf3 100644 --- a/src/main/java/net/knarcraft/stargate/container/BlockLocation.java +++ b/src/main/java/net/knarcraft/stargate/container/BlockLocation.java @@ -102,13 +102,12 @@ public class BlockLocation extends Location { * @param depth

The amount of blocks to go downwards when looking the opposite direction from the yaw

* @param distance

The amount of blocks to go outwards when looking the opposite direction from the yaw

* @param portalYaw

The yaw when looking out from the portal

- * @param yaw

The yaw of the travelling entity

* @return A new location relative to this block location */ - public Location getRelativeLocation(double right, double depth, double distance, float portalYaw, float yaw) { + public Location getRelativeLocation(double right, double depth, double distance, float portalYaw) { Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(right, depth, distance, portalYaw); return makeRelativeLocation(0.5 + realVector.getBlockX(), realVector.getBlockY(), - 0.5 + realVector.getBlockZ(), yaw); + 0.5 + realVector.getBlockZ(), portalYaw); } /** diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index 2e3d31d..6e55cc8 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -118,7 +118,7 @@ public class PlayerEventListener implements Listener { horse.setOwner(player); } } - destination.teleport((Vehicle) playerVehicle, entrancePortal); + destination.teleport((Vehicle) playerVehicle); } else { destination.teleport(player, entrancePortal, event); } diff --git a/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java b/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java index 4a69c13..3b01193 100644 --- a/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java @@ -70,7 +70,7 @@ public class VehicleEventListener implements Listener { return; } Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " + destinationPortal.getSignLocation()); - destinationPortal.teleport(vehicle, entrancePortal); + destinationPortal.teleport(vehicle); } } @@ -109,7 +109,7 @@ public class VehicleEventListener implements Listener { } Stargate.sendSuccessMessage(player, Stargate.getString("teleportMsg")); - destinationPortal.teleport(vehicle, entrancePortal); + destinationPortal.teleport(vehicle); entrancePortal.close(false); } diff --git a/src/main/java/net/knarcraft/stargate/portal/Portal.java b/src/main/java/net/knarcraft/stargate/portal/Portal.java index 8dc9afd..f4dc24a 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Portal.java +++ b/src/main/java/net/knarcraft/stargate/portal/Portal.java @@ -484,7 +484,7 @@ public class Portal { Location exit = getExit(player, traveller); //Rotate the player to face out from the portal - adjustRotation(exit, origin); + adjustRotation(exit); //Call the StargatePortalEvent to allow plugins to change destination if (!origin.equals(this)) { @@ -514,11 +514,10 @@ public class Portal { * Adjusts the rotation of the player to face out from the portal * * @param exit

The location the player will exit from

- * @param origin

The portal the player entered from

*/ - private void adjustRotation(Location exit, Portal origin) { + private void adjustRotation(Location exit) { int adjust = 0; - if (options.isBackwards() != origin.options.isBackwards()) { + if (options.isBackwards()) { adjust = 180; } float newYaw = (this.getYaw() + adjust) % 360; @@ -530,9 +529,8 @@ public class Portal { * Teleports a vehicle to this portal * * @param vehicle

The vehicle to teleport

- * @param origin

The portal the vehicle entered

*/ - public void teleport(final Vehicle vehicle, Portal origin) { + public void teleport(final Vehicle vehicle) { Location traveller = vehicle.getLocation(); Location exit = getExit(vehicle, traveller); @@ -544,7 +542,7 @@ public class Portal { //Get new velocity Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(this.getYaw()); Vector newVelocity = newVelocityDirection.multiply(velocity); - adjustRotation(exit, origin); + adjustRotation(exit); List passengers = vehicle.getPassengers(); @@ -632,11 +630,11 @@ public class Portal { RelativeBlockVector relativeExit = gate.getLayout().getExit(); if (relativeExit != null) { BlockLocation exit = getBlockAt(relativeExit); - float yaw = traveller.getYaw(); + float portalYaw = this.getYaw(); if (options.isBackwards()) { - yaw += 180; + portalYaw += 180; } - exitLocation = exit.getRelativeLocation(0D, 0D, 1, this.getYaw(), yaw); + exitLocation = exit.getRelativeLocation(0D, 0D, 1, portalYaw); if (entity != null) { double entitySize = EntityHelper.getEntityMaxSize(entity);