public static EnumFacing intersects(Vec3d origin, Vec3d direction, AxisAlignedBB bbox)

{

double[] ray = getRay(origin, direction);

if ((direction.xCoord < 0.0D) && (direction.yCoord < 0.0D) && (direction.zCoord < 0.0D))

{

if (origin.xCoord < bbox.minX) {

return null;

}

if (origin.yCoord < bbox.minY) {

return null;

}

if (origin.zCoord < bbox.minZ) {

return null;

}

if (side(ray, getEdgeRay(Edge.EF, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.EH, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.DH, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.DC, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.BC, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.BF, bbox)) < 0.0D) {

return null;

}

if ((side(ray, getEdgeRay(Edge.HG, bbox)) > 0.0D) && (side(ray, getEdgeRay(Edge.FG, bbox)) < 0.0D)) {

return EnumFacing.SOUTH;

}

if (side(ray, getEdgeRay(Edge.CG, bbox)) < 0.0D) {

return EnumFacing.UP;

}

return EnumFacing.EAST;

}

if ((direction.xCoord < 0.0D) && (direction.yCoord < 0.0D) && (direction.zCoord >= 0.0D))

{

if (origin.xCoord < bbox.minX) {

return null;

}

if (origin.yCoord < bbox.minY) {

return null;

}

if (origin.zCoord > bbox.maxZ) {

return null;

}

if (side(ray, getEdgeRay(Edge.HG, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.DH, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AD, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AB, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.BF, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.FG, bbox)) < 0.0D) {

return null;

}

if ((side(ray, getEdgeRay(Edge.DC, bbox)) > 0.0D) && (side(ray, getEdgeRay(Edge.CG, bbox)) > 0.0D)) {

return EnumFacing.EAST;

}

if (side(ray, getEdgeRay(Edge.BC, bbox)) < 0.0D) {

return EnumFacing.UP;

}

return EnumFacing.NORTH;

}

if ((direction.xCoord < 0.0D) && (direction.yCoord >= 0.0D) && (direction.zCoord < 0.0D))

{

if (origin.xCoord < bbox.minX) {

return null;

}

if (origin.yCoord > bbox.maxY) {

return null;

}

if (origin.zCoord < bbox.minZ) {

return null;

}

if (side(ray, getEdgeRay(Edge.FG, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.EF, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AE, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AD, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.DC, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.CG, bbox)) < 0.0D) {

return null;

}

if ((side(ray, getEdgeRay(Edge.EH, bbox)) > 0.0D) && (side(ray, getEdgeRay(Edge.HG, bbox)) > 0.0D)) {

return EnumFacing.SOUTH;

}

if (side(ray, getEdgeRay(Edge.DH, bbox)) < 0.0D) {

return EnumFacing.EAST;

}

return EnumFacing.DOWN;

}

if ((direction.xCoord < 0.0D) && (direction.yCoord >= 0.0D) && (direction.zCoord >= 0.0D))

{

if (origin.xCoord < bbox.minX) {

return null;

}

if (origin.yCoord > bbox.maxY) {

return null;

}

if (origin.zCoord > bbox.maxZ) {

return null;

}

if (side(ray, getEdgeRay(Edge.EH, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AE, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AB, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.BC, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.CG, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.HG, bbox)) > 0.0D) {

return null;

}

if ((side(ray, getEdgeRay(Edge.AD, bbox)) > 0.0D) && (side(ray, getEdgeRay(Edge.DH, bbox)) > 0.0D)) {

return EnumFacing.DOWN;

}

if (side(ray, getEdgeRay(Edge.DC, bbox)) < 0.0D) {

return EnumFacing.NORTH;

}

return EnumFacing.EAST;

}

if ((direction.xCoord >= 0.0D) && (direction.yCoord < 0.0D) && (direction.zCoord < 0.0D))

{

if (origin.xCoord > bbox.maxX) {

return null;

}

if (origin.yCoord < bbox.minY) {

return null;

}

if (origin.zCoord < bbox.minZ) {

return null;

}

if (side(ray, getEdgeRay(Edge.AB, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AE, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.EH, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.HG, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.CG, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.BC, bbox)) > 0.0D) {

return null;

}

if ((side(ray, getEdgeRay(Edge.EF, bbox)) > 0.0D) && (side(ray, getEdgeRay(Edge.BF, bbox)) < 0.0D)) {

return EnumFacing.WEST;

}

if (side(ray, getEdgeRay(Edge.FG, bbox)) < 0.0D) {

return EnumFacing.SOUTH;

}

return EnumFacing.UP;

}

if ((direction.xCoord >= 0.0D) && (direction.yCoord < 0.0D) && (direction.zCoord >= 0.0D))

{

if (origin.xCoord > bbox.maxX) {

return null;

}

if (origin.yCoord < bbox.minY) {

return null;

}

if (origin.zCoord > bbox.maxZ) {

return null;

}

if (side(ray, getEdgeRay(Edge.DC, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AD, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AE, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.EF, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.FG, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.CG, bbox)) > 0.0D) {

return null;

}

if ((side(ray, getEdgeRay(Edge.AB, bbox)) > 0.0D) && (side(ray, getEdgeRay(Edge.BC, bbox)) > 0.0D)) {

return EnumFacing.NORTH;

}

if (side(ray, getEdgeRay(Edge.BF, bbox)) < 0.0D) {

return EnumFacing.WEST;

}

return EnumFacing.UP;

}

if ((direction.xCoord >= 0.0D) && (direction.yCoord >= 0.0D) && (direction.zCoord < 0.0D))

{

if (origin.xCoord > bbox.maxX) {

return null;

}

if (origin.yCoord > bbox.maxY) {

return null;

}

if (origin.zCoord < bbox.minZ) {

return null;

}

if (side(ray, getEdgeRay(Edge.BF, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AB, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.AD, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.DH, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.HG, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.FG, bbox)) > 0.0D) {

return null;

}

if ((side(ray, getEdgeRay(Edge.AE, bbox)) > 0.0D) && (side(ray, getEdgeRay(Edge.EF, bbox)) > 0.0D)) {

return EnumFacing.WEST;

}

if (side(ray, getEdgeRay(Edge.EH, bbox)) < 0.0D) {

return EnumFacing.DOWN;

}

return EnumFacing.SOUTH;

}

if (origin.xCoord > bbox.maxX) {

return null;

}

if (origin.yCoord > bbox.maxY) {

return null;

}

if (origin.zCoord > bbox.maxZ) {

return null;

}

if (side(ray, getEdgeRay(Edge.EF, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.EH, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.DH, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.DC, bbox)) > 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.BC, bbox)) < 0.0D) {

return null;

}

if (side(ray, getEdgeRay(Edge.BF, bbox)) > 0.0D) {

return null;

}

if ((side(ray, getEdgeRay(Edge.AB, bbox)) < 0.0D) && (side(ray, getEdgeRay(Edge.AE, bbox)) > 0.0D)) {

return EnumFacing.WEST;

}

if (side(ray, getEdgeRay(Edge.AD, bbox)) < 0.0D) {

return EnumFacing.NORTH;

}

return EnumFacing.DOWN; }