Adjust the Guardrail bounding and collision boxes to better match the block model
mallrat208 opened this issue ยท 1 comments
The Bounding and Collision boxes for Guardrails do not match the model and behaves a bit unexpectedly. Players and entities can 'stand' on the the guard rails despite 3/4 of the model being empty space.
In a local 1.12.2 test world, I've modified the collision and bounding boxes to more closely match the model used. For example in this photo Alex is standing in the center of a 2x2 square of guardrails, which is currently impossible, you would normally float on top of it.
To do this, I added the following to BlockRoadGuardrail
private static AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0,0,0,1,1,0.25);
private static AxisAlignedBB SOUTH_L_PILLAR_AABB = new AxisAlignedBB(0,0,0,0.25,1,0.25);
private static AxisAlignedBB SOUTH_R_PILLAR_AABB = new AxisAlignedBB(0.75,0,0,1,1,0.25);
private static AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.75,0,0,1,1,1);
private static AxisAlignedBB WEST_R_PILLAR_AABB = new AxisAlignedBB(0.75,0,0.75,1,1,1);
private static AxisAlignedBB WEST_L_PILLAR_AABB = new AxisAlignedBB(0.75,0,0,1,1,0.25);
private static AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0,0,0.75,1,1,1);
private static AxisAlignedBB NORTH_L_PILLAR_AABB = new AxisAlignedBB(0.75,0,0.75,1,1,1);
private static AxisAlignedBB NORTH_R_PILLAR_AABB = new AxisAlignedBB(0,0,0.75,0.25,1,1);
private static AxisAlignedBB EAST_AABB = new AxisAlignedBB(0,0,0,0.25,1,1);
private static AxisAlignedBB EAST_R_PILLAR_AABB = new AxisAlignedBB(0,0,0,0.25,1,0.25);
private static AxisAlignedBB EAST_L_PILLAR_AABB = new AxisAlignedBB(0,0,0.75,0.25,1,1);
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState) {
EnumShape actualShape = getActualState(state, worldIn, pos).getValue(SHAPE);
if(actualShape==EnumShape.OUTER_RIGHT || actualShape==EnumShape.OUTER_LEFT) {
switch(state.getValue(FACING)) {
case WEST:
addCollisionBoxToList(pos,entityBox,collidingBoxes,actualShape == EnumShape.OUTER_RIGHT?NORTH_AABB:SOUTH_AABB);
break;
case EAST:
addCollisionBoxToList(pos,entityBox,collidingBoxes,actualShape == EnumShape.OUTER_RIGHT?SOUTH_AABB:NORTH_AABB);
break;
case NORTH:
addCollisionBoxToList(pos,entityBox,collidingBoxes,actualShape == EnumShape.OUTER_RIGHT?EAST_AABB:WEST_AABB);
break;
default:
addCollisionBoxToList(pos,entityBox,collidingBoxes,actualShape == EnumShape.OUTER_RIGHT?WEST_AABB:EAST_AABB);
}
}
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entityIn, isActualState);
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
EnumShape actualShape = getActualState(state, source, pos).getValue(SHAPE);
boolean inner = actualShape == EnumShape.INNER_LEFT || actualShape == EnumShape.INNER_RIGHT;
boolean left = inner && actualShape == EnumShape.INNER_LEFT;
switch(state.getValue(FACING)) {
case WEST:
return !inner ? WEST_AABB : left ? WEST_L_PILLAR_AABB : WEST_R_PILLAR_AABB;
case EAST:
return !inner ? EAST_AABB : left ? EAST_L_PILLAR_AABB : EAST_R_PILLAR_AABB;
case NORTH:
return !inner ? NORTH_AABB : left ? NORTH_L_PILLAR_AABB : NORTH_R_PILLAR_AABB;
default:
return !inner ? SOUTH_AABB : left ? SOUTH_L_PILLAR_AABB : SOUTH_R_PILLAR_AABB;
}
}