net.minecraft.util.BlockRotation Java Examples

The following examples show how to use net.minecraft.util.BlockRotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Walkway.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public BlockState rotate(BlockState state, BlockRotation rotation) {
    switch (rotation) {
        case CLOCKWISE_180:
            return state.with(NORTH, state.get(SOUTH)).with(EAST, state.get(WEST)).with(SOUTH, state.get(NORTH)).with(WEST, state.get(EAST));
        case COUNTERCLOCKWISE_90:
            return state.with(NORTH, state.get(EAST)).with(EAST, state.get(SOUTH)).with(SOUTH, state.get(WEST)).with(WEST, state.get(NORTH));
        case CLOCKWISE_90:
            return state.with(NORTH, state.get(WEST)).with(EAST, state.get(NORTH)).with(SOUTH, state.get(EAST)).with(WEST, state.get(SOUTH));
        default:
            return state;
    }
}
 
Example #2
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BlockState rotate(BlockState blockState_1, BlockRotation blockRotation_1) {
    return WrappingUtil.convert(block.rotate(
            (org.sandboxpowered.sandbox.api.state.BlockState) blockState_1,
            WrappingUtil.convert(blockRotation_1)
    ));
}
 
Example #3
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BlockState rotate(BlockState blockState_1, BlockRotation blockRotation_1) {
    return WrappingUtil.convert(block.rotate(
            (org.sandboxpowered.sandbox.api.state.BlockState) blockState_1,
            WrappingUtil.convert(blockRotation_1)
    ));
}
 
Example #4
Source File: MoonVillagePiece.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public MoonVillagePiece(StructureManager structureManager, StructurePoolElement structurePoolElement, BlockPos blockPos, int i, BlockRotation blockRotation, BlockBox blockBox) {
    super(GalacticraftStructurePieceTypes.MOON_VILLAGE, structureManager, structurePoolElement, blockPos, i, blockRotation, blockBox);
}
 
Example #5
Source File: IForgeBlockState.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
default BlockState rotate(IWorld world, BlockPos pos, BlockRotation direction) {
	return patchwork$getForgeBlock().rotate(getBlockState(), world, pos, direction);
}
 
Example #6
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
default BlockState rotate(BlockState state, IWorld world, BlockPos pos, BlockRotation direction) {
	return state.rotate(direction);
}
 
Example #7
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Rotation convert(BlockRotation rotation) {
    return Rotation.values()[rotation.ordinal()];
}
 
Example #8
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static BlockRotation convert(Rotation rotation) {
    return BlockRotation.values()[rotation.ordinal()];
}
 
Example #9
Source File: BlockRotator.java    From fabric-carpet with MIT License 4 votes vote down vote up
public static boolean flip_block(BlockState state, World world, PlayerEntity player, Hand hand, BlockHitResult hit)
{
    Block block = state.getBlock();
    BlockPos pos = hit.getBlockPos();
    Vec3d hitVec = hit.getPos().subtract(pos.getX(), pos.getY(), pos.getZ());
    Direction facing = hit.getSide();
    BlockState newState = null;
    if ( (block instanceof GlazedTerracottaBlock) || (block instanceof AbstractRedstoneGateBlock) || (block instanceof RailBlock) ||
         (block instanceof TrapdoorBlock)         || (block instanceof LeverBlock)         || (block instanceof FenceGateBlock))
    {
        newState = state.rotate(BlockRotation.CLOCKWISE_90);
    }
    else if ((block instanceof ObserverBlock) || (block instanceof EndRodBlock))
    {
        newState = state.with(FacingBlock.FACING, (Direction) state.get(FacingBlock.FACING).getOpposite());
    }
    else if (block instanceof DispenserBlock)
    {
        newState = state.with(DispenserBlock.FACING, state.get(DispenserBlock.FACING).getOpposite());
    }
    else if (block instanceof PistonBlock)
    {
        if (!(state.get(PistonBlock.EXTENDED)))
            newState = state.with(FacingBlock.FACING, state.get(FacingBlock.FACING).getOpposite());
    }
    else if (block instanceof SlabBlock)
    {
        if (((SlabBlock) block).hasSidedTransparency(state))
        {
            newState =  state.with(SlabBlock.TYPE, state.get(SlabBlock.TYPE) == SlabType.TOP ? SlabType.BOTTOM : SlabType.TOP);
        }
    }
    else if (block instanceof HopperBlock)
    {
        if ((Direction)state.get(HopperBlock.FACING) != Direction.DOWN)
        {
            newState =  state.with(HopperBlock.FACING, state.get(HopperBlock.FACING).rotateYClockwise());
        }
    }
    else if (block instanceof StairsBlock)
    {
        //LOG.error(String.format("hit with facing: %s, at side %.1fX, X %.1fY, Y %.1fZ",facing, hitX, hitY, hitZ));
        if ((facing == Direction.UP && hitVec.y == 1.0f) || (facing == Direction.DOWN && hitVec.y == 0.0f))
        {
            newState =  state.with(StairsBlock.HALF, state.get(StairsBlock.HALF) == BlockHalf.TOP ? BlockHalf.BOTTOM : BlockHalf.TOP );
        }
        else
        {
            boolean turn_right;
            if (facing == Direction.NORTH)
            {
                turn_right = (hitVec.x <= 0.5);
            }
            else if (facing == Direction.SOUTH)
            {
                turn_right = !(hitVec.x <= 0.5);
            }
            else if (facing == Direction.EAST)
            {
                turn_right = (hitVec.z <= 0.5);
            }
            else if (facing == Direction.WEST)
            {
                turn_right = !(hitVec.z <= 0.5);
            }
            else
            {
                return false;
            }
            if (turn_right)
            {
                newState = state.rotate(BlockRotation.COUNTERCLOCKWISE_90);
            }
            else
            {
                newState = state.rotate(BlockRotation.CLOCKWISE_90);
            }
        }
    }
    else
    {
        return false;
    }
    if (newState != null)
    {
        world.setBlockState(pos, newState, 2 | 1024);
        world.checkBlockRerender(pos, state, newState);
        return true;
    }
    return false;
}