Skip to content

Commit f91f923

Browse files
authored
bug fix
block was behaving weird when being rotated by mechanical bearing
1 parent bcb8681 commit f91f923

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/main/java/com/yu/fishycreatestuffs/content/throughshaftgearbox/ThroughShaftGearboxBlock.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.yu.fishycreatestuffs.content.throughshaftgearbox;
22

3+
import com.simibubi.create.content.contraptions.ITransformableBlock;
4+
import com.simibubi.create.content.contraptions.StructureTransform;
35
import com.yu.fishycreatestuffs.BlockEntityTypes;
46
import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity;
57
import com.simibubi.create.content.kinetics.base.KineticBlock;
@@ -18,6 +20,7 @@
1820
import net.minecraft.world.level.Level;
1921
import net.minecraft.world.level.LevelReader;
2022
import net.minecraft.world.level.block.Block;
23+
import net.minecraft.world.level.block.Rotation;
2124
import net.minecraft.world.level.block.entity.BlockEntity;
2225
import net.minecraft.world.level.block.entity.BlockEntityType;
2326
import net.minecraft.world.level.block.state.BlockState;
@@ -33,7 +36,7 @@
3336
import org.jetbrains.annotations.Nullable;
3437
import net.fabricmc.fabric.api.block.BlockPickInteractionAware;
3538

36-
public class ThroughShaftGearboxBlock extends KineticBlock implements IBE<ThroughShaftGearboxEntity>, BlockPickInteractionAware {
39+
public class ThroughShaftGearboxBlock extends KineticBlock implements IBE<ThroughShaftGearboxEntity>, BlockPickInteractionAware, ITransformableBlock {
3740

3841
public static final EnumProperty<Axis> AXIS = BlockStateProperties.AXIS;
3942
public static final DirectionProperty FACING = BlockStateProperties.FACING;
@@ -132,6 +135,26 @@ public BlockState getRotatedBlockState(BlockState originalState, Direction targe
132135
.setValue(FACING, originalState.getValue(FACING).getClockWise(rotateAxis));
133136
}
134137

138+
139+
140+
@Override
141+
public BlockState transform(BlockState state, StructureTransform transform) {
142+
Direction facing = state.getValue(FACING);
143+
Axis axis = state.getValue(AXIS);
144+
facing = rotate(facing, transform.rotationAxis, transform.rotation);
145+
axis = rotate(VoxelShaper.axisAsFace(axis), transform.rotationAxis, transform.rotation).getAxis();
146+
return state.setValue(FACING, facing).setValue(AXIS, axis);
147+
} //thanks duquee
148+
149+
public static Direction rotate(Direction direction, Direction.Axis axis, Rotation rotation) {
150+
return switch (rotation) {
151+
case CLOCKWISE_90 -> direction.getClockWise(axis);
152+
case COUNTERCLOCKWISE_90 -> direction.getCounterClockWise(axis);
153+
case CLOCKWISE_180 -> axis == direction.getAxis() ? direction : direction.getOpposite();
154+
case NONE -> direction;
155+
};
156+
}
157+
135158
@Override
136159
public Class<ThroughShaftGearboxEntity> getBlockEntityClass() {
137160
return ThroughShaftGearboxEntity.class;

0 commit comments

Comments
 (0)