Removes SimpleVectorOperation and adds a different message for a failed teleportation
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
This commit is contained in:
@@ -202,6 +202,11 @@ public enum Message {
|
|||||||
* The author that created the loaded translation
|
* The author that created the loaded translation
|
||||||
*/
|
*/
|
||||||
AUTHOR("author"),
|
AUTHOR("author"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The error message to display when a teleportation fails for whatever reason
|
||||||
|
*/
|
||||||
|
TELEPORTATION_FAILED("teleportationFailed"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.knarcraft.stargate.container;
|
package net.knarcraft.stargate.container;
|
||||||
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -22,28 +21,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
*/
|
*/
|
||||||
public record RelativeBlockVector(int right, int down, int out) {
|
public record RelativeBlockVector(int right, int down, int out) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the given value to this relative block vector's "right" property
|
|
||||||
*
|
|
||||||
* @param valueToAdd <p>The value to add</p>
|
|
||||||
* @return <p>The new resulting vector</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public RelativeBlockVector addRight(int valueToAdd) {
|
|
||||||
return new RelativeBlockVector(this.right + valueToAdd, this.down, this.out);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the given value to this relative block vector's "down" property
|
|
||||||
*
|
|
||||||
* @param valueToAdd <p>The value to add</p>
|
|
||||||
* @return <p>The new resulting vector</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public RelativeBlockVector addDown(int valueToAdd) {
|
|
||||||
return new RelativeBlockVector(this.right, this.down + valueToAdd, this.out);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given value to this relative block vector's "out" property
|
* Adds the given value to this relative block vector's "out" property
|
||||||
*
|
*
|
||||||
@@ -55,15 +32,6 @@ public record RelativeBlockVector(int right, int down, int out) {
|
|||||||
return new RelativeBlockVector(this.right, this.down, this.out + valueToAdd);
|
return new RelativeBlockVector(this.right, this.down, this.out + valueToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a relative vector in the real space representing this relative block vector
|
|
||||||
*
|
|
||||||
* @return <p>A vector representing this relative block vector</p>
|
|
||||||
*/
|
|
||||||
public Vector toVector() {
|
|
||||||
return new Vector(this.right, -this.down, this.out);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a relative block vector which is this inverted (pointing in the opposite direction)
|
* Gets a relative block vector which is this inverted (pointing in the opposite direction)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -388,6 +388,7 @@ public class StargateTeleportListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal,
|
private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal,
|
||||||
@NotNull Portal destination, @NotNull PlayerMoveEvent event) {
|
@NotNull Portal destination, @NotNull PlayerMoveEvent event) {
|
||||||
|
boolean success = true;
|
||||||
if (playerVehicle instanceof LivingEntity) {
|
if (playerVehicle instanceof LivingEntity) {
|
||||||
//Make sure any horses are properly tamed
|
//Make sure any horses are properly tamed
|
||||||
if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) {
|
if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) {
|
||||||
@@ -399,10 +400,12 @@ public class StargateTeleportListener implements Listener {
|
|||||||
new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal);
|
new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal);
|
||||||
} else {
|
} else {
|
||||||
//Just teleport the player like normal
|
//Just teleport the player like normal
|
||||||
new PlayerTeleporter(destination, player).teleportPlayer(entrancePortal, event);
|
success = new PlayerTeleporter(destination, player).teleportPlayer(entrancePortal, event);
|
||||||
}
|
}
|
||||||
if (!entrancePortal.getOptions().isQuiet()) {
|
if (success && !entrancePortal.getOptions().isQuiet()) {
|
||||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||||
|
} else if (!success) {
|
||||||
|
new SGFormatBuilder(Message.TELEPORTATION_FAILED);
|
||||||
}
|
}
|
||||||
entrancePortal.getPortalOpener().closePortal(false);
|
entrancePortal.getPortalOpener().closePortal(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import net.knarcraft.stargate.portal.property.PortalOwner;
|
|||||||
import net.knarcraft.stargate.portal.property.PortalStrings;
|
import net.knarcraft.stargate.portal.property.PortalStrings;
|
||||||
import net.knarcraft.stargate.portal.property.PortalStructure;
|
import net.knarcraft.stargate.portal.property.PortalStructure;
|
||||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||||
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
|
||||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -28,7 +26,6 @@ public class Portal {
|
|||||||
private final String cleanName;
|
private final String cleanName;
|
||||||
private final String network;
|
private final String network;
|
||||||
private final String cleanNetwork;
|
private final String cleanNetwork;
|
||||||
private final SimpleVectorOperation vectorOperation;
|
|
||||||
|
|
||||||
private final PortalOwner portalOwner;
|
private final PortalOwner portalOwner;
|
||||||
private boolean isRegistered;
|
private boolean isRegistered;
|
||||||
@@ -64,7 +61,6 @@ public class Portal {
|
|||||||
this.portalActivator = portalOpener.getPortalActivator();
|
this.portalActivator = portalOpener.getPortalActivator();
|
||||||
this.cleanName = cleanString(name);
|
this.cleanName = cleanString(name);
|
||||||
this.cleanNetwork = cleanString(network);
|
this.cleanNetwork = cleanString(network);
|
||||||
this.vectorOperation = new SimpleVectorOperation(DirectionHelper.getBlockFaceFromYaw(portalLocation.getYaw()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -317,7 +313,7 @@ public class Portal {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public BlockLocation getBlockAt(@NotNull RelativeBlockVector vector) {
|
public BlockLocation getBlockAt(@NotNull RelativeBlockVector vector) {
|
||||||
return (BlockLocation) getTopLeft().clone().add(vectorOperation.performToRealSpaceOperation(vector.toVector()));
|
return getTopLeft().getRelativeLocation(vector, this.getYaw());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -71,15 +71,18 @@ public class PortalHandler {
|
|||||||
List<String> destinations = new ArrayList<>();
|
List<String> destinations = new ArrayList<>();
|
||||||
List<String> portalsInNetwork = PortalRegistry.getNetwork(network);
|
List<String> portalsInNetwork = PortalRegistry.getNetwork(network);
|
||||||
if (portalsInNetwork == null) {
|
if (portalsInNetwork == null) {
|
||||||
|
Stargate.debug("PortalHandler::getDestinations", "Portal network " + network + " is null");
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
for (String destination : portalsInNetwork) {
|
for (String destination : portalsInNetwork) {
|
||||||
Portal portal = getByName(destination, network);
|
Portal portal = getByName(destination, network);
|
||||||
if (portal == null) {
|
if (portal == null) {
|
||||||
|
Stargate.debug("PortalHandler::getDestinations", "Invalid portal with name " + destination);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDestinationAvailable(entrancePortal, portal, player)) {
|
if (isDestinationAvailable(entrancePortal, portal, player)) {
|
||||||
|
Stargate.debug("PortalHandler::getDestinations", "Found available destination " + portal.getName());
|
||||||
destinations.add(portal.getName());
|
destinations.add(portal.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,6 +123,7 @@ public class PortalHandler {
|
|||||||
//Check if this player can access the destination world
|
//Check if this player can access the destination world
|
||||||
if (destinationPortal.getWorld() != null && PermissionHelper.cannotAccessWorld(player,
|
if (destinationPortal.getWorld() != null && PermissionHelper.cannotAccessWorld(player,
|
||||||
destinationPortal.getWorld().getName())) {
|
destinationPortal.getWorld().getName())) {
|
||||||
|
Stargate.debug("PortalHandler::isDestinationAvailable", "Missing permission for destination world");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//The portal is visible to the player
|
//The portal is visible to the player
|
||||||
@@ -473,7 +477,8 @@ public class PortalHandler {
|
|||||||
if (!MaterialHelper.specifiersToMaterials(portal.getGate().getControlBlockMaterials()).contains(
|
if (!MaterialHelper.specifiersToMaterials(portal.getGate().getControlBlockMaterials()).contains(
|
||||||
block.getType())) {
|
block.getType())) {
|
||||||
Stargate.debug("PortalHandler::unregisterInvalidPortal", "Control Block Type == " +
|
Stargate.debug("PortalHandler::unregisterInvalidPortal", "Control Block Type == " +
|
||||||
block.getType().name());
|
block.getType().name() + " at " + control + " real: " + block + " facing " +
|
||||||
|
portal.getLocation().getYaw());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PortalRegistry.unregisterPortal(portal, false);
|
PortalRegistry.unregisterPortal(portal, false);
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public class PlayerTeleporter extends Teleporter {
|
|||||||
* @param origin <p>The portal the player teleports from</p>
|
* @param origin <p>The portal the player teleports from</p>
|
||||||
* @param event <p>The player move event triggering the event</p>
|
* @param event <p>The player move event triggering the event</p>
|
||||||
*/
|
*/
|
||||||
public void teleportPlayer(@NotNull Portal origin, @Nullable PlayerMoveEvent event) {
|
public boolean teleportPlayer(@NotNull Portal origin, @Nullable PlayerMoveEvent event) {
|
||||||
|
boolean success = true;
|
||||||
double velocity = player.getVelocity().length();
|
double velocity = player.getVelocity().length();
|
||||||
List<Entity> passengers = player.getPassengers();
|
List<Entity> passengers = player.getPassengers();
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ public class PlayerTeleporter extends Teleporter {
|
|||||||
if (!origin.equals(portal)) {
|
if (!origin.equals(portal)) {
|
||||||
exit = triggerPortalEvent(origin, new StargatePlayerPortalEvent(player, origin, portal, exit));
|
exit = triggerPortalEvent(origin, new StargatePlayerPortalEvent(player, origin, portal, exit));
|
||||||
if (exit == null) {
|
if (exit == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,14 +68,16 @@ public class PlayerTeleporter extends Teleporter {
|
|||||||
|
|
||||||
//If no event is passed in, assume it's a teleport, and act as such
|
//If no event is passed in, assume it's a teleport, and act as such
|
||||||
if (event == null) {
|
if (event == null) {
|
||||||
player.teleport(exit);
|
success &= player.teleport(exit);
|
||||||
} else {
|
} else {
|
||||||
//Set the exit location of the event
|
//Set the exit location of the event
|
||||||
|
success &= !event.isCancelled();
|
||||||
event.setTo(exit);
|
event.setTo(exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set the velocity of the teleported player after the teleportation is finished
|
//Set the velocity of the teleported player after the teleportation is finished
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () -> player.setVelocity(newVelocity), 1);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () -> player.setVelocity(newVelocity), 1);
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,185 +0,0 @@
|
|||||||
package net.knarcraft.stargate.transformation;
|
|
||||||
|
|
||||||
import org.bukkit.Axis;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.util.BlockVector;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class for performing rotational operations on vectors
|
|
||||||
*
|
|
||||||
* @author Kristian Knarvik
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class SimpleVectorOperation {
|
|
||||||
|
|
||||||
private static final Map<BlockFace, Double> rotationAngles = new HashMap<>();
|
|
||||||
private static final Map<BlockFace, Vector> rotationAxes = new HashMap<>();
|
|
||||||
private static final Map<BlockFace, Axis> normalAxes = new HashMap<>();
|
|
||||||
private static final BlockFace defaultDirection = BlockFace.SOUTH;
|
|
||||||
private static final Axis defaultVerticalAxis = Axis.Y;
|
|
||||||
|
|
||||||
private final Axis normalAxis;
|
|
||||||
private boolean flipZAxis = false;
|
|
||||||
private final BlockFace facing;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a vector operation to rotate vectors in the direction of a sign face
|
|
||||||
*
|
|
||||||
* @param signFace <p>The sign face of a gate's sign</p>
|
|
||||||
*/
|
|
||||||
public SimpleVectorOperation(@NotNull BlockFace signFace) {
|
|
||||||
if (normalAxes.isEmpty()) {
|
|
||||||
initializeIrisNormalAxes();
|
|
||||||
initializeOperations();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.facing = signFace;
|
|
||||||
this.normalAxis = normalAxes.get(signFace);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the block face of a sign given upon instantiation
|
|
||||||
*
|
|
||||||
* @return <p>The block face of a sign given upon instantiation</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public BlockFace getFacing() {
|
|
||||||
return facing;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the normal axis orthogonal to the opening plane
|
|
||||||
*
|
|
||||||
* <p>Said another way, get the axis going directly towards or away from a stargate's entrance.</p>
|
|
||||||
*
|
|
||||||
* @return <p>The normal axis orthogonal to the opening plane</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public Axis getNormalAxis() {
|
|
||||||
return normalAxis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether to flip the Z- axis
|
|
||||||
*
|
|
||||||
* @param flipZAxis <p>Whether to flip the z-axis</p>
|
|
||||||
*/
|
|
||||||
public void setFlipZAxis(boolean flipZAxis) {
|
|
||||||
this.flipZAxis = flipZAxis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs an operation from the real space to the vector space
|
|
||||||
*
|
|
||||||
* @param vector <p>The vector to perform the operation on</p>
|
|
||||||
* @return vector <p>A new vector with the operation applied</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public Vector performToAbstractSpaceOperation(@NotNull Vector vector) {
|
|
||||||
Vector clone = vector.clone();
|
|
||||||
clone.rotateAroundAxis(rotationAxes.get(facing), rotationAngles.get(facing));
|
|
||||||
if (flipZAxis) {
|
|
||||||
clone.setZ(-clone.getZ());
|
|
||||||
}
|
|
||||||
return clone;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs an operation from the vector space to the real space
|
|
||||||
*
|
|
||||||
* @param vector <p>The vector to perform the inverse operation on</p>
|
|
||||||
* @return vector <p>A new vector with the operation applied</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public Vector performToRealSpaceOperation(@NotNull Vector vector) {
|
|
||||||
Vector clone = vector.clone();
|
|
||||||
if (flipZAxis) {
|
|
||||||
clone.setZ(-clone.getZ());
|
|
||||||
}
|
|
||||||
return clone.rotateAroundAxis(rotationAxes.get(facing), -rotationAngles.get(facing));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs an operation from the vector space to the real space
|
|
||||||
*
|
|
||||||
* @param vector <p>The vector to perform the inverse operation on</p>
|
|
||||||
* @return vector <p>A new vector with the operation applied</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public BlockVector performToRealSpaceOperation(@NotNull BlockVector vector) {
|
|
||||||
return performToRealSpaceOperation((Vector) vector).toBlockVector();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the operations used for rotating to each block-face
|
|
||||||
*/
|
|
||||||
private static void initializeOperations() {
|
|
||||||
Map<Axis, Vector> axisVectors = new HashMap<>();
|
|
||||||
axisVectors.put(Axis.Y, new Vector(0, 1, 0));
|
|
||||||
axisVectors.put(Axis.X, new Vector(1, 0, 0));
|
|
||||||
axisVectors.put(Axis.Z, new Vector(0, 0, 1));
|
|
||||||
|
|
||||||
//Use the cross product to find the correct axis
|
|
||||||
for (BlockFace face : normalAxes.keySet()) {
|
|
||||||
Vector crossProduct = face.getDirection().crossProduct(defaultDirection.getDirection());
|
|
||||||
if (face == defaultDirection || face == defaultDirection.getOppositeFace()) {
|
|
||||||
rotationAxes.put(face, axisVectors.get(defaultVerticalAxis));
|
|
||||||
} else if (Math.abs(crossProduct.getZ()) > 0) {
|
|
||||||
rotationAxes.put(face, axisVectors.get(Axis.Z));
|
|
||||||
} else if (Math.abs(crossProduct.getY()) > 0) {
|
|
||||||
rotationAxes.put(face, axisVectors.get(Axis.Y));
|
|
||||||
} else {
|
|
||||||
rotationAxes.put(face, axisVectors.get(Axis.X));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
calculateRotations();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the required rotations based on the default rotation
|
|
||||||
*/
|
|
||||||
private static void calculateRotations() {
|
|
||||||
double halfRotation = Math.PI;
|
|
||||||
double quarterRotation = halfRotation / 2;
|
|
||||||
|
|
||||||
Vector defaultDirectionVector = defaultDirection.getDirection();
|
|
||||||
boolean defaultDirectionPositive = defaultDirectionVector.getX() + defaultDirectionVector.getY() +
|
|
||||||
defaultDirectionVector.getZ() > 0;
|
|
||||||
|
|
||||||
for (BlockFace blockFace : normalAxes.keySet()) {
|
|
||||||
if (defaultDirection == blockFace) {
|
|
||||||
//The default direction requires no rotation
|
|
||||||
rotationAngles.put(blockFace, 0d);
|
|
||||||
} else if (defaultDirection.getOppositeFace() == blockFace) {
|
|
||||||
//The opposite direction requires a half rotation
|
|
||||||
rotationAngles.put(blockFace, halfRotation);
|
|
||||||
} else {
|
|
||||||
//All the other used directions require a quarter rotation
|
|
||||||
Vector faceDirectionVector = blockFace.getDirection();
|
|
||||||
boolean faceDirectionPositive = faceDirectionVector.getX() + faceDirectionVector.getY() +
|
|
||||||
faceDirectionVector.getZ() > 0;
|
|
||||||
double rotation = defaultDirectionPositive && faceDirectionPositive ? quarterRotation : -quarterRotation;
|
|
||||||
rotationAngles.put(blockFace, rotation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the iris normal axes corresponding to each block face
|
|
||||||
*/
|
|
||||||
private static void initializeIrisNormalAxes() {
|
|
||||||
normalAxes.put(BlockFace.EAST, Axis.Z);
|
|
||||||
normalAxes.put(BlockFace.WEST, Axis.Z);
|
|
||||||
normalAxes.put(BlockFace.NORTH, Axis.X);
|
|
||||||
normalAxes.put(BlockFace.SOUTH, Axis.X);
|
|
||||||
normalAxes.put(BlockFace.UP, Axis.Y);
|
|
||||||
normalAxes.put(BlockFace.DOWN, Axis.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -39,3 +39,4 @@ signToUse=to use gate
|
|||||||
teleportMsg=Teleported
|
teleportMsg=Teleported
|
||||||
vaultLoadError=Economy is enabled but Vault could not be loaded. Economy disabled
|
vaultLoadError=Economy is enabled but Vault could not be loaded. Economy disabled
|
||||||
vaultLoaded=Vault v%version% found
|
vaultLoaded=Vault v%version% found
|
||||||
|
teleportationFailed=Teleportation was cancelled or denied
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package net.knarcraft.stargate.container;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
public class RelativeBlockVectorTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addToVectorTest() {
|
|
||||||
int right = 5;
|
|
||||||
int down = 5;
|
|
||||||
int out = 3;
|
|
||||||
|
|
||||||
RelativeBlockVector relativeBlockVector = new RelativeBlockVector(right, down, out);
|
|
||||||
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
|
||||||
int randomValue = getRandomNumber();
|
|
||||||
RelativeBlockVector newVector = relativeBlockVector.addRight(randomValue);
|
|
||||||
assertEquals(new RelativeBlockVector(right + randomValue, down, out), newVector);
|
|
||||||
|
|
||||||
newVector = relativeBlockVector.addOut(randomValue);
|
|
||||||
assertEquals(new RelativeBlockVector(right, down, out + randomValue), newVector);
|
|
||||||
|
|
||||||
newVector = relativeBlockVector.addDown(randomValue);
|
|
||||||
assertEquals(new RelativeBlockVector(right, down + randomValue, out), newVector);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void invertTest() {
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
|
||||||
int randomNumber1 = getRandomNumber();
|
|
||||||
int randomNumber2 = getRandomNumber();
|
|
||||||
int randomNumber3 = getRandomNumber();
|
|
||||||
|
|
||||||
RelativeBlockVector relativeBlockVector = new RelativeBlockVector(randomNumber1, randomNumber2,
|
|
||||||
randomNumber3);
|
|
||||||
RelativeBlockVector invertedBlockVector = new RelativeBlockVector(-randomNumber1, -randomNumber2,
|
|
||||||
-randomNumber3);
|
|
||||||
assertEquals(invertedBlockVector, relativeBlockVector.invert());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a random number between -500 and 500
|
|
||||||
*
|
|
||||||
* @return <p>A random number between -500 and 500</p>
|
|
||||||
*/
|
|
||||||
private int getRandomNumber() {
|
|
||||||
return (int) ((Math.random() - 0.5) * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user