Search in sources :

Example 1 with FaceAttachedHorizontalDirectionalBlock

use of net.minecraft.world.level.block.FaceAttachedHorizontalDirectionalBlock in project Create by Creators-of-Create.

the class StructureTransform method apply.

/**
 * Minecraft does not support blockstate rotation around axes other than y. Add
 * specific cases here for blockstates, that should react to rotations around
 * horizontal axes
 */
public BlockState apply(BlockState state) {
    if (mirror != null)
        state = state.mirror(mirror);
    Block block = state.getBlock();
    if (rotationAxis == Axis.Y) {
        if (block instanceof BellBlock) {
            if (state.getValue(BlockStateProperties.BELL_ATTACHMENT) == BellAttachType.DOUBLE_WALL)
                state = state.setValue(BlockStateProperties.BELL_ATTACHMENT, BellAttachType.SINGLE_WALL);
            return state.setValue(BellBlock.FACING, rotation.rotate(state.getValue(BellBlock.FACING)));
        }
        return state.rotate(rotation);
    }
    if (block instanceof AbstractChassisBlock)
        return rotateChassis(state);
    if (block instanceof FaceAttachedHorizontalDirectionalBlock) {
        DirectionProperty facingProperty = FaceAttachedHorizontalDirectionalBlock.FACING;
        EnumProperty<AttachFace> faceProperty = FaceAttachedHorizontalDirectionalBlock.FACE;
        Direction stateFacing = state.getValue(facingProperty);
        AttachFace stateFace = state.getValue(faceProperty);
        Direction forcedAxis = rotationAxis == Axis.Z ? Direction.EAST : Direction.SOUTH;
        if (stateFacing.getAxis() == rotationAxis && stateFace == AttachFace.WALL)
            return state;
        for (int i = 0; i < rotation.ordinal(); i++) {
            stateFace = state.getValue(faceProperty);
            stateFacing = state.getValue(facingProperty);
            boolean b = state.getValue(faceProperty) == AttachFace.CEILING;
            state = state.setValue(facingProperty, b ? forcedAxis : forcedAxis.getOpposite());
            if (stateFace != AttachFace.WALL) {
                state = state.setValue(faceProperty, AttachFace.WALL);
                continue;
            }
            if (stateFacing.getAxisDirection() == AxisDirection.POSITIVE) {
                state = state.setValue(faceProperty, AttachFace.FLOOR);
                continue;
            }
            state = state.setValue(faceProperty, AttachFace.CEILING);
        }
        return state;
    }
    boolean halfTurn = rotation == Rotation.CLOCKWISE_180;
    if (block instanceof StairBlock) {
        state = transformStairs(state, halfTurn);
        return state;
    }
    if (AllBlocks.BELT.has(state)) {
        state = transformBelt(state, halfTurn);
        return state;
    }
    if (state.hasProperty(FACING)) {
        Direction newFacing = transformFacing(state.getValue(FACING));
        if (state.hasProperty(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE)) {
            if (rotationAxis == newFacing.getAxis() && rotation.ordinal() % 2 == 1)
                state = state.cycle(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE);
        }
        state = state.setValue(FACING, newFacing);
    } else if (state.hasProperty(AXIS)) {
        state = state.setValue(AXIS, transformAxis(state.getValue(AXIS)));
    } else if (halfTurn) {
        if (state.hasProperty(FACING)) {
            Direction stateFacing = state.getValue(FACING);
            if (stateFacing.getAxis() == rotationAxis)
                return state;
        }
        if (state.hasProperty(HORIZONTAL_FACING)) {
            Direction stateFacing = state.getValue(HORIZONTAL_FACING);
            if (stateFacing.getAxis() == rotationAxis)
                return state;
        }
        state = state.rotate(rotation);
        if (state.hasProperty(SlabBlock.TYPE) && state.getValue(SlabBlock.TYPE) != SlabType.DOUBLE)
            state = state.setValue(SlabBlock.TYPE, state.getValue(SlabBlock.TYPE) == SlabType.BOTTOM ? SlabType.TOP : SlabType.BOTTOM);
    }
    return state;
}
Also used : FaceAttachedHorizontalDirectionalBlock(net.minecraft.world.level.block.FaceAttachedHorizontalDirectionalBlock) AttachFace(net.minecraft.world.level.block.state.properties.AttachFace) BellBlock(net.minecraft.world.level.block.BellBlock) AbstractChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock) BeltBlock(com.simibubi.create.content.contraptions.relays.belt.BeltBlock) SlabBlock(net.minecraft.world.level.block.SlabBlock) BellBlock(net.minecraft.world.level.block.BellBlock) AbstractChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock) FaceAttachedHorizontalDirectionalBlock(net.minecraft.world.level.block.FaceAttachedHorizontalDirectionalBlock) DirectionalAxisKineticBlock(com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock) Block(net.minecraft.world.level.block.Block) StairBlock(net.minecraft.world.level.block.StairBlock) StairBlock(net.minecraft.world.level.block.StairBlock) DirectionProperty(net.minecraft.world.level.block.state.properties.DirectionProperty) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Aggregations

DirectionalAxisKineticBlock (com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock)1 AbstractChassisBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock)1 BeltBlock (com.simibubi.create.content.contraptions.relays.belt.BeltBlock)1 Direction (net.minecraft.core.Direction)1 AxisDirection (net.minecraft.core.Direction.AxisDirection)1 BellBlock (net.minecraft.world.level.block.BellBlock)1 Block (net.minecraft.world.level.block.Block)1 FaceAttachedHorizontalDirectionalBlock (net.minecraft.world.level.block.FaceAttachedHorizontalDirectionalBlock)1 SlabBlock (net.minecraft.world.level.block.SlabBlock)1 StairBlock (net.minecraft.world.level.block.StairBlock)1 AttachFace (net.minecraft.world.level.block.state.properties.AttachFace)1 DirectionProperty (net.minecraft.world.level.block.state.properties.DirectionProperty)1