Renames RelativeBlockVector's right, depth and distance to right, down and out respectively

This commit is contained in:
2021-10-24 22:48:13 +02:00
parent 822f8fb2b5
commit 669767ef89
9 changed files with 82 additions and 71 deletions

View File

@ -86,29 +86,29 @@ public class BlockLocation extends Location {
* Gets a location relative to this block location
*
* @param relativeVector <p>The relative block vector describing the relative location</p>
* @param yaw <p>The yaw pointing outwards from a portal (in the relative vector's distance direction)</p>
* @param yaw <p>The yaw pointing outwards from a portal (in the relative vector's out direction)</p>
* @return <p>A location relative to this location</p>
*/
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
*
* <p>The distance goes in the direction of the yaw. Right goes in the direction of (yaw - 90) degrees.
* <p>Out goes in the direction of the yaw. Right goes in the direction of (yaw - 90) degrees.
* Depth goes downwards following the -y direction.</p>
*
* @param right <p>The amount of blocks to go right when looking towards a portal</p>
* @param depth <p>The amount of blocks to go downwards when looking towards a portal</p>
* @param distance <p>The amount of blocks to go outwards when looking towards a portal</p>
* @param down <p>The amount of blocks to go downwards when looking towards a portal</p>
* @param out <p>The amount of blocks to go outwards when looking towards a portal</p>
* @param portalYaw <p>The yaw when looking out from the portal</p>
* @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);
}

View File

@ -5,28 +5,33 @@ package net.knarcraft.stargate.container;
*
* <p>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.</p>
* 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.</p>
*/
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 <p>The distance to the right relative to the origin</p>
* @param depth <p>The distance downward relative to the origin</p>
* @param distance <p>The distance outward relative to the origin</p>
* <p>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.</p>
*
* @param right <p>The distance rightward relative to the origin</p>
* @param down <p>The distance downward relative to the origin</p>
* @param out <p>The distance outward relative to the origin</p>
*/
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 <p>This vector, but inverted</p>
*/
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 <p>The distance downward relative to the origin</p>
*/
public int getDepth() {
return depth;
public int getDown() {
return down;
}
/**
@ -81,13 +86,13 @@ public class RelativeBlockVector {
*
* @return <p>The distance outward relative to the origin</p>
*/
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;
}
}