Fixed hitbox

This commit is contained in:
2025-11-12 20:45:09 +01:00
parent 16fcd92372
commit 139bc09aca
@@ -3,6 +3,8 @@ package dev.kleo.redstonerewired;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.block.AbstractBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
@@ -48,6 +50,20 @@ public class CableBlock extends Block {
.with(WEST, west), 2);
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
super.onPlaced(world, pos, state, placer, itemStack);
boolean north = world.getBlockState(pos.north()).getBlock() instanceof CableBlock;
boolean south = world.getBlockState(pos.south()).getBlock() instanceof CableBlock;
boolean east = world.getBlockState(pos.east()).getBlock() instanceof CableBlock;
boolean west = world.getBlockState(pos.west()).getBlock() instanceof CableBlock;
world.setBlockState(pos, state.with(NORTH, north)
.with(SOUTH, south)
.with(EAST, east)
.with(WEST, west), 2);
}
@Override
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
VoxelShape shape = Block.createCuboidShape(6, 6, 6, 10, 10, 10);
@@ -57,13 +73,13 @@ public class CableBlock extends Block {
boolean east = state.get(EAST);
boolean west = state.get(WEST);
if (north)
if (north || (south && !east && !west))
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 6, 0, 10, 10, 6));
if (south)
if (south || (north && !east && !west))
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 6, 10, 10, 10, 16));
if (east)
if (east || (!north && !south && west))
shape = VoxelShapes.union(shape, Block.createCuboidShape(10, 6, 6, 16, 10, 10));
if (west)
if (west || (!north && !south && east))
shape = VoxelShapes.union(shape, Block.createCuboidShape(0, 6, 6, 6, 10, 10));
return shape;