diff --git a/src/main/java/li/cil/oc2/api/util/Side.java b/src/main/java/li/cil/oc2/api/util/Side.java index baded973..59c9e3aa 100644 --- a/src/main/java/li/cil/oc2/api/util/Side.java +++ b/src/main/java/li/cil/oc2/api/util/Side.java @@ -3,6 +3,8 @@ package li.cil.oc2.api.util; import net.minecraft.core.Direction; +import net.minecraft.core.Vec3i; +import net.minecraft.core.BlockPos; import javax.annotation.Nullable; @@ -73,4 +75,34 @@ public enum Side { public String toString() { return base != null ? base.toString() : super.toString(); } + + public static Direction relativeDirection(BlockPos from, BlockPos to) { + int dx = to.getX() - from.getX(); + int dy = to.getY() - from.getY(); + int dz = to.getZ() - from.getZ(); + if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > Math.abs(dz)) { + if (dx > 0) { + return Direction.EAST; + } + else { + return Direction.WEST; + } + } + else if (Math.abs(dy) > Math.abs(dx) && Math.abs(dy) > Math.abs(dz)) { + if (dy > 0) { + return Direction.UP; + } + else { + return Direction.DOWN; + } + } + else { + if (dz > 0) { + return Direction.SOUTH; + } + else { + return Direction.NORTH; + } + } + } }