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;
}
Aggregations