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
This commit is contained in:
Kristian Knarvik 2021-10-08 18:59:14 +02:00
parent fff4d8d78b
commit 0c29788a31
4 changed files with 13 additions and 16 deletions

View File

@ -102,13 +102,12 @@ public class BlockLocation extends Location {
* @param depth <p>The amount of blocks to go downwards when looking the opposite direction from the yaw</p> * @param depth <p>The amount of blocks to go downwards when looking the opposite direction from the yaw</p>
* @param distance <p>The amount of blocks to go outwards when looking the opposite direction from the yaw</p> * @param distance <p>The amount of blocks to go outwards when looking the opposite direction from the yaw</p>
* @param portalYaw <p>The yaw when looking out from the portal</p> * @param portalYaw <p>The yaw when looking out from the portal</p>
* @param yaw <p>The yaw of the travelling entity</p>
* @return A new location relative to this block location * @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); Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(right, depth, distance, portalYaw);
return makeRelativeLocation(0.5 + realVector.getBlockX(), realVector.getBlockY(), return makeRelativeLocation(0.5 + realVector.getBlockX(), realVector.getBlockY(),
0.5 + realVector.getBlockZ(), yaw); 0.5 + realVector.getBlockZ(), portalYaw);
} }
/** /**

View File

@ -118,7 +118,7 @@ public class PlayerEventListener implements Listener {
horse.setOwner(player); horse.setOwner(player);
} }
} }
destination.teleport((Vehicle) playerVehicle, entrancePortal); destination.teleport((Vehicle) playerVehicle);
} else { } else {
destination.teleport(player, entrancePortal, event); destination.teleport(player, entrancePortal, event);
} }

View File

@ -70,7 +70,7 @@ public class VehicleEventListener implements Listener {
return; return;
} }
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " + destinationPortal.getSignLocation()); 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")); Stargate.sendSuccessMessage(player, Stargate.getString("teleportMsg"));
destinationPortal.teleport(vehicle, entrancePortal); destinationPortal.teleport(vehicle);
entrancePortal.close(false); entrancePortal.close(false);
} }

View File

@ -484,7 +484,7 @@ public class Portal {
Location exit = getExit(player, traveller); Location exit = getExit(player, traveller);
//Rotate the player to face out from the portal //Rotate the player to face out from the portal
adjustRotation(exit, origin); adjustRotation(exit);
//Call the StargatePortalEvent to allow plugins to change destination //Call the StargatePortalEvent to allow plugins to change destination
if (!origin.equals(this)) { if (!origin.equals(this)) {
@ -514,11 +514,10 @@ public class Portal {
* Adjusts the rotation of the player to face out from the portal * Adjusts the rotation of the player to face out from the portal
* *
* @param exit <p>The location the player will exit from</p> * @param exit <p>The location the player will exit from</p>
* @param origin <p>The portal the player entered from</p>
*/ */
private void adjustRotation(Location exit, Portal origin) { private void adjustRotation(Location exit) {
int adjust = 0; int adjust = 0;
if (options.isBackwards() != origin.options.isBackwards()) { if (options.isBackwards()) {
adjust = 180; adjust = 180;
} }
float newYaw = (this.getYaw() + adjust) % 360; float newYaw = (this.getYaw() + adjust) % 360;
@ -530,9 +529,8 @@ public class Portal {
* Teleports a vehicle to this portal * Teleports a vehicle to this portal
* *
* @param vehicle <p>The vehicle to teleport</p> * @param vehicle <p>The vehicle to teleport</p>
* @param origin <p>The portal the vehicle entered</p>
*/ */
public void teleport(final Vehicle vehicle, Portal origin) { public void teleport(final Vehicle vehicle) {
Location traveller = vehicle.getLocation(); Location traveller = vehicle.getLocation();
Location exit = getExit(vehicle, traveller); Location exit = getExit(vehicle, traveller);
@ -544,7 +542,7 @@ public class Portal {
//Get new velocity //Get new velocity
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(this.getYaw()); Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(this.getYaw());
Vector newVelocity = newVelocityDirection.multiply(velocity); Vector newVelocity = newVelocityDirection.multiply(velocity);
adjustRotation(exit, origin); adjustRotation(exit);
List<Entity> passengers = vehicle.getPassengers(); List<Entity> passengers = vehicle.getPassengers();
@ -632,11 +630,11 @@ public class Portal {
RelativeBlockVector relativeExit = gate.getLayout().getExit(); RelativeBlockVector relativeExit = gate.getLayout().getExit();
if (relativeExit != null) { if (relativeExit != null) {
BlockLocation exit = getBlockAt(relativeExit); BlockLocation exit = getBlockAt(relativeExit);
float yaw = traveller.getYaw(); float portalYaw = this.getYaw();
if (options.isBackwards()) { 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) { if (entity != null) {
double entitySize = EntityHelper.getEntityMaxSize(entity); double entitySize = EntityHelper.getEntityMaxSize(entity);