001 package net.minecraftforge.common;
002
003 public enum ForgeDirection
004 {
005 /** -Y */
006 DOWN(0, -1, 0),
007
008 /** +Y */
009 UP(0, 1, 0),
010
011 /** -Z */
012 NORTH(0, 0, -1),
013
014 /** +Z */
015 SOUTH(0, 0, 1),
016
017 /** -X */
018 WEST(-1, 0, 0),
019
020 /** +X */
021 EAST(1, 0, 0),
022
023 /**
024 * Used only by getOrientation, for invalid inputs
025 */
026 UNKNOWN(0, 0, 0);
027
028 public final int offsetX;
029 public final int offsetY;
030 public final int offsetZ;
031 public final int flag;
032 public static final ForgeDirection[] VALID_DIRECTIONS = {DOWN, UP, NORTH, SOUTH, WEST, EAST};
033 public static final int[] OPPOSITES = {1, 0, 3, 2, 5, 4, 6};
034 // Left hand rule rotation matrix for all possible axes of rotation
035 public static final int[][] ROTATION_MATRIX = {
036 {0, 1, 4, 5, 3, 2, 6},
037 {0, 1, 5, 4, 2, 3, 6},
038 {5, 4, 2, 3, 0, 1, 6},
039 {4, 5, 2, 3, 1, 0, 6},
040 {2, 3, 1, 0, 4, 5, 6},
041 {3, 2, 0, 1, 4, 5, 6},
042 {0, 1, 2, 3, 4, 5, 6},
043 };
044
045 private ForgeDirection(int x, int y, int z)
046 {
047 offsetX = x;
048 offsetY = y;
049 offsetZ = z;
050 flag = 1 << ordinal();
051 }
052
053 public static ForgeDirection getOrientation(int id)
054 {
055 if (id >= 0 && id < VALID_DIRECTIONS.length)
056 {
057 return VALID_DIRECTIONS[id];
058 }
059 return UNKNOWN;
060 }
061
062 public ForgeDirection getOpposite()
063 {
064 return getOrientation(OPPOSITES[ordinal()]);
065 }
066
067 public ForgeDirection getRotation(ForgeDirection axis)
068 {
069 return getOrientation(ROTATION_MATRIX[axis.ordinal()][ordinal()]);
070 }
071 }