Fastest pixel blitting renderer being created in Java. 3D renderer. For educational purposes and most importantly, FUN
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SigRenderer2/src/sig/FacingDirection.java

44 lines
1.8 KiB

package sig;
public enum FacingDirection {
SOUTH,
WEST,
NORTH,
EAST;
static FacingDirection[] orderList = new FacingDirection[]{SOUTH,WEST,NORTH,EAST};
FacingDirection clockwise() {
return orderList[(this.ordinal()+1)%orderList.length];
}
FacingDirection counterClockwise() {
return orderList[Math.floorMod((this.ordinal()-1),orderList.length)];
}
boolean isOpposite(FacingDirection dir) {
return this.ordinal()!=dir.ordinal()&&this.ordinal()%2==dir.ordinal()%2;
}
public static boolean isFacingEachOther(Block b1, Block b2) {
float xDiff=b1.pos.x-b2.pos.x;
float zDiff=b1.pos.z-b2.pos.z;
if (Math.abs(xDiff)+Math.abs(zDiff)==1) {
return (xDiff==-1&&b1.getFacingDirection()==WEST&&b2.getFacingDirection()==EAST)||
(xDiff==1&&b1.getFacingDirection()==EAST&&b2.getFacingDirection()==WEST)||
(zDiff==-1&&b1.getFacingDirection()==NORTH&&b2.getFacingDirection()==SOUTH)||
(zDiff==1&&b1.getFacingDirection()==SOUTH&&b2.getFacingDirection()==NORTH);
} else {
return false;
}
}
public static boolean isFacingAwayFromEachOther(Block b1, Block b2) {
float xDiff=b1.pos.x-b2.pos.x;
float zDiff=b1.pos.z-b2.pos.z;
if (Math.abs(xDiff)+Math.abs(zDiff)==1) {
return (xDiff==-1&&b1.getFacingDirection()==EAST&&b2.getFacingDirection()==WEST)||
(xDiff==1&&b1.getFacingDirection()==WEST&&b2.getFacingDirection()==EAST)||
(zDiff==-1&&b1.getFacingDirection()==SOUTH&&b2.getFacingDirection()==NORTH)||
(zDiff==1&&b1.getFacingDirection()==NORTH&&b2.getFacingDirection()==SOUTH);
} else {
return false;
}
}
}