2013-04-13 16:35:13 +02:00
|
|
|
package ic2.api;
|
|
|
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the 6 possible directions along the axis of a block.
|
|
|
|
*/
|
|
|
|
public enum Direction {
|
|
|
|
/**
|
|
|
|
* -X
|
|
|
|
*/
|
|
|
|
XN(0),
|
|
|
|
/**
|
|
|
|
* +X
|
|
|
|
*/
|
|
|
|
XP(1),
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
/**
|
|
|
|
* -Y
|
|
|
|
*/
|
|
|
|
YN(2), //MC-Code starts with 0 here
|
|
|
|
/**
|
|
|
|
* +Y
|
|
|
|
*/
|
|
|
|
YP(3), // 1...
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
/**
|
|
|
|
* -Z
|
|
|
|
*/
|
|
|
|
ZN(4),
|
|
|
|
/**
|
|
|
|
* +Z
|
|
|
|
*/
|
|
|
|
ZP(5);
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
Direction(int dir) {
|
|
|
|
this.dir = dir;
|
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
/*public CoordinateTuple ApplyToCoordinates(CoordinateTuple coordinates) {
|
|
|
|
CoordinateTuple ret = new CoordinateTuple(coordinates);
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
ret.coords[dir/2] += GetSign();
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
return ret;
|
|
|
|
}*/
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
/**
|
|
|
|
* Get the tile entity next to a tile entity following this direction.
|
|
|
|
*
|
|
|
|
* @param tileEntity tile entity to check
|
|
|
|
* @return Adjacent tile entity or null if none exists
|
|
|
|
*/
|
|
|
|
public TileEntity applyToTileEntity(TileEntity tileEntity) {
|
|
|
|
int coords[] = { tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord };
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
coords[dir/2] += getSign();
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
if (tileEntity.worldObj != null && tileEntity.worldObj.blockExists(coords[0], coords[1], coords[2])) {
|
2013-12-26 21:00:08 +01:00
|
|
|
try {
|
|
|
|
return tileEntity.worldObj.getBlockTileEntity(coords[0], coords[1], coords[2]);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException("error getting TileEntity at dim "+tileEntity.worldObj.provider.dimensionId+" "+coords[0]+"/"+coords[1]+"/"+coords[2]);
|
|
|
|
}
|
2013-04-13 16:35:13 +02:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
/**
|
|
|
|
* Get the inverse of this direction (XN -> XP, XP -> XN, etc.)
|
|
|
|
*
|
|
|
|
* @return Inverse direction
|
|
|
|
*/
|
|
|
|
public Direction getInverse() {
|
|
|
|
int inverseDir = dir - getSign();
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
for (Direction direction : directions) {
|
|
|
|
if (direction.dir == inverseDir) return direction;
|
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
return this;
|
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
/**
|
|
|
|
* Convert this direction to a Minecraft side value.
|
|
|
|
*
|
|
|
|
* @return Minecraft side value
|
|
|
|
*/
|
|
|
|
public int toSideValue() {
|
|
|
|
return (dir + 4) % 6;
|
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
/**
|
|
|
|
* Determine direction sign (N for negative or P for positive).
|
|
|
|
*
|
|
|
|
* @return -1 if the direction is negative, +1 if the direction is positive
|
|
|
|
*/
|
|
|
|
private int getSign() {
|
|
|
|
return (dir % 2) * 2 - 1;
|
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
public ForgeDirection toForgeDirection() {
|
|
|
|
return ForgeDirection.getOrientation(toSideValue());
|
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
private int dir;
|
2013-07-20 18:10:14 +02:00
|
|
|
public static final Direction[] directions = Direction.values();
|
2013-04-13 16:35:13 +02:00
|
|
|
}
|
|
|
|
|