Add ability to rotate diagonal cable block freely (possibly breaking!)
- Click on face with connector to flip connector to opposite face - Click on face opposite a connector to rotate second connector CW - Click on face coplanar with both connectors to rotate both of them CW - Possibly breaking: FACING property replaced with FACING_PRIMARY and _SECONDARY properties
This commit is contained in:
@@ -1,88 +1,256 @@
|
||||
{
|
||||
"variants": {
|
||||
"facing=down,facing_up=false,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block"
|
||||
"facing_primary=down,facing_secondary=down,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing=down,facing_up=false,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block"
|
||||
"facing_primary=down,facing_secondary=down,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing=down,facing_up=true,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up"
|
||||
"facing_primary=down,facing_secondary=east,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down"
|
||||
},
|
||||
"facing=down,facing_up=true,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up"
|
||||
"facing_primary=down,facing_secondary=east,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down"
|
||||
},
|
||||
"facing=east,facing_up=false,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block"
|
||||
},
|
||||
"facing=east,facing_up=false,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block"
|
||||
},
|
||||
"facing=east,facing_up=true,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up"
|
||||
},
|
||||
"facing=east,facing_up=true,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up"
|
||||
},
|
||||
"facing=north,facing_up=false,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block",
|
||||
"facing_primary=down,facing_secondary=north,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 270
|
||||
},
|
||||
"facing=north,facing_up=false,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block",
|
||||
"facing_primary=down,facing_secondary=north,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 270
|
||||
},
|
||||
"facing=north,facing_up=true,waterlogged=false": {
|
||||
"facing_primary=down,facing_secondary=south,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 90
|
||||
},
|
||||
"facing_primary=down,facing_secondary=south,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 90
|
||||
},
|
||||
"facing_primary=down,facing_secondary=up,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=down,facing_secondary=up,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=down,facing_secondary=west,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=down,facing_secondary=west,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=east,facing_secondary=down,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=down,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=east,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=east,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=north,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=north,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=south,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 90
|
||||
},
|
||||
"facing_primary=east,facing_secondary=south,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 90
|
||||
},
|
||||
"facing_primary=east,facing_secondary=up,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=up,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=west,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=east,facing_secondary=west,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=north,facing_secondary=down,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 270
|
||||
},
|
||||
"facing_primary=north,facing_secondary=down,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 270
|
||||
},
|
||||
"facing_primary=north,facing_secondary=east,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal"
|
||||
},
|
||||
"facing_primary=north,facing_secondary=east,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal"
|
||||
},
|
||||
"facing_primary=north,facing_secondary=north,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=north,facing_secondary=north,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=north,facing_secondary=south,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=north,facing_secondary=south,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=north,facing_secondary=up,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 270
|
||||
},
|
||||
"facing=north,facing_up=true,waterlogged=true": {
|
||||
"facing_primary=north,facing_secondary=up,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 270
|
||||
},
|
||||
"facing=south,facing_up=false,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block",
|
||||
"facing_primary=north,facing_secondary=west,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 270
|
||||
},
|
||||
"facing_primary=north,facing_secondary=west,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 270
|
||||
},
|
||||
"facing_primary=south,facing_secondary=down,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 90
|
||||
},
|
||||
"facing=south,facing_up=false,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block",
|
||||
"facing_primary=south,facing_secondary=down,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 90
|
||||
},
|
||||
"facing=south,facing_up=true,waterlogged=false": {
|
||||
"facing_primary=south,facing_secondary=east,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 90
|
||||
},
|
||||
"facing_primary=south,facing_secondary=east,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 90
|
||||
},
|
||||
"facing_primary=south,facing_secondary=north,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=south,facing_secondary=north,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=south,facing_secondary=south,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=south,facing_secondary=south,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=south,facing_secondary=up,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 90
|
||||
},
|
||||
"facing=south,facing_up=true,waterlogged=true": {
|
||||
"facing_primary=south,facing_secondary=up,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 90
|
||||
},
|
||||
"facing=up,facing_up=false,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block"
|
||||
"facing_primary=south,facing_secondary=west,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 180
|
||||
},
|
||||
"facing=up,facing_up=false,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block"
|
||||
"facing_primary=south,facing_secondary=west,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 180
|
||||
},
|
||||
"facing=up,facing_up=true,waterlogged=false": {
|
||||
"facing_primary=up,facing_secondary=down,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=up,facing_secondary=down,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=up,facing_secondary=east,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up"
|
||||
},
|
||||
"facing=up,facing_up=true,waterlogged=true": {
|
||||
"facing_primary=up,facing_secondary=east,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up"
|
||||
},
|
||||
"facing=west,facing_up=false,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block",
|
||||
"y": 180
|
||||
"facing_primary=up,facing_secondary=north,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 270
|
||||
},
|
||||
"facing=west,facing_up=false,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block",
|
||||
"y": 180
|
||||
"facing_primary=up,facing_secondary=north,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 270
|
||||
},
|
||||
"facing=west,facing_up=true,waterlogged=false": {
|
||||
"facing_primary=up,facing_secondary=south,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 90
|
||||
},
|
||||
"facing_primary=up,facing_secondary=south,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 90
|
||||
},
|
||||
"facing_primary=up,facing_secondary=up,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=up,facing_secondary=up,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=up,facing_secondary=west,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 180
|
||||
},
|
||||
"facing=west,facing_up=true,waterlogged=true": {
|
||||
"facing_primary=up,facing_secondary=west,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=west,facing_secondary=down,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=west,facing_secondary=down,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_down",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=west,facing_secondary=east,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=west,facing_secondary=east,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=west,facing_secondary=north,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 270
|
||||
},
|
||||
"facing_primary=west,facing_secondary=north,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 270
|
||||
},
|
||||
"facing_primary=west,facing_secondary=south,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=west,facing_secondary=south,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_horizontal",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=west,facing_secondary=up,waterlogged=false": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=west,facing_secondary=up,waterlogged=true": {
|
||||
"model": "tfmg:block/diagonal_cable_block/block_up",
|
||||
"y": 180
|
||||
},
|
||||
"facing_primary=west,facing_secondary=west,waterlogged=false": {
|
||||
"model": "minecraft:block/air"
|
||||
},
|
||||
"facing_primary=west,facing_secondary=west,waterlogged=true": {
|
||||
"model": "minecraft:block/air"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,13 +99,17 @@ public class TFMGShapes {
|
||||
.add(3, 11, 3, 13, 16, 13)
|
||||
.add(3, 0, 3, 13, 5, 13)
|
||||
.forDirectional(),
|
||||
DIAGONAL_CABLE_BLOCK_DOWN = shape(3, 3, 11, 13, 13, 16)
|
||||
.add(3, 11, 3, 13, 16, 13)
|
||||
.add(4, 4, 5, 12, 11, 12)
|
||||
DIAGONAL_CABLE_BLOCK_DOWN = shape(3, 3, 11, 13, 13, 16) // DOWN conn
|
||||
.add(3, 11, 3, 13, 16, 13) // EAST conn
|
||||
.add(4, 4, 5, 12, 11, 12) // Cable box
|
||||
.forDirectional(),
|
||||
DIAGONAL_CABLE_BLOCK_UP = shape(3, 3, 0, 13, 13, 5)
|
||||
.add(3, 11, 3, 13, 16, 13)
|
||||
.add(4, 4, 5, 12, 11, 12)
|
||||
DIAGONAL_CABLE_BLOCK_UP = shape(3, 3, 0, 13, 13, 5) // UP conn
|
||||
.add(3, 11, 3, 13, 16, 13) // EAST conn
|
||||
.add(4, 4, 5, 12, 11, 12) // Cable box
|
||||
.forDirectional(),
|
||||
DIAGONAL_CABLE_BLOCK_HORIZONTAL = shape(0, 3, 3, 5, 13, 13) // NORTH conn
|
||||
.add(3, 11, 3, 13, 16, 13) // EAST conn
|
||||
.add(4, 4, 5, 12, 11, 12) // Cable box
|
||||
.forDirectional(),
|
||||
CASTING_BASIN = shape(0, 0, 0, 16, 8, 16)
|
||||
.add(4, 8, 14, 12, 13, 16)
|
||||
@@ -145,7 +149,6 @@ public class TFMGShapes {
|
||||
FULL = shape(0, 0, 0, 16, 16, 16).build(),
|
||||
ELECTRIC_POST = shape(4, 0, 4, 12, 16, 12).build(),
|
||||
SLAB = shape(0, 0, 0, 16, 8, 16).build();
|
||||
;
|
||||
|
||||
private static Builder shape(VoxelShape shape) {
|
||||
return new Builder(shape);
|
||||
|
||||
@@ -23,9 +23,11 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
@@ -36,22 +38,27 @@ import java.util.Objects;
|
||||
@SuppressWarnings({"unused","deprecation"})
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
public class DiagonalCableBlock extends DirectionalBlock implements SimpleWaterloggedBlock, IWrenchable, IBE<DiagonalCableBlockEntity> {
|
||||
public class DiagonalCableBlock extends Block implements SimpleWaterloggedBlock, IWrenchable, IBE<DiagonalCableBlockEntity> {
|
||||
|
||||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||
public static final BooleanProperty FACING_UP = BooleanProperty.create("facing_up");
|
||||
public DiagonalCableBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, Boolean.FALSE).setValue(FACING, Direction.NORTH).setValue(FACING_UP, false));
|
||||
public static final DirectionProperty FACING_PRIMARY = DirectionProperty.create("facing_primary");
|
||||
public static final DirectionProperty FACING_SECONDARY = DirectionProperty.create("facing_secondary");
|
||||
|
||||
public DiagonalCableBlock(Properties properties) {
|
||||
super(properties);
|
||||
this.registerDefaultState(this.stateDefinition.any()
|
||||
.setValue(WATERLOGGED, Boolean.FALSE)
|
||||
.setValue(FACING_PRIMARY, Direction.NORTH)
|
||||
.setValue(FACING_SECONDARY, Direction.DOWN));
|
||||
}
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_55125_) {
|
||||
p_55125_.add(WATERLOGGED,FACING, FACING_UP);
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(WATERLOGGED, FACING_PRIMARY, FACING_SECONDARY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockState p_51475_) {
|
||||
return p_51475_.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(p_51475_);
|
||||
public FluidState getFluidState(BlockState blockState) {
|
||||
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
|
||||
}
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
@@ -61,32 +68,93 @@ public class DiagonalCableBlock extends DirectionalBlock implements SimpleWaterl
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
public VoxelShape getShape(BlockState state, BlockGetter p_54562_, BlockPos p_54563_, CollisionContext p_54564_) {
|
||||
|
||||
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
||||
Direction primary = state.getValue(FACING_PRIMARY);
|
||||
Direction secondary = state.getValue(FACING_SECONDARY);
|
||||
|
||||
// Determine which axis is vertical (if any)
|
||||
boolean primaryIsVertical = primary.getAxis() == Direction.Axis.Y;
|
||||
boolean secondaryIsVertical = secondary.getAxis() == Direction.Axis.Y;
|
||||
|
||||
if (primaryIsVertical || secondaryIsVertical) {
|
||||
// Vertical cable case (UP/DOWN + horizontal)
|
||||
Direction vertical = primaryIsVertical ? primary : secondary;
|
||||
Direction horizontal = primaryIsVertical ? secondary : primary;
|
||||
|
||||
if (state.getValue(FACING_UP)) {
|
||||
return TFMGShapes.DIAGONAL_CABLE_BLOCK_UP.get(state.getValue(FACING));
|
||||
return vertical == Direction.UP
|
||||
? TFMGShapes.DIAGONAL_CABLE_BLOCK_UP.get(horizontal)
|
||||
: TFMGShapes.DIAGONAL_CABLE_BLOCK_DOWN.get(horizontal);
|
||||
} else {
|
||||
// Horizontal cable case (two horizontal directions)
|
||||
boolean isClockwise = isClockwisePair(primary, secondary);
|
||||
Direction shapeDirection = isClockwise ? primary : secondary;
|
||||
return TFMGShapes.DIAGONAL_CABLE_BLOCK_HORIZONTAL.get(shapeDirection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return TFMGShapes.DIAGONAL_CABLE_BLOCK_DOWN.get(state.getValue(FACING));
|
||||
|
||||
|
||||
private boolean isClockwisePair(Direction a, Direction b) {
|
||||
// Check if the pair follows the clockwise NE, ES, SW, WN sequence
|
||||
return (a == Direction.NORTH && b == Direction.EAST) ||
|
||||
(a == Direction.EAST && b == Direction.SOUTH) ||
|
||||
(a == Direction.SOUTH && b == Direction.WEST) ||
|
||||
(a == Direction.WEST && b == Direction.NORTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
|
||||
InteractionResult onWrenched = IWrenchable.super.onWrenched(state, context);
|
||||
if (!onWrenched.consumesAction())
|
||||
return onWrenched;
|
||||
InteractionResult result = IWrenchable.super.onWrenched(state, context);
|
||||
if (!result.consumesAction()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
context.getLevel().setBlock(context.getClickedPos(),state.setValue(FACING_UP,!state.getValue(FACING_UP)),2);
|
||||
Direction clickedFace = context.getClickedFace();
|
||||
Direction primary = state.getValue(FACING_PRIMARY);
|
||||
Direction secondary = state.getValue(FACING_SECONDARY);
|
||||
|
||||
withBlockEntityDo(context.getLevel(),context.getClickedPos(), IElectric::onPlaced);
|
||||
BlockState newState = calculateRotatedState(state, clickedFace, primary, secondary);
|
||||
|
||||
context.getLevel().setBlock(context.getClickedPos(), newState, Block.UPDATE_ALL);
|
||||
withBlockEntityDo(context.getLevel(), context.getClickedPos(), IElectric::onPlaced);
|
||||
IWrenchable.playRotateSound(context.getLevel(), context.getClickedPos());
|
||||
return onWrenched;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private BlockState calculateRotatedState(BlockState currentState, Direction clickedFace,
|
||||
Direction primary, Direction secondary) {
|
||||
// Flip primary if clicking it
|
||||
if (clickedFace == primary) {
|
||||
return currentState.setValue(FACING_PRIMARY, clickedFace);
|
||||
}
|
||||
|
||||
// Flip secondary if clicking it
|
||||
if (clickedFace == secondary) {
|
||||
return currentState.setValue(FACING_SECONDARY, clickedFace);
|
||||
}
|
||||
|
||||
// Rotate secondary around primary axis
|
||||
if (clickedFace == primary.getOpposite()) {
|
||||
return currentState.setValue(FACING_SECONDARY, rotateAroundAxis(secondary, primary.getAxis()));
|
||||
}
|
||||
|
||||
// Rotate primary around secondary axis
|
||||
if (clickedFace == secondary.getOpposite()) {
|
||||
return currentState.setValue(FACING_PRIMARY, rotateAroundAxis(primary, secondary.getAxis()));
|
||||
}
|
||||
|
||||
// Rotate both around clicked axis
|
||||
return currentState
|
||||
.setValue(FACING_PRIMARY, rotateAroundAxis(primary, clickedFace.getAxis()))
|
||||
.setValue(FACING_SECONDARY, rotateAroundAxis(secondary, clickedFace.getAxis()));
|
||||
}
|
||||
|
||||
private Direction rotateAroundAxis(Direction direction, Direction.Axis axis) {
|
||||
// Skip rotation if already aligned with the axis
|
||||
if (direction.getAxis() == axis) {
|
||||
return direction;
|
||||
}
|
||||
return direction.getClockWise(axis);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,17 +175,20 @@ public class DiagonalCableBlock extends DirectionalBlock implements SimpleWaterl
|
||||
Direction facing = Objects.requireNonNull(context.getPlayer()).getDirection();
|
||||
Direction clickedFace = context.getClickedFace();
|
||||
|
||||
if (context.getPlayer() != null && context.getPlayer().isShiftKeyDown()) {
|
||||
if (clickedFace == Direction.DOWN)
|
||||
return defaultBlockState().setValue(FACING, facing.getOpposite()).setValue(FACING_UP,true).setValue(WATERLOGGED, flag);
|
||||
else
|
||||
return defaultBlockState().setValue(FACING, facing.getOpposite()).setValue(FACING_UP,false).setValue(WATERLOGGED, flag);
|
||||
if (context.getPlayer() != null) {
|
||||
if (clickedFace.getAxis() == Direction.Axis.Y)
|
||||
return defaultBlockState()
|
||||
.setValue(FACING_PRIMARY, clickedFace.getOpposite())
|
||||
.setValue(FACING_SECONDARY, facing)
|
||||
.setValue(WATERLOGGED, flag);
|
||||
else {
|
||||
return defaultBlockState()
|
||||
.setValue(FACING_PRIMARY, facing)
|
||||
.setValue(FACING_SECONDARY, facing.getClockWise(Direction.Axis.Y))
|
||||
.setValue(WATERLOGGED, flag);
|
||||
}
|
||||
}
|
||||
if (clickedFace == Direction.DOWN)
|
||||
return defaultBlockState().setValue(FACING, facing).setValue(FACING_UP,true).setValue(WATERLOGGED, flag);
|
||||
|
||||
|
||||
return defaultBlockState().setValue(FACING, facing).setValue(FACING_UP,false).setValue(WATERLOGGED, flag);
|
||||
return defaultBlockState().setValue(FACING_PRIMARY, Direction.UP).setValue(FACING_SECONDARY,facing).setValue(WATERLOGGED, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static com.drmangotea.tfmg.content.electricity.connection.diagonal.DiagonalCableBlock.FACING_UP;
|
||||
import static com.drmangotea.tfmg.content.electricity.connection.diagonal.DiagonalCableBlock.*;
|
||||
import static net.minecraft.world.level.block.DirectionalBlock.FACING;
|
||||
|
||||
public class DiagonalCableBlockEntity extends ElectricBlockEntity {
|
||||
@@ -20,14 +20,6 @@ public class DiagonalCableBlockEntity extends ElectricBlockEntity {
|
||||
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
|
||||
if(getBlockState().getValue(FACING_UP)){
|
||||
|
||||
return direction == Direction.UP||direction == getBlockState().getValue(FACING);
|
||||
|
||||
|
||||
}else {
|
||||
return direction == Direction.DOWN||direction == getBlockState().getValue(FACING);
|
||||
}
|
||||
return direction == getBlockState().getValue(FACING_PRIMARY) || direction == getBlockState().getValue(FACING_SECONDARY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,15 @@ package com.drmangotea.tfmg.content.electricity.connection.diagonal;
|
||||
import com.simibubi.create.foundation.data.SpecialBlockStateGen;
|
||||
import com.tterrag.registrate.providers.DataGenContext;
|
||||
import com.tterrag.registrate.providers.RegistrateBlockstateProvider;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
|
||||
import static com.drmangotea.tfmg.content.electricity.connection.diagonal.DiagonalCableBlock.FACING_PRIMARY;
|
||||
import static com.drmangotea.tfmg.content.electricity.connection.diagonal.DiagonalCableBlock.FACING_SECONDARY;
|
||||
import static com.simibubi.create.foundation.data.AssetLookup.partialBaseModel;
|
||||
import static net.minecraft.core.Direction.*;
|
||||
|
||||
public class DiagonalCableGenerator extends SpecialBlockStateGen {
|
||||
|
||||
@@ -18,24 +22,53 @@ public class DiagonalCableGenerator extends SpecialBlockStateGen {
|
||||
|
||||
@Override
|
||||
protected int getYRotation(BlockState state) {
|
||||
return switch (state.getValue(DiagonalCableBlock.FACING)) {
|
||||
case NORTH -> 270;
|
||||
case SOUTH -> 90;
|
||||
case WEST -> 180;
|
||||
case EAST -> 0;
|
||||
case DOWN -> 0;
|
||||
case UP -> 0;
|
||||
};
|
||||
Direction primaryFacing = state.getValue(FACING_PRIMARY);
|
||||
Direction secondaryFacing = state.getValue(FACING_SECONDARY);
|
||||
|
||||
if (primaryFacing == UP || primaryFacing == DOWN)
|
||||
return switch (secondaryFacing) {
|
||||
case NORTH -> 270;
|
||||
case SOUTH -> 90;
|
||||
case WEST -> 180;
|
||||
case EAST -> 0;
|
||||
default -> 0;
|
||||
};
|
||||
else if (secondaryFacing == UP || secondaryFacing == DOWN)
|
||||
return switch (primaryFacing) {
|
||||
case NORTH -> 270;
|
||||
case SOUTH -> 90;
|
||||
case WEST -> 180;
|
||||
case EAST -> 0;
|
||||
default -> 0;
|
||||
};
|
||||
else if (primaryFacing.getAxis().isHorizontal() && secondaryFacing.getAxis().isHorizontal()) {
|
||||
if (primaryFacing == NORTH && secondaryFacing == EAST || primaryFacing == EAST && secondaryFacing == NORTH)
|
||||
return 0;
|
||||
if (primaryFacing == EAST && secondaryFacing == SOUTH || primaryFacing == SOUTH && secondaryFacing == EAST)
|
||||
return 90;
|
||||
if (primaryFacing == SOUTH && secondaryFacing == WEST || primaryFacing == WEST && secondaryFacing == SOUTH)
|
||||
return 180;
|
||||
if (primaryFacing == WEST && secondaryFacing == NORTH || primaryFacing == NORTH && secondaryFacing == WEST)
|
||||
return 270;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T extends Block> ModelFile getModel(DataGenContext<Block, T> ctx, RegistrateBlockstateProvider prov,
|
||||
BlockState state) {
|
||||
// return AssetLookup.forPowered(ctx, prov)
|
||||
// .apply(state);
|
||||
|
||||
return state.getValue(DiagonalCableBlock.FACING_UP) ? partialBaseModel(ctx, prov, "up")
|
||||
: partialBaseModel(ctx, prov);
|
||||
Direction primaryFacing = state.getValue(FACING_PRIMARY);
|
||||
Direction secondaryFacing = state.getValue(FACING_SECONDARY);
|
||||
if (primaryFacing == secondaryFacing || primaryFacing == secondaryFacing.getOpposite())
|
||||
return prov.models().getExistingFile(prov.mcLoc("block/air"));
|
||||
if (primaryFacing == UP || secondaryFacing == UP)
|
||||
return partialBaseModel(ctx, prov, "up");
|
||||
if (primaryFacing == DOWN || secondaryFacing == DOWN)
|
||||
return partialBaseModel(ctx, prov, "down");
|
||||
|
||||
return partialBaseModel(ctx, prov, "horizontal");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"format_version": "1.21.6",
|
||||
"credit": "Made with Blockbench",
|
||||
"texture_size": [24, 24],
|
||||
"textures": {
|
||||
"1": "tfmg:block/diagonal_cable_block",
|
||||
"particle": "tfmg:block/diagonal_cable_block"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"from": [4, 4, 0],
|
||||
"to": [12, 12, 2],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]},
|
||||
"faces": {
|
||||
"north": {"uv": [5.33333, 8, 0, 13.33333], "texture": "#1"},
|
||||
"east": {"uv": [0, 14.66667, 5.33333, 16], "rotation": 270, "texture": "#1"},
|
||||
"south": {"uv": [5.33333, 8, 0, 2.66667], "rotation": 180, "texture": "#1"},
|
||||
"west": {"uv": [0, 14.66667, 5.33333, 16], "rotation": 90, "texture": "#1"},
|
||||
"up": {"uv": [0, 14.66667, 5.33333, 16], "rotation": 180, "texture": "#1"},
|
||||
"down": {"uv": [0, 14.66667, 5.33333, 16], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [14, 4, 4],
|
||||
"to": [16, 12, 12],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]},
|
||||
"faces": {
|
||||
"north": {"uv": [0, 13.33333, 5.33333, 14.66667], "rotation": 270, "texture": "#1"},
|
||||
"east": {"uv": [5.33333, 13.33333, 0, 8], "rotation": 180, "texture": "#1"},
|
||||
"south": {"uv": [0, 13.33333, 5.33333, 14.66667], "rotation": 90, "texture": "#1"},
|
||||
"west": {"uv": [5.33333, 2.66667, 0, 8], "texture": "#1"},
|
||||
"up": {"uv": [0, 13.33333, 5.33333, 14.66667], "rotation": 90, "texture": "#1"},
|
||||
"down": {"uv": [0, 13.33333, 5.33333, 14.66667], "rotation": 90, "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [1, 6, 1.75736],
|
||||
"to": [15, 10, 5.75736],
|
||||
"rotation": {"angle": -45, "axis": "y", "origin": [8, 8, 8]},
|
||||
"faces": {
|
||||
"north": {"uv": [6.66667, 6.66667, 9.33333, 16], "rotation": 90, "texture": "#1"},
|
||||
"east": {"uv": [16, 2, 13.33333, 4.66667], "rotation": 180, "texture": "#1"},
|
||||
"south": {"uv": [11.33333, 6.66667, 14, 16], "rotation": 270, "texture": "#1"},
|
||||
"west": {"uv": [16, 2.66667, 13.33333, 0], "texture": "#1"},
|
||||
"up": {"uv": [13.33333, 6.66667, 16, 16], "rotation": 270, "texture": "#1"},
|
||||
"down": {"uv": [9.33333, 6.66667, 12, 16], "rotation": 270, "texture": "#1"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user