From 79703e49afb076152506d4959784222b395106f0 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sat, 27 Feb 2021 21:15:39 +0100 Subject: [PATCH] Adds a class which helps with modZ and modX calculations --- .../stargate/utility/DirectionHelper.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/net/knarcraft/stargate/utility/DirectionHelper.java 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

+ * @return

The 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 location

The location to adjust

+ * @param right

The amount of blocks to the right to adjust

+ * @param depth

The amount of blocks upward to adjust

+ * @param distance

The distance outward to adjust

+ * @param modX

The x modifier to use

+ * @param modZ

The z modifier to use

+ * @return

The 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); + } + +}