下面列出了net.minecraft.util.EnumFacing#rotateAround ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void main(String str[]) {
for(EnumFacing stationFacing : EnumFacing.values()) {
for(EnumFacing dirFacing : EnumFacing.values() ) {
EnumFacing cross = dirFacing.rotateAround(stationFacing.getAxis());
System.out.println();
}
}
}
public static EnumFacing rotateAround(EnumFacing facing, EnumFacing rotationAxis)
{
EnumFacing newFacing = facing.rotateAround(rotationAxis.getAxis());
if (rotationAxis.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
return newFacing;
}
// Negative axis direction, if the facing was actually rotated then get the opposite
return newFacing != facing ? newFacing.getOpposite() : facing;
}
/**
* Helper method to add back a way to do left hand rotations, like ForgeDirection had.
*/
public static EnumFacing getRotation(EnumFacing facing, EnumFacing axis)
{
EnumFacing newFacing = facing.rotateAround(axis.getAxis());
if (axis.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
return newFacing;
}
// Negative axis direction, if the facing was actually rotated then get the opposite
return newFacing != facing ? newFacing.getOpposite() : facing;
}
private boolean walkFrameLoop(BlockPos pos, EnumFacing.Axis axis, EnumFacing frameSide, int distanceLimit)
{
int counter = 0;
int turns = 0;
int tries = 0;
IBlockState state;
Block block;
BlockPos startPos = pos;
BlockPos posLast = startPos;
EnumFacing firstTrySide = frameSide;
EnumFacing moveDirection = frameSide;
while (counter < distanceLimit)
{
moveDirection = firstTrySide;
for (tries = 0; tries < 4; tries++)
{
pos = posLast.offset(moveDirection);
state = this.world.getBlockState(pos);
block = state.getBlock();
if (block.isAir(state, this.world, pos))
{
posLast = pos;
// The firstTrySide is facing into the adjacent portal frame when traveling
// along a straight frame. Thus we need to rotate it once to keep going straight.
// If we need to rotate it more than once, then we have hit a "right hand corner".
if (tries > 1)
{
turns++;
}
// If we didn't have to rotate the firstTrySide at all, then we hit a "left hand turn"
// ie. traveled through an outer bend.
else if (tries == 0)
{
turns--;
}
// Set the firstTrySide one rotation back from the side that we successfully moved to
// so that we can go around possible outer bends.
firstTrySide = moveDirection.rotateAround(axis).getOpposite();
break;
}
// Found a portal frame block, try the next adjacent side...
else if (block == this.blockFrame)
{
moveDirection = moveDirection.rotateAround(axis);
}
// Found a non-air, non-portal-frame block -> invalid area.
else
{
return false;
}
}
// If we can return to the starting position hugging the portal frame,
// then this is a valid portal frame loop.
// Note that it is only valid if it forms an inside area, thus the turns check.
// the tries == 4 && counter == 0 check is for a 1x1 area special case
if ((tries == 4 && counter == 0) || pos.equals(startPos))
{
return turns >= 0;
}
counter++;
}
return false;
}