diff --git a/src/main/java/net/knarcraft/stargate/container/BlockLocation.java b/src/main/java/net/knarcraft/stargate/container/BlockLocation.java index 1f552fb..bb8b533 100644 --- a/src/main/java/net/knarcraft/stargate/container/BlockLocation.java +++ b/src/main/java/net/knarcraft/stargate/container/BlockLocation.java @@ -86,29 +86,29 @@ public class BlockLocation extends Location { * Gets a location relative to this block location * * @param relativeVector

The relative block vector describing the relative location

- * @param yaw

The yaw pointing outwards from a portal (in the relative vector's distance direction)

+ * @param yaw

The yaw pointing outwards from a portal (in the relative vector's out direction)

* @return

A location relative to this location

*/ public BlockLocation getRelativeLocation(RelativeBlockVector relativeVector, double yaw) { Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(relativeVector.getRight(), - relativeVector.getDepth(), relativeVector.getDistance(), yaw); + relativeVector.getDown(), relativeVector.getOut(), yaw); return makeRelativeBlockLocation(realVector.getBlockX(), realVector.getBlockY(), realVector.getBlockZ()); } /** * Makes a location relative to the current location according to given parameters * - *

The distance goes in the direction of the yaw. Right goes in the direction of (yaw - 90) degrees. + *

Out goes in the direction of the yaw. Right goes in the direction of (yaw - 90) degrees. * Depth goes downwards following the -y direction.

* * @param right

The amount of blocks to go right when looking towards a portal

- * @param depth

The amount of blocks to go downwards when looking towards a portal

- * @param distance

The amount of blocks to go outwards when looking towards a portal

+ * @param down

The amount of blocks to go downwards when looking towards a portal

+ * @param out

The amount of blocks to go outwards when looking towards a portal

* @param portalYaw

The yaw when looking out from the portal

* @return A new location relative to this block location */ - public Location getRelativeLocation(double right, double depth, double distance, float portalYaw) { - Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(right, depth, distance, portalYaw); + public Location getRelativeLocation(double right, double down, double out, float portalYaw) { + Vector realVector = DirectionHelper.getCoordinateVectorFromRelativeVector(right, down, out, portalYaw); return makeRelativeLocation(0.5 + realVector.getBlockX(), realVector.getBlockY(), 0.5 + realVector.getBlockZ(), portalYaw); } diff --git a/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java b/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java index 30b23de..932ee84 100644 --- a/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java +++ b/src/main/java/net/knarcraft/stargate/container/RelativeBlockVector.java @@ -5,28 +5,33 @@ package net.knarcraft.stargate.container; * *

A relative block vector stores a vector relative to some origin. The origin in this plugin is usually the * top-left block of a gate (top-left when looking at the side with the sign). The right is therefore the distance - * from the top-left corner towards the top-right corner. Depth is the distance from the top-left corner to the - * bottom-left corner. Distance is the distance outward from the gate.

+ * from the top-left corner towards the top-right corner. Down is the distance from the top-left corner towards the + * bottom-left corner. Out is the distance outward from the gate.

*/ public class RelativeBlockVector { private final int right; - private final int depth; - private final int distance; + private final int down; + private final int out; - public enum Property {RIGHT, DEPTH, DISTANCE} + public enum Property {RIGHT, DOWN, OUT} /** * Instantiates a new relative block vector * - * @param right

The distance to the right relative to the origin

- * @param depth

The distance downward relative to the origin

- * @param distance

The distance outward relative to the origin

+ *

Relative block vectors start from a top-left corner. A yaw is used to orient a relative block vector in the + * "real world". + * In terms of a gate layout, the origin is 0,0. Right is towards the end of the line. Down is to the + * next line. Out is towards the observer.

+ * + * @param right

The distance rightward relative to the origin

+ * @param down

The distance downward relative to the origin

+ * @param out

The distance outward relative to the origin

*/ - public RelativeBlockVector(int right, int depth, int distance) { + public RelativeBlockVector(int right, int down, int out) { this.right = right; - this.depth = depth; - this.distance = distance; + this.down = down; + this.out = out; } /** @@ -39,11 +44,11 @@ public class RelativeBlockVector { public RelativeBlockVector addToVector(Property propertyToAddTo, int valueToAdd) { switch (propertyToAddTo) { case RIGHT: - return new RelativeBlockVector(this.right + valueToAdd, this.depth, this.distance); - case DEPTH: - return new RelativeBlockVector(this.right, this.depth + valueToAdd, this.distance); - case DISTANCE: - return new RelativeBlockVector(this.right, this.depth, this.distance + valueToAdd); + return new RelativeBlockVector(this.right + valueToAdd, this.down, this.out); + case DOWN: + return new RelativeBlockVector(this.right, this.down + valueToAdd, this.out); + case OUT: + return new RelativeBlockVector(this.right, this.down, this.out + valueToAdd); default: throw new IllegalArgumentException("Invalid relative block vector property given"); } @@ -55,7 +60,7 @@ public class RelativeBlockVector { * @return

This vector, but inverted

*/ public RelativeBlockVector invert() { - return new RelativeBlockVector(-this.right, -this.depth, -this.distance); + return new RelativeBlockVector(-this.right, -this.down, -this.out); } /** @@ -72,8 +77,8 @@ public class RelativeBlockVector { * * @return

The distance downward relative to the origin

*/ - public int getDepth() { - return depth; + public int getDown() { + return down; } /** @@ -81,13 +86,13 @@ public class RelativeBlockVector { * * @return

The distance outward relative to the origin

*/ - public int getDistance() { - return distance; + public int getOut() { + return out; } @Override public String toString() { - return String.format("(right = %d, depth = %d, distance = %d)", right, depth, distance); + return String.format("(right = %d, down = %d, out = %d)", right, down, out); } @Override @@ -99,8 +104,8 @@ public class RelativeBlockVector { return false; } RelativeBlockVector otherVector = (RelativeBlockVector) other; - return this.right == otherVector.right && this.depth == otherVector.depth && - this.distance == otherVector.distance; + return this.right == otherVector.right && this.down == otherVector.down && + this.out == otherVector.out; } } diff --git a/src/main/java/net/knarcraft/stargate/portal/Gate.java b/src/main/java/net/knarcraft/stargate/portal/Gate.java index 31b36c1..0d0c312 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Gate.java +++ b/src/main/java/net/knarcraft/stargate/portal/Gate.java @@ -189,7 +189,7 @@ public class Gate { Map characterMaterialMap = new HashMap<>(this.characterMaterialMap); for (RelativeBlockVector borderVector : layout.getBorder()) { int rowIndex = borderVector.getRight(); - int lineIndex = borderVector.getDepth(); + int lineIndex = borderVector.getDown(); Character key = layout.getLayout()[lineIndex][rowIndex]; Material materialInLayout = characterMaterialMap.get(key); diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java b/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java index 0714e2a..e5c06e7 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java @@ -276,7 +276,7 @@ public class PortalCreator { BlockFace buttonFacing) { //Go one block outwards to find the button's location rather than the control block's location BlockLocation button = topLeft.getRelativeLocation(buttonVector.addToVector( - RelativeBlockVector.Property.DISTANCE, 1), portal.getYaw()); + RelativeBlockVector.Property.OUT, 1), portal.getYaw()); Directional buttonData = (Directional) Bukkit.createBlockData(portal.getGate().getPortalButton()); buttonData.setFacing(buttonFacing); diff --git a/src/main/java/net/knarcraft/stargate/portal/Teleporter.java b/src/main/java/net/knarcraft/stargate/portal/Teleporter.java index f4c8040..683fc04 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Teleporter.java +++ b/src/main/java/net/knarcraft/stargate/portal/Teleporter.java @@ -146,7 +146,7 @@ public abstract class Teleporter { RelativeBlockVector openingEdge = relativeExit; do { RelativeBlockVector possibleOpening = new RelativeBlockVector(openingEdge.getRight() + direction, - openingEdge.getDepth(), openingEdge.getDistance()); + openingEdge.getDown(), openingEdge.getOut()); if (portal.getGate().getLayout().getExits().contains(possibleOpening)) { openingEdge = possibleOpening; } else { diff --git a/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java b/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java index 5564633..3229c6d 100644 --- a/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java @@ -5,7 +5,7 @@ import org.bukkit.block.BlockFace; import org.bukkit.util.Vector; /** - * This class helps with direction-dependent calculations + * This class helps with direction-related calculations */ public final class DirectionHelper { @@ -17,11 +17,12 @@ public final class DirectionHelper { * Gets a yaw by comparing two locations * *

The yaw here is the direction an observer a the first location has to look to face the second location. - * The yaw is only meant to be calculated for locations with equal x or equal z.

+ * The yaw is only meant to be calculated for locations where both have either the same x value or the same z value. + * Equal locations, or locations with equal x and equal z will throw an exception.

* * @param location1

The first location, which works as the origin

- * @param location2

The second location, which the yaw will point at

- * @return

The yaw

+ * @param location2

The second location, which the yaw will point towards

+ * @return

The yaw pointing from the first location to the second location

*/ public static float getYawFromLocationDifference(Location location1, Location location2) { Location difference = location1.clone().subtract(location2.clone()); @@ -38,9 +39,11 @@ public final class DirectionHelper { } /** - * Gets a block face given a yaw + * Gets a block face given a yaw value * - * @param yaw

The yaw to use

+ *

The supplied yaw must be a value such that (yaw mod 90) = 0. If not, an exception is thrown.

+ * + * @param yaw

The yaw value to convert

* @return

The block face the yaw corresponds to

*/ public static BlockFace getBlockFaceFromYaw(double yaw) { @@ -56,15 +59,15 @@ public final class DirectionHelper { } else if (yaw == 270) { return BlockFace.EAST; } else { - throw new IllegalArgumentException("Invalid yaw given"); + throw new IllegalArgumentException("Invalid yaw given. Yaw must be divisible by 90."); } } /** * Gets a direction vector given a yaw * - * @param yaw

The yaw to use

- * @return

The direction vector of the yaw

+ * @param yaw

The yaw to convert to a direction vector

+ * @return

The direction vector pointing in the same direction as the yaw

*/ public static Vector getDirectionVectorFromYaw(double yaw) { //Make sure the yaw is between 0 and 360 @@ -84,37 +87,40 @@ public final class DirectionHelper { } /** - * Moves a location relatively + * Moves a location by the given amounts * - * @param location

The location to move

- * @param right

The amount to go right (When looking at the front of a portal)

- * @param depth

The amount to go downward (When looking at the front of a portal)

- * @param distance

The amount to go outward (When looking a the front of a portal)

+ *

The right, down and out work the same as for the relative block vector. Looking a the front of a portal, + * right goes rightwards, down goes downwards and out goes towards the observer.

+ * + * @param location

The location to start at

+ * @param right

The amount to go right

+ * @param down

The amount to go downward

+ * @param out

The amount to go outward

* @param yaw

The yaw when looking directly outwards from a portal

* @return

A location relative to the given location

*/ - public static Location moveLocation(Location location, double right, double depth, double distance, double yaw) { - return location.add(getCoordinateVectorFromRelativeVector(right, depth, distance, yaw)); + public static Location moveLocation(Location location, double right, double down, double out, double yaw) { + return location.add(getCoordinateVectorFromRelativeVector(right, down, out, yaw)); } /** * Gets a vector in Minecraft's normal X,Y,Z-space from a relative block vector * - * @param right

The amount of right steps from the top-left origin

- * @param depth

The amount of downward steps from the top-left origin

- * @param distance

The distance outward from the top-left origin

- * @param yaw

The yaw when looking directly outwards from a portal

+ * @param right

The amount of rightward steps from the top-left origin

+ * @param down

The amount of downward steps from the top-left origin

+ * @param out

The distance outward from the top-left origin

+ * @param yaw

The yaw when looking directly outwards from a portal

* @return

A normal vector

*/ - public static Vector getCoordinateVectorFromRelativeVector(double right, double depth, double distance, double yaw) { + public static Vector getCoordinateVectorFromRelativeVector(double right, double down, double out, double yaw) { Vector distanceVector = DirectionHelper.getDirectionVectorFromYaw(yaw); - distanceVector.multiply(distance); + distanceVector.multiply(out); Vector rightVector = DirectionHelper.getDirectionVectorFromYaw(yaw - 90); rightVector.multiply(right); Vector depthVector = new Vector(0, -1, 0); - depthVector.multiply(depth); + depthVector.multiply(down); return distanceVector.add(rightVector).add(depthVector); } diff --git a/src/test/java/net/knarcraft/stargate/RelativeBlockVectorTest.java b/src/test/java/net/knarcraft/stargate/RelativeBlockVectorTest.java index 8310474..f75aefe 100644 --- a/src/test/java/net/knarcraft/stargate/RelativeBlockVectorTest.java +++ b/src/test/java/net/knarcraft/stargate/RelativeBlockVectorTest.java @@ -12,8 +12,8 @@ public class RelativeBlockVectorTest { public void getTest() { RelativeBlockVector relativeBlockVector = new RelativeBlockVector(56, 44, 23); assertEquals(56, relativeBlockVector.getRight()); - assertEquals(44, relativeBlockVector.getDepth()); - assertEquals(23, relativeBlockVector.getDistance()); + assertEquals(44, relativeBlockVector.getDown()); + assertEquals(23, relativeBlockVector.getOut()); } @Test diff --git a/src/test/java/net/knarcraft/stargate/container/BlockLocationTest.java b/src/test/java/net/knarcraft/stargate/container/BlockLocationTest.java index c3cd916..520627a 100644 --- a/src/test/java/net/knarcraft/stargate/container/BlockLocationTest.java +++ b/src/test/java/net/knarcraft/stargate/container/BlockLocationTest.java @@ -27,22 +27,22 @@ public class BlockLocationTest { RelativeBlockVector relativeBlockVector = new RelativeBlockVector(2, 1, 3); BlockLocation relativeLocation1 = startLocation.getRelativeLocation(relativeBlockVector, 0); - //With yaw = 0, going right goes in the x direction, and distance goes in the z direction, while y is decremented + //With yaw = 0, going right goes in the x direction, and out goes in the z direction, while y is decremented BlockLocation targetLocation1 = new BlockLocation(world, 9, 2, 9); Assertions.assertEquals(targetLocation1, relativeLocation1); BlockLocation relativeLocation2 = startLocation.getRelativeLocation(relativeBlockVector, 90); - //With yaw = 90, going right goes in the z direction, and distance goes in the -x direction, while y is decremented + //With yaw = 90, going right goes in the z direction, and out goes in the -x direction, while y is decremented BlockLocation targetLocation2 = new BlockLocation(world, 4, 2, 8); Assertions.assertEquals(targetLocation2, relativeLocation2); BlockLocation relativeLocation3 = startLocation.getRelativeLocation(relativeBlockVector, 180); - //With yaw = 180, going right goes in the -x direction, and distance goes in the -z direction, while y is decremented + //With yaw = 180, going right goes in the -x direction, and out goes in the -z direction, while y is decremented BlockLocation targetLocation3 = new BlockLocation(world, 5, 2, 3); Assertions.assertEquals(targetLocation3, relativeLocation3); BlockLocation relativeLocation4 = startLocation.getRelativeLocation(relativeBlockVector, 270); - //With yaw = 270, going right goes in the -z direction, and distance goes in the x direction, while y is decremented + //With yaw = 270, going right goes in the -z direction, and out goes in the x direction, while y is decremented BlockLocation targetLocation4 = new BlockLocation(world, 10, 2, 4); Assertions.assertEquals(targetLocation4, relativeLocation4); } diff --git a/src/test/java/net/knarcraft/stargate/container/RelativeBlockVectorTest.java b/src/test/java/net/knarcraft/stargate/container/RelativeBlockVectorTest.java index 54613f1..8259b37 100644 --- a/src/test/java/net/knarcraft/stargate/container/RelativeBlockVectorTest.java +++ b/src/test/java/net/knarcraft/stargate/container/RelativeBlockVectorTest.java @@ -8,21 +8,21 @@ public class RelativeBlockVectorTest { @Test public void addToVectorTest() { int right = 5; - int depth = 5; - int distance = 3; + int down = 5; + int out = 3; - RelativeBlockVector relativeBlockVector = new RelativeBlockVector(right, depth, distance); + RelativeBlockVector relativeBlockVector = new RelativeBlockVector(right, down, out); for (int i = 0; i < 1000; i++) { int randomValue = getRandomNumber(); RelativeBlockVector newVector = relativeBlockVector.addToVector(RelativeBlockVector.Property.RIGHT, randomValue); - Assertions.assertEquals(new RelativeBlockVector(right + randomValue, depth, distance), newVector); + Assertions.assertEquals(new RelativeBlockVector(right + randomValue, down, out), newVector); - newVector = relativeBlockVector.addToVector(RelativeBlockVector.Property.DISTANCE, randomValue); - Assertions.assertEquals(new RelativeBlockVector(right, depth, distance + randomValue), newVector); + newVector = relativeBlockVector.addToVector(RelativeBlockVector.Property.OUT, randomValue); + Assertions.assertEquals(new RelativeBlockVector(right, down, out + randomValue), newVector); - newVector = relativeBlockVector.addToVector(RelativeBlockVector.Property.DEPTH, randomValue); - Assertions.assertEquals(new RelativeBlockVector(right, depth + randomValue, distance), newVector); + newVector = relativeBlockVector.addToVector(RelativeBlockVector.Property.DOWN, randomValue); + Assertions.assertEquals(new RelativeBlockVector(right, down + randomValue, out), newVector); } }