diff --git a/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java b/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java new file mode 100644 index 0000000..eb67b99 --- /dev/null +++ b/src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java @@ -0,0 +1,37 @@ +package net.knarcraft.stargate.utility; + +import net.knarcraft.stargate.BlockLocation; +import net.knarcraft.stargate.RelativeBlockVector; +import org.bukkit.Location; + +/** + * This class helps with direction-dependent (modX, modZ) calculations + */ +public class DirectionHelper { + + /** + * Gets the block at a relative block vector location + * + * @param vector
The relative block vector
+ * @returnThe block at the given relative position
+ */ + public static BlockLocation getBlockAt(BlockLocation topLeft, RelativeBlockVector vector, int modX, int modZ) { + return topLeft.modRelative(vector.getRight(), vector.getDepth(), vector.getDistance(), modX, 1, modZ); + } + + /** + * Adds a relative block vector to a location, accounting for direction + * @param locationThe location to adjust
+ * @param rightThe amount of blocks to the right to adjust
+ * @param depthThe amount of blocks upward to adjust
+ * @param distanceThe distance outward to adjust
+ * @param modXThe x modifier to use
+ * @param modZThe z modifier to use
+ * @returnThe altered location
+ */ + public static Location adjustLocation(Location location, double right, double depth, double distance, int modX, + int modZ) { + return location.add(-right * modX + distance * modZ, depth, -right * modZ + -distance * modX); + } + +}