Skip to content

Commit

Permalink
fix: entity.collisions.suffocation using wrong eye Box for block coll…
Browse files Browse the repository at this point in the history
…ision check
  • Loading branch information
2No2Name committed Dec 13, 2021
1 parent bf3c69b commit 71fb4f4
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,23 @@ public boolean isInsideWall() {
if (this.noClip) {
return false;
}
Vec3d vec3d = this.getEyePos();
Vec3d eyePos = this.getEyePos();
double suffocationRadius = Math.abs((double) (this.dimensions.width * 0.8f) / 2.0);

BlockPos incorrectSuffocationPos = new BlockPos(vec3d);
BlockPos incorrectSuffocationPos = new BlockPos(eyePos);

int minX = MathHelper.floor(vec3d.x - suffocationRadius);
int minY = MathHelper.floor(vec3d.y - 5.0E-7);
int minZ = MathHelper.floor(vec3d.z - suffocationRadius);
int maxX = MathHelper.floor(vec3d.x + suffocationRadius);
int maxY = MathHelper.floor(vec3d.y + 5.0E-7);
int maxZ = MathHelper.floor(vec3d.z + suffocationRadius);
double suffocationMinX = eyePos.x - suffocationRadius;
double suffocationMinY = eyePos.y - 5.0E-7;
double suffocationMinZ = eyePos.z - suffocationRadius;
double suffocationMaxX = eyePos.x + suffocationRadius;
double suffocationMaxY = eyePos.y + 5.0E-7;
double suffocationMaxZ = eyePos.z + suffocationRadius;
int minX = MathHelper.floor(suffocationMinX);
int minY = MathHelper.floor(suffocationMinY);
int minZ = MathHelper.floor(suffocationMinZ);
int maxX = MathHelper.floor(suffocationMaxX);
int maxY = MathHelper.floor(suffocationMaxY);
int maxZ = MathHelper.floor(suffocationMaxZ);

World world = this.world;
BlockPos.Mutable blockPos = new BlockPos.Mutable();
Expand All @@ -63,9 +69,11 @@ public boolean isInsideWall() {
// [VanillaCopy] https://bugs.mojang.com/browse/MC-242543 (incorrectly marked as cannot reproduce)
if (!blockState.isAir() && blockState.shouldSuffocate(this.world, incorrectSuffocationPos)) {
if (suffocationShape == null) {
suffocationShape = VoxelShapes.cuboid(new Box(minX, minY, minZ, maxX, maxY, maxZ));
suffocationShape = VoxelShapes.cuboid(new Box(suffocationMinX, suffocationMinY, suffocationMinZ, suffocationMaxX, suffocationMaxY, suffocationMaxZ));
}
if (VoxelShapes.matchesAnywhere(blockState.getCollisionShape(this.world, incorrectSuffocationPos).offset(vec3d.x, vec3d.y, vec3d.z), suffocationShape, BooleanBiFunction.AND)) {
if (VoxelShapes.matchesAnywhere(blockState.getCollisionShape(this.world, incorrectSuffocationPos).
offset(eyePos.x, eyePos.y, eyePos.z), // [VanillaCopy] This is broken. Should be offset by blockPos. But vanilla does it like this. Causes https://bugs.mojang.com/browse/MC-245416
suffocationShape, BooleanBiFunction.AND)) {
return true;
}
}
Expand Down

0 comments on commit 71fb4f4

Please sign in to comment.