Java Code Examples for net.minecraft.util.math.Direction#EAST

The following examples show how to use net.minecraft.util.math.Direction#EAST . 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: BlockRotator.java    From fabric-carpet with MIT License 6 votes vote down vote up
private static Direction rotateClockwise(Direction direction, Direction.Axis direction$Axis_1) {
    switch(direction$Axis_1) {
        case X:
            if (direction != Direction.WEST && direction != Direction.EAST) {
                return rotateXClockwise(direction);
            }

            return direction;
        case Y:
            if (direction != Direction.UP && direction != Direction.DOWN) {
                return rotateYClockwise(direction);
            }

            return direction;
        case Z:
            if (direction != Direction.NORTH && direction != Direction.SOUTH) {
                return rotateZClockwise(direction);
            }

            return direction;
        default:
            throw new IllegalStateException("Unable to get CW facing for axis " + direction$Axis_1);
    }
}
 
Example 2
Source File: BlockValue.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public Direction[] getPlacementDirections() {
    switch(this.facing) {
        case DOWN:
        default:
            return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP};
        case UP:
            return new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
        case NORTH:
            return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.SOUTH};
        case SOUTH:
            return new Direction[]{Direction.DOWN, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.NORTH};
        case WEST:
            return new Direction[]{Direction.DOWN, Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.EAST};
        case EAST:
            return new Direction[]{Direction.DOWN, Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.WEST};
    }
}
 
Example 3
Source File: Protocol_1_12_2.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public boolean acceptBlockState(BlockState state) {
    Block block = state.getBlock();
    if (block == Blocks.TNT)
        return super.acceptBlockState(state.with(TntBlock.UNSTABLE, false)); // re-add unstable because it was absent from 1.13.0 :thonkjang:

    if (!super.acceptBlockState(state))
        return false;

    if (block instanceof LeavesBlock && state.get(LeavesBlock.DISTANCE) < 6)
        return false;
    if (block == Blocks.PISTON_HEAD && state.get(PistonHeadBlock.SHORT))
        return false;
    if (state.getEntries().containsKey(Properties.WATERLOGGED) && state.get(Properties.WATERLOGGED))
        return false;
    if (block == Blocks.LEVER) {
        WallMountLocation face = state.get(LeverBlock.FACE);
        Direction facing = state.get(LeverBlock.FACING);
        if ((face == WallMountLocation.FLOOR || face == WallMountLocation.CEILING) && (facing == Direction.SOUTH || facing == Direction.EAST))
            return false;
    }
    if (block instanceof TrapdoorBlock && state.get(TrapdoorBlock.POWERED))
        return false;
    if ((block == Blocks.OAK_WOOD || block == Blocks.SPRUCE_WOOD
            || block == Blocks.BIRCH_WOOD || block == Blocks.JUNGLE_WOOD
            || block == Blocks.ACACIA_WOOD || block == Blocks.DARK_OAK_WOOD)
            && state.get(PillarBlock.AXIS) != Direction.Axis.Y)
        return false;
    return true;
}
 
Example 4
Source File: HopperMinecartEntity_transferItemsOutFeatureMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Inventory getOutputInventory() {
    Vec3d offsetToInventory = getBlockBelowCartOffset();
    //The visual rotation point of the minecart is roughly 0.5 above its feet (determined visually ingame)
    //Search 0.5 Blocks below the feet for an inventory
    Inventory inv =  HopperBlockEntity.getInventoryAt(this.world, this.getX() + offsetToInventory.x, this.getY() + 0.5 + offsetToInventory.y, this.getZ() + offsetToInventory.z);

    //There is probably a way nicer way to determine the access side of the target inventory
    if(inv instanceof BlockEntity){
        BlockPos pos = ((BlockEntity) inv).getPos();
        if(pos.getY() < MathHelper.floor(this.getY()))
            outputDirection = Direction.DOWN;
        else if(pos.getX() > MathHelper.floor(this.getX()))
            outputDirection = Direction.EAST;
        else if(pos.getX() < MathHelper.floor(this.getX()))
            outputDirection = Direction.WEST;
        else if(pos.getZ() > MathHelper.floor(this.getZ()))
            outputDirection = Direction.SOUTH;
        else if(pos.getZ() < MathHelper.floor(this.getZ()))
            outputDirection = Direction.NORTH;
        else outputDirection = Direction.DOWN;
    }else
        outputDirection = Direction.DOWN;



    return inv;
}
 
Example 5
Source File: BlockRotator.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static Direction rotateYClockwise(Direction dir) {
    switch(dir) {
        case NORTH:
            return Direction.EAST;
        case EAST:
            return Direction.SOUTH;
        case SOUTH:
            return Direction.WEST;
        case WEST:
            return Direction.NORTH;
        default:
            throw new IllegalStateException("Unable to get Y-rotated facing of " + dir);
    }
}
 
Example 6
Source File: BlockRotator.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static Direction rotateZClockwise(Direction dir) {
    switch(dir) {
        case EAST:
            return Direction.DOWN;
        case SOUTH:
        default:
            throw new IllegalStateException("Unable to get Z-rotated facing of " + dir);
        case WEST:
            return Direction.UP;
        case UP:
            return Direction.EAST;
        case DOWN:
            return Direction.WEST;
    }
}
 
Example 7
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;
}