- Modified connectivity behaviour of Girders
- Girders now support and connect to lanterns and chains
This commit is contained in:
simibubi 2022-07-03 16:34:35 +02:00
parent 58263f9c06
commit 9b9e252bac
4 changed files with 179 additions and 77 deletions

View file

@ -1,5 +1,6 @@
package com.simibubi.create.content.curiosities.girder; package com.simibubi.create.content.curiosities.girder;
import static net.minecraft.world.level.block.FaceAttachedHorizontalDirectionalBlock.FACE;
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.WATERLOGGED; import static net.minecraft.world.level.block.state.properties.BlockStateProperties.WATERLOGGED;
import java.util.Random; import java.util.Random;
@ -25,6 +26,7 @@ import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis; import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Direction.AxisDirection;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
@ -34,11 +36,14 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ChainBlock;
import net.minecraft.world.level.block.LanternBlock;
import net.minecraft.world.level.block.Mirror; import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.SimpleWaterloggedBlock;
@ -46,13 +51,17 @@ import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition.Builder; import net.minecraft.world.level.block.state.StateDefinition.Builder;
import net.minecraft.world.level.block.state.properties.AttachFace;
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.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenchable { public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenchable {
@ -63,10 +72,12 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
public static final BooleanProperty Z = BooleanProperty.create("z"); public static final BooleanProperty Z = BooleanProperty.create("z");
public static final BooleanProperty TOP = BooleanProperty.create("top"); public static final BooleanProperty TOP = BooleanProperty.create("top");
public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom"); public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom");
public static final EnumProperty<Axis> AXIS = BlockStateProperties.AXIS;
public GirderBlock(Properties p_49795_) { public GirderBlock(Properties p_49795_) {
super(p_49795_); super(p_49795_);
registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false) registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false)
.setValue(AXIS, Axis.Y)
.setValue(TOP, false) .setValue(TOP, false)
.setValue(BOTTOM, false) .setValue(BOTTOM, false)
.setValue(X, false) .setValue(X, false)
@ -75,7 +86,13 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
@Override @Override
protected void createBlockStateDefinition(Builder<Block, BlockState> pBuilder) { protected void createBlockStateDefinition(Builder<Block, BlockState> pBuilder) {
super.createBlockStateDefinition(pBuilder.add(X, Z, TOP, BOTTOM, WATERLOGGED)); super.createBlockStateDefinition(pBuilder.add(X, Z, TOP, BOTTOM, AXIS, WATERLOGGED));
}
@Override
@SuppressWarnings("deprecation")
public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, BlockPos pPos) {
return Shapes.or(super.getBlockSupportShape(pState, pReader, pPos), AllShapes.EIGHT_VOXEL_POLE.get(Axis.Y));
} }
@Override @Override
@ -92,19 +109,20 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
.setValue(BOTTOM, pState.getValue(BOTTOM)) .setValue(BOTTOM, pState.getValue(BOTTOM))
.setValue(GirderEncasedShaftBlock.HORIZONTAL_AXIS, pState.getValue(X) || pHit.getDirection() .setValue(GirderEncasedShaftBlock.HORIZONTAL_AXIS, pState.getValue(X) || pHit.getDirection()
.getAxis() == Axis.Z ? Axis.Z : Axis.X)); .getAxis() == Axis.Z ? Axis.Z : Axis.X));
pLevel.playSound(null, pPos, SoundEvents.NETHERITE_BLOCK_HIT, SoundSource.BLOCKS, 0.5f, 1.25f); pLevel.playSound(null, pPos, SoundEvents.NETHERITE_BLOCK_HIT, SoundSource.BLOCKS, 0.5f, 1.25f);
if (!pLevel.isClientSide && !pPlayer.isCreative()) { if (!pLevel.isClientSide && !pPlayer.isCreative()) {
itemInHand.shrink(1); itemInHand.shrink(1);
if (itemInHand.isEmpty()) if (itemInHand.isEmpty())
pPlayer.setItemInHand(pHand, ItemStack.EMPTY); pPlayer.setItemInHand(pHand, ItemStack.EMPTY);
} }
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
if (AllItems.WRENCH.isIn(itemInHand) && !pPlayer.isSteppingCarefully()) { if (AllItems.WRENCH.isIn(itemInHand) && !pPlayer.isSteppingCarefully()) {
if (GirderWrenchBehavior.handleClick(pLevel, pPos, pState, pHit)) if (GirderWrenchBehavior.handleClick(pLevel, pPos, pState, pHit))
return InteractionResult.sidedSuccess(pLevel.isClientSide); return InteractionResult.sidedSuccess(pLevel.isClientSide);
return InteractionResult.FAIL; return InteractionResult.FAIL;
} }
@ -121,6 +139,11 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState(); return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState();
} }
@Override
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
return InteractionResult.PASS;
}
@Override @Override
public void tick(BlockState p_60462_, ServerLevel p_60463_, BlockPos p_60464_, Random p_60465_) { public void tick(BlockState p_60462_, ServerLevel p_60463_, BlockPos p_60464_, Random p_60465_) {
Block.updateOrDestroy(p_60462_, Block.updateFromNeighbourShapes(p_60462_, p_60463_, p_60464_), p_60463_, Block.updateOrDestroy(p_60462_, Block.updateFromNeighbourShapes(p_60462_, p_60463_, p_60464_), p_60463_,
@ -133,12 +156,29 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
if (state.getValue(WATERLOGGED)) if (state.getValue(WATERLOGGED))
world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
Axis axis = direction.getAxis(); Axis axis = direction.getAxis();
if (direction.getAxis() != Axis.Y) {
if (state.getValue(AXIS) != direction.getAxis()) {
Property<Boolean> updateProperty = Property<Boolean> updateProperty =
axis == Axis.X ? X : axis == Axis.Z ? Z : direction == Direction.UP ? TOP : BOTTOM; axis == Axis.X ? X : axis == Axis.Z ? Z : direction == Direction.UP ? TOP : BOTTOM;
if (!isConnected(world, pos, state, direction) && !isConnected(world, pos, state, direction.getOpposite())) if (!isConnected(world, pos, state, direction)
&& !isConnected(world, pos, state, direction.getOpposite()))
state = state.setValue(updateProperty, false); state = state.setValue(updateProperty, false);
}
} else if (state.getValue(AXIS) != Axis.Y) {
if (world.getBlockState(pos.above())
.getBlockSupportShape(world, pos.above())
.isEmpty())
state = state.setValue(TOP, false);
if (world.getBlockState(pos.below())
.getBlockSupportShape(world, pos.below())
.isEmpty())
state = state.setValue(BOTTOM, false);
}
for (Direction d : Iterate.directionsInAxis(axis)) for (Direction d : Iterate.directionsInAxis(axis))
state = updateState(world, pos, state, d); state = updateState(world, pos, state, d);
return state; return state;
} }
@ -151,6 +191,7 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
BlockState state = super.getStateForPlacement(context); BlockState state = super.getStateForPlacement(context);
state = state.setValue(X, face.getAxis() == Axis.X); state = state.setValue(X, face.getAxis() == Axis.X);
state = state.setValue(Z, face.getAxis() == Axis.Z); state = state.setValue(Z, face.getAxis() == Axis.Z);
state = state.setValue(AXIS, face.getAxis());
for (Direction d : Iterate.directions) for (Direction d : Iterate.directions)
state = updateState(level, pos, state, d); state = updateState(level, pos, state, d);
@ -166,7 +207,9 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
if (axis.isVertical()) if (axis.isVertical())
return updateVerticalProperty(level, pos, state, updateProperty, sideState, d); return updateVerticalProperty(level, pos, state, updateProperty, sideState, d);
if (sideState.getBlock() instanceof GirderEncasedShaftBlock if (state.getValue(AXIS) == axis)
state = state.setValue(updateProperty, true);
else if (sideState.getBlock() instanceof GirderEncasedShaftBlock
&& sideState.getValue(GirderEncasedShaftBlock.HORIZONTAL_AXIS) != axis) && sideState.getValue(GirderEncasedShaftBlock.HORIZONTAL_AXIS) != axis)
state = state.setValue(updateProperty, true); state = state.setValue(updateProperty, true);
else if (sideState.getBlock() == state.getBlock() && sideState.getValue(updateProperty)) else if (sideState.getBlock() == state.getBlock() && sideState.getValue(updateProperty))
@ -206,20 +249,37 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
public static BlockState updateVerticalProperty(LevelAccessor level, BlockPos pos, BlockState state, public static BlockState updateVerticalProperty(LevelAccessor level, BlockPos pos, BlockState state,
Property<Boolean> updateProperty, BlockState sideState, Direction d) { Property<Boolean> updateProperty, BlockState sideState, Direction d) {
if (isGirder(sideState) && isXGirder(sideState) == isZGirder(sideState)) boolean canAttach = false;
state = state.setValue(updateProperty, true);
if (state.hasProperty(AXIS) && state.getValue(AXIS) == Axis.Y)
canAttach = true;
else if (isGirder(sideState) && isXGirder(sideState) == isZGirder(sideState))
canAttach = true;
else if (isGirder(sideState)) else if (isGirder(sideState))
state = state.setValue(updateProperty, true); canAttach = true;
else if (sideState.hasProperty(WallBlock.UP) && sideState.getValue(WallBlock.UP)) else if (sideState.hasProperty(WallBlock.UP) && sideState.getValue(WallBlock.UP))
state = state.setValue(updateProperty, true); canAttach = true;
else if (sideState.getBlock() instanceof NixieTubeBlock && NixieTubeBlock.getFacing(sideState) == d) else if (sideState.getBlock() instanceof NixieTubeBlock && NixieTubeBlock.getFacing(sideState) == d)
state = state.setValue(updateProperty, true); canAttach = true;
else if (sideState.getBlock() instanceof FlapDisplayBlock) else if (sideState.getBlock() instanceof FlapDisplayBlock)
state = state.setValue(updateProperty, true); canAttach = true;
else if (sideState.getBlock() instanceof PlacardBlock && PlacardBlock.connectedDirection(sideState) == d) else if (sideState.getBlock() instanceof LanternBlock
state = state.setValue(updateProperty, true); && (d == Direction.DOWN) == (sideState.getValue(LanternBlock.HANGING)))
canAttach = true;
else if (sideState.getBlock() instanceof ChainBlock && sideState.getValue(ChainBlock.AXIS) == Axis.Y)
canAttach = true;
else if (sideState.hasProperty(FACE)) {
if (sideState.getValue(FACE) == AttachFace.CEILING && d == Direction.DOWN)
canAttach = true;
else if (sideState.getValue(FACE) == AttachFace.FLOOR && d == Direction.UP)
canAttach = true;
} else if (sideState.getBlock() instanceof PlacardBlock && PlacardBlock.connectedDirection(sideState) == d)
canAttach = true;
else if (isFacingBracket(level, pos, d)) else if (isFacingBracket(level, pos, d))
state = state.setValue(updateProperty, true); canAttach = true;
if (canAttach)
return state.setValue(updateProperty, true);
return state; return state;
} }
@ -280,6 +340,9 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
@Override @Override
public BlockState rotate(BlockState state, Rotation rot) { public BlockState rotate(BlockState state, Rotation rot) {
state = state.setValue(AXIS,
rot.rotate(Direction.fromAxisAndDirection(state.getValue(AXIS), AxisDirection.POSITIVE))
.getAxis());
if (rot.rotate(Direction.EAST) if (rot.rotate(Direction.EAST)
.getAxis() == Axis.X) .getAxis() == Axis.X)
return state; return state;

View file

@ -30,6 +30,7 @@ import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
public class GirderEncasedShaftBlock extends HorizontalAxisKineticBlock public class GirderEncasedShaftBlock extends HorizontalAxisKineticBlock
@ -52,12 +53,19 @@ public class GirderEncasedShaftBlock extends HorizontalAxisKineticBlock
return AllShapes.GIRDER_BEAM_SHAFT.get(pState.getValue(HORIZONTAL_AXIS)); return AllShapes.GIRDER_BEAM_SHAFT.get(pState.getValue(HORIZONTAL_AXIS));
} }
@Override
@SuppressWarnings("deprecation")
public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, BlockPos pPos) {
return Shapes.or(super.getBlockSupportShape(pState, pReader, pPos), AllShapes.EIGHT_VOXEL_POLE.get(Axis.Y));
}
@Override @Override
public BlockState getRotatedBlockState(BlockState originalState, Direction targetedFace) { public BlockState getRotatedBlockState(BlockState originalState, Direction targetedFace) {
return AllBlocks.METAL_GIRDER.getDefaultState() return AllBlocks.METAL_GIRDER.getDefaultState()
.setValue(WATERLOGGED, originalState.getValue(WATERLOGGED)) .setValue(WATERLOGGED, originalState.getValue(WATERLOGGED))
.setValue(GirderBlock.X, originalState.getValue(HORIZONTAL_AXIS) == Axis.Z) .setValue(GirderBlock.X, originalState.getValue(HORIZONTAL_AXIS) == Axis.Z)
.setValue(GirderBlock.Z, originalState.getValue(HORIZONTAL_AXIS) == Axis.X) .setValue(GirderBlock.Z, originalState.getValue(HORIZONTAL_AXIS) == Axis.X)
.setValue(GirderBlock.AXIS, originalState.getValue(HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X)
.setValue(GirderBlock.BOTTOM, originalState.getValue(BOTTOM)) .setValue(GirderBlock.BOTTOM, originalState.getValue(BOTTOM))
.setValue(GirderBlock.TOP, originalState.getValue(TOP)); .setValue(GirderBlock.TOP, originalState.getValue(TOP));
} }
@ -96,6 +104,9 @@ public class GirderEncasedShaftBlock extends HorizontalAxisKineticBlock
Property<Boolean> updateProperty = direction == Direction.UP ? TOP : BOTTOM; Property<Boolean> updateProperty = direction == Direction.UP ? TOP : BOTTOM;
if (direction.getAxis() if (direction.getAxis()
.isVertical()) { .isVertical()) {
if (world.getBlockState(pos.relative(direction))
.getBlockSupportShape(world, pos.relative(direction))
.isEmpty())
state = state.setValue(updateProperty, false); state = state.setValue(updateProperty, false);
return GirderBlock.updateVerticalProperty(world, pos, state, updateProperty, neighbourState, direction); return GirderBlock.updateVerticalProperty(world, pos, state, updateProperty, neighbourState, direction);
} }

View file

@ -67,7 +67,8 @@ public class GirderPlacementHelper implements IPlacementHelper {
private BlockState withAxis(BlockState state, Axis axis) { private BlockState withAxis(BlockState state, Axis axis) {
if (state.getBlock() instanceof GirderBlock) if (state.getBlock() instanceof GirderBlock)
return state.setValue(GirderBlock.X, axis == Axis.X) return state.setValue(GirderBlock.X, axis == Axis.X)
.setValue(GirderBlock.Z, axis == Axis.Z); .setValue(GirderBlock.Z, axis == Axis.Z)
.setValue(GirderBlock.AXIS, axis);
if (state.getBlock() instanceof GirderEncasedShaftBlock && axis.isHorizontal()) if (state.getBlock() instanceof GirderEncasedShaftBlock && axis.isHorizontal())
return state.setValue(GirderEncasedShaftBlock.HORIZONTAL_AXIS, axis == Axis.X ? Axis.Z : Axis.X); return state.setValue(GirderEncasedShaftBlock.HORIZONTAL_AXIS, axis == Axis.X ? Axis.Z : Axis.X);
return state; return state;

View file

@ -19,12 +19,12 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -58,21 +58,38 @@ public class GirderWrenchBehavior {
return; return;
Vec3 center = VecHelper.getCenterOf(pos); Vec3 center = VecHelper.getCenterOf(pos);
Vec3 edge = center.add(Vec3.atLowerCornerOf(dirPair.getFirst().getNormal()).scale(0.4)); Vec3 edge = center.add(Vec3.atLowerCornerOf(dirPair.getFirst()
Direction.Axis[] axes = Arrays.stream(Iterate.axes).filter(axis -> axis != dirPair.getFirst().getAxis()).toArray(Direction.Axis[]::new); .getNormal())
.scale(0.4));
Direction.Axis[] axes = Arrays.stream(Iterate.axes)
.filter(axis -> axis != dirPair.getFirst()
.getAxis())
.toArray(Direction.Axis[]::new);
double normalMultiplier = dirPair.getSecond() == Action.PAIR ? 4 : 1;
double normalMultiplier = dirPair.getSecond() == Action.PAIR ? 3 : 1;
Vec3 corner1 = edge Vec3 corner1 = edge
.add(Vec3.atLowerCornerOf(Direction.fromAxisAndDirection(axes[0], Direction.AxisDirection.POSITIVE).getNormal()).scale(0.3)) .add(Vec3.atLowerCornerOf(Direction.fromAxisAndDirection(axes[0], Direction.AxisDirection.POSITIVE)
.add(Vec3.atLowerCornerOf(Direction.fromAxisAndDirection(axes[1], Direction.AxisDirection.POSITIVE).getNormal()).scale(0.3)) .getNormal())
.add(Vec3.atLowerCornerOf(dirPair.getFirst().getNormal()).scale(0.1 * normalMultiplier)); .scale(0.3))
.add(Vec3.atLowerCornerOf(Direction.fromAxisAndDirection(axes[1], Direction.AxisDirection.POSITIVE)
.getNormal())
.scale(0.3))
.add(Vec3.atLowerCornerOf(dirPair.getFirst()
.getNormal())
.scale(0.1 * normalMultiplier));
normalMultiplier = dirPair.getSecond() == Action.HORIZONTAL ? 9 : 1; normalMultiplier = dirPair.getSecond() == Action.HORIZONTAL ? 9 : 2;
Vec3 corner2 = edge Vec3 corner2 = edge
.add(Vec3.atLowerCornerOf(Direction.fromAxisAndDirection(axes[0], Direction.AxisDirection.NEGATIVE).getNormal()).scale(0.3)) .add(Vec3.atLowerCornerOf(Direction.fromAxisAndDirection(axes[0], Direction.AxisDirection.NEGATIVE)
.add(Vec3.atLowerCornerOf(Direction.fromAxisAndDirection(axes[1], Direction.AxisDirection.NEGATIVE).getNormal()).scale(0.3)) .getNormal())
.add(Vec3.atLowerCornerOf(dirPair.getFirst().getOpposite().getNormal()).scale(0.1 * normalMultiplier)); .scale(0.3))
.add(Vec3.atLowerCornerOf(Direction.fromAxisAndDirection(axes[1], Direction.AxisDirection.NEGATIVE)
.getNormal())
.scale(0.3))
.add(Vec3.atLowerCornerOf(dirPair.getFirst()
.getOpposite()
.getNormal())
.scale(0.1 * normalMultiplier));
CreateClient.OUTLINER.showAABB("girderWrench", new AABB(corner1, corner2)) CreateClient.OUTLINER.showAABB("girderWrench", new AABB(corner1, corner2))
.lineWidth(1 / 32f) .lineWidth(1 / 32f)
@ -86,7 +103,10 @@ public class GirderWrenchBehavior {
if (validDirections.isEmpty()) if (validDirections.isEmpty())
return null; return null;
List<Direction> directions = IPlacementHelper.orderedByDistance(pos, result.getLocation(), validDirections.stream().map(Pair::getFirst).toList()); List<Direction> directions = IPlacementHelper.orderedByDistance(pos, result.getLocation(),
validDirections.stream()
.map(Pair::getFirst)
.toList());
if (directions.isEmpty()) if (directions.isEmpty())
return null; return null;
@ -108,13 +128,15 @@ public class GirderWrenchBehavior {
.<Pair<Direction, Action>>mapMulti((direction, consumer) -> { .<Pair<Direction, Action>>mapMulti((direction, consumer) -> {
BlockState other = level.getBlockState(pos.relative(direction)); BlockState other = level.getBlockState(pos.relative(direction));
if (!blockState.getValue(GirderBlock.X) && !blockState.getValue(GirderBlock.Z))
return;
// up and down // up and down
if (direction.getAxis() == Direction.Axis.Y) { if (direction.getAxis() == Direction.Axis.Y) {
// no other girder in target dir // no other girder in target dir
if (!AllBlocks.METAL_GIRDER.has(other)) { if (!AllBlocks.METAL_GIRDER.has(other)) {
if (!blockState.getValue(GirderBlock.X) ^ !blockState.getValue(GirderBlock.Z)) if (!blockState.getValue(GirderBlock.X) ^ !blockState.getValue(GirderBlock.Z))
consumer.accept(Pair.of(direction, Action.SINGLE)); consumer.accept(Pair.of(direction, Action.SINGLE));
return; return;
} }
// this girder is a pole or cross // this girder is a pole or cross
@ -129,20 +151,21 @@ public class GirderWrenchBehavior {
return; return;
} }
if (AllBlocks.METAL_GIRDER.has(other)) // if (AllBlocks.METAL_GIRDER.has(other))
consumer.accept(Pair.of(direction, Action.HORIZONTAL)); // consumer.accept(Pair.of(direction, Action.HORIZONTAL));
}).toList(); })
.toList();
} }
public static boolean handleClick(Level level, BlockPos pos, BlockState state, BlockHitResult result) { public static boolean handleClick(Level level, BlockPos pos, BlockState state, BlockHitResult result) {
Pair<Direction, Action> dirPair = getDirectionAndAction(result, level, pos); Pair<Direction, Action> dirPair = getDirectionAndAction(result, level, pos);
if (dirPair == null) if (dirPair == null)
return false; return false;
if (level.isClientSide) if (level.isClientSide)
return true; return true;
if (!state.getValue(GirderBlock.X) && !state.getValue(GirderBlock.Z))
return false;
Direction dir = dirPair.getFirst(); Direction dir = dirPair.getFirst();
@ -150,35 +173,39 @@ public class GirderWrenchBehavior {
BlockState other = level.getBlockState(otherPos); BlockState other = level.getBlockState(otherPos);
if (dir == Direction.UP) { if (dir == Direction.UP) {
level.setBlock(pos, state.cycle(GirderBlock.TOP), 2 | 16); level.setBlock(pos, postProcess(state.cycle(GirderBlock.TOP)), 2 | 16);
if (dirPair.getSecond() == Action.PAIR && AllBlocks.METAL_GIRDER.has(other)) { if (dirPair.getSecond() == Action.PAIR && AllBlocks.METAL_GIRDER.has(other))
level.setBlock(otherPos, other.cycle(GirderBlock.BOTTOM), 2 | 16); level.setBlock(otherPos, postProcess(other.cycle(GirderBlock.BOTTOM)), 2 | 16);
}
return true; return true;
} }
if (dir == Direction.DOWN) { if (dir == Direction.DOWN) {
level.setBlock(pos, state.cycle(GirderBlock.BOTTOM), 2 | 16); level.setBlock(pos, postProcess(state.cycle(GirderBlock.BOTTOM)), 2 | 16);
if (dirPair.getSecond() == Action.PAIR && AllBlocks.METAL_GIRDER.has(other)) { if (dirPair.getSecond() == Action.PAIR && AllBlocks.METAL_GIRDER.has(other))
level.setBlock(otherPos, other.cycle(GirderBlock.TOP), 2 | 16); level.setBlock(otherPos, postProcess(other.cycle(GirderBlock.TOP)), 2 | 16);
}
return true; return true;
} }
if (dirPair.getSecond() == Action.HORIZONTAL) { // if (dirPair.getSecond() == Action.HORIZONTAL) {
BooleanProperty property = dir.getAxis() == Direction.Axis.X ? GirderBlock.X : GirderBlock.Z; // BooleanProperty property = dir.getAxis() == Direction.Axis.X ? GirderBlock.X : GirderBlock.Z;
level.setBlock(pos, state.cycle(property), 2 | 16); // level.setBlock(pos, state.cycle(property), 2 | 16);
//
// return true;
// }
return true; return true;
} }
return true; private static BlockState postProcess(BlockState newState) {
if (newState.getValue(GirderBlock.TOP) && newState.getValue(GirderBlock.BOTTOM))
return newState;
if (newState.getValue(GirderBlock.AXIS) != Axis.Y)
return newState;
return newState.setValue(GirderBlock.AXIS, newState.getValue(GirderBlock.X) ? Axis.X : Axis.Z);
} }
private enum Action { private enum Action {
SINGLE, SINGLE, PAIR, HORIZONTAL
PAIR,
HORIZONTAL
} }
} }