Skip to content

Commit

Permalink
Fixes to horizontal blocking.
Browse files Browse the repository at this point in the history
  • Loading branch information
MerchantPug committed Nov 19, 2024
1 parent 607c4b5 commit 6688f0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
## Bugfixes
- Fixed directional barrier collisions.
- Fixed a crash when starting to specify directional barriers in a component.
- Fixed east and west barrier models having an incorrect face.
- Fixed smaller entities being able to go through horizontal directional barriers.
- Fixed edge case where an entity will collide with a horizontal barrier's edge.
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,15 @@ public Direction blockingDirection(BlockPos pos, CollisionContext context) {
return direction;
if (direction == Direction.UP && context.isAbove(Shapes.block(), pos, false))
return direction;
if (intersectsHorizontal(direction, entity.getBoundingBox(), entity.getDeltaMovement(), pos))
if (isOnOtherSideOfFace(direction, entity.getBoundingBox(), pos))
return direction;
}
return null;
}

public static boolean intersectsHorizontal(Direction direction, AABB box, Vec3 deltaMovement, BlockPos pos) {
Vec3 startPos = new Vec3(pos.getX(), pos.getY(), pos.getZ()).add(getPoint(direction, Direction.Axis.X, 0, -0.1), getPoint(direction, Direction.Axis.Y, 0.5, -0.1), getPoint(direction, Direction.Axis.Z, 0, -0.1));
Vec3 endPos = startPos.add(getPoint(direction, Direction.Axis.X, 1, 0.2), getPoint(direction, Direction.Axis.Y, 0, 0.2), getPoint(direction, Direction.Axis.Z, 1, 0.2));
public static boolean isOnOtherSideOfFace(Direction direction, AABB box, BlockPos pos) {
Vec3 boxDotPos = new Vec3(box.getCenter().x() - (pos.getX() + (direction.getAxis() == Direction.Axis.X ? Math.max(direction.getAxisDirection().getStep(), 0) : 0.5)), 0, box.getCenter().z() - (pos.getZ() + (direction.getAxis() == Direction.Axis.Z ? Math.max(direction.getAxisDirection().getStep(), 0) : 0.5))).normalize();
return box.expandTowards(deltaMovement.x(), 0, deltaMovement.z()).intersects(startPos, endPos) && boxDotPos.dot(new Vec3(direction.getStepX(), 0, direction.getStepZ())) > 0.2;
}

public static double getPoint(Direction direction, Direction.Axis axis, double defaultValue, double offset) {
if (direction.getAxis() == axis)
defaultValue = Math.max(direction.getAxisDirection().getStep(), 0) + offset;
return defaultValue;
return boxDotPos.dot(new Vec3(direction.getStepX(), 0, direction.getStepZ())) > box.getSize() * 0.3;
}

public boolean isHorizontal() {
Expand Down

0 comments on commit 6688f0b

Please sign in to comment.