|
1 | 1 | package com.yu.fishycreatestuffs.content.throughshaftgearbox;
|
2 | 2 |
|
| 3 | +import com.simibubi.create.content.contraptions.ITransformableBlock; |
| 4 | +import com.simibubi.create.content.contraptions.StructureTransform; |
3 | 5 | import com.yu.fishycreatestuffs.BlockEntityTypes;
|
4 | 6 | import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity;
|
5 | 7 | import com.simibubi.create.content.kinetics.base.KineticBlock;
|
|
18 | 20 | import net.minecraft.world.level.Level;
|
19 | 21 | import net.minecraft.world.level.LevelReader;
|
20 | 22 | import net.minecraft.world.level.block.Block;
|
| 23 | +import net.minecraft.world.level.block.Rotation; |
21 | 24 | import net.minecraft.world.level.block.entity.BlockEntity;
|
22 | 25 | import net.minecraft.world.level.block.entity.BlockEntityType;
|
23 | 26 | import net.minecraft.world.level.block.state.BlockState;
|
|
33 | 36 | import org.jetbrains.annotations.Nullable;
|
34 | 37 | import net.fabricmc.fabric.api.block.BlockPickInteractionAware;
|
35 | 38 |
|
36 |
| -public class ThroughShaftGearboxBlock extends KineticBlock implements IBE<ThroughShaftGearboxEntity>, BlockPickInteractionAware { |
| 39 | +public class ThroughShaftGearboxBlock extends KineticBlock implements IBE<ThroughShaftGearboxEntity>, BlockPickInteractionAware, ITransformableBlock { |
37 | 40 |
|
38 | 41 | public static final EnumProperty<Axis> AXIS = BlockStateProperties.AXIS;
|
39 | 42 | public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
@@ -132,6 +135,26 @@ public BlockState getRotatedBlockState(BlockState originalState, Direction targe
|
132 | 135 | .setValue(FACING, originalState.getValue(FACING).getClockWise(rotateAxis));
|
133 | 136 | }
|
134 | 137 |
|
| 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 | + |
135 | 158 | @Override
|
136 | 159 | public Class<ThroughShaftGearboxEntity> getBlockEntityClass() {
|
137 | 160 | return ThroughShaftGearboxEntity.class;
|
|
0 commit comments