mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
Fix VoxelShape#isFullBlock() for non-single AABB types
The correct logic to implement NOT_SAME with Shapes#block() is to test whether any shape data exists outside of [0.0, 1.0] and to test whether the shape is completely filled from 0.0 to 1.0 on all axis. This can be implemented by checking whether the bounds represent the full block and whether everything within the bounds is filled.
This commit is contained in:
parent
298c47857b
commit
c207429b21
@ -3941,10 +3941,10 @@ index cf469f9daa81da8bc330c9cac7e813db87f9f9af..d9256710e815a5cb55409a80d59df202
|
|||||||
|
|
||||||
private static DiscreteVoxelShape makeSlice(DiscreteVoxelShape voxelSet, Direction.Axis axis, int sliceWidth) {
|
private static DiscreteVoxelShape makeSlice(DiscreteVoxelShape voxelSet, Direction.Axis axis, int sliceWidth) {
|
||||||
diff --git a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
|
diff --git a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
|
||||||
index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..b9aa58d5209c244fe255ab258bb29a82b121d097 100644
|
index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..6bd6385ad82481a099f3556ed2dbd3744888fc34 100644
|
||||||
--- a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
|
--- a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
|
||||||
+++ b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
|
+++ b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
|
||||||
@@ -16,30 +16,401 @@ import net.minecraft.world.phys.BlockHitResult;
|
@@ -16,30 +16,438 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
public abstract class VoxelShape {
|
public abstract class VoxelShape {
|
||||||
@ -4220,7 +4220,7 @@ index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..b9aa58d5209c244fe255ab258bb29a82
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ private boolean computeFullBlock() {
|
+ private boolean computeFullBlock() {
|
||||||
+ final Boolean ret;
|
+ Boolean ret;
|
||||||
+ if (this.isEmpty) {
|
+ if (this.isEmpty) {
|
||||||
+ ret = Boolean.FALSE;
|
+ ret = Boolean.FALSE;
|
||||||
+ } else if ((VoxelShape)(Object)this == Shapes.block()) {
|
+ } else if ((VoxelShape)(Object)this == Shapes.block()) {
|
||||||
@ -4228,8 +4228,45 @@ index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..b9aa58d5209c244fe255ab258bb29a82
|
|||||||
+ } else {
|
+ } else {
|
||||||
+ final AABB singleAABB = this.singleAABBRepresentation;
|
+ final AABB singleAABB = this.singleAABBRepresentation;
|
||||||
+ if (singleAABB == null) {
|
+ if (singleAABB == null) {
|
||||||
+ // note: Shapes.join(BLOCK, this, NOT_SAME) cannot be empty when voxelSize > 2
|
+ final io.papermc.paper.util.collisions.CachedShapeData shapeData = this.cachedShapeData;
|
||||||
+ ret = Boolean.FALSE;
|
+ final int sMinX = shapeData.minFullX();
|
||||||
|
+ final int sMinY = shapeData.minFullY();
|
||||||
|
+ final int sMinZ = shapeData.minFullZ();
|
||||||
|
+
|
||||||
|
+ final int sMaxX = shapeData.maxFullX();
|
||||||
|
+ final int sMaxY = shapeData.maxFullY();
|
||||||
|
+ final int sMaxZ = shapeData.maxFullZ();
|
||||||
|
+
|
||||||
|
+ if (Math.abs(this.rootCoordinatesX[sMinX] + this.offsetX) <= io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON &&
|
||||||
|
+ Math.abs(this.rootCoordinatesY[sMinY] + this.offsetY) <= io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON &&
|
||||||
|
+ Math.abs(this.rootCoordinatesZ[sMinZ] + this.offsetZ) <= io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON &&
|
||||||
|
+
|
||||||
|
+ Math.abs(1.0 - (this.rootCoordinatesX[sMaxX] + this.offsetX)) <= io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON &&
|
||||||
|
+ Math.abs(1.0 - (this.rootCoordinatesY[sMaxY] + this.offsetY)) <= io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON &&
|
||||||
|
+ Math.abs(1.0 - (this.rootCoordinatesZ[sMaxZ] + this.offsetZ)) <= io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON) {
|
||||||
|
+
|
||||||
|
+ // index = z + y*sizeZ + x*(sizeZ*sizeY)
|
||||||
|
+
|
||||||
|
+ final int sizeY = shapeData.sizeY();
|
||||||
|
+ final int sizeZ = shapeData.sizeZ();
|
||||||
|
+
|
||||||
|
+ final long[] bitset = shapeData.voxelSet();
|
||||||
|
+
|
||||||
|
+ ret = Boolean.TRUE;
|
||||||
|
+
|
||||||
|
+ check_full:
|
||||||
|
+ for (int x = sMinX; x < sMaxX; ++x) {
|
||||||
|
+ for (int y = sMinY; y < sMaxY; ++y) {
|
||||||
|
+ final int baseIndex = y*sizeZ + x*(sizeZ*sizeY);
|
||||||
|
+ if (!io.papermc.paper.util.collisions.FlatBitsetUtil.isRangeSet(bitset, baseIndex + sMinZ, baseIndex + sMaxZ)) {
|
||||||
|
+ ret = Boolean.FALSE;
|
||||||
|
+ break check_full;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ } else {
|
||||||
|
+ ret = Boolean.FALSE;
|
||||||
|
+ }
|
||||||
+ } else {
|
+ } else {
|
||||||
+ ret = Boolean.valueOf(
|
+ ret = Boolean.valueOf(
|
||||||
+ Math.abs(singleAABB.minX) <= io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON &&
|
+ Math.abs(singleAABB.minX) <= io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON &&
|
||||||
@ -4356,7 +4393,7 @@ index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..b9aa58d5209c244fe255ab258bb29a82
|
|||||||
}
|
}
|
||||||
|
|
||||||
public VoxelShape singleEncompassing() {
|
public VoxelShape singleEncompassing() {
|
||||||
@@ -53,19 +424,106 @@ public abstract class VoxelShape {
|
@@ -53,19 +461,106 @@ public abstract class VoxelShape {
|
||||||
protected abstract DoubleList getCoords(Direction.Axis axis);
|
protected abstract DoubleList getCoords(Direction.Axis axis);
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
@ -4470,7 +4507,7 @@ index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..b9aa58d5209c244fe255ab258bb29a82
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void forAllEdges(Shapes.DoubleLineConsumer consumer) {
|
public void forAllEdges(Shapes.DoubleLineConsumer consumer) {
|
||||||
@@ -83,12 +541,43 @@ public abstract class VoxelShape {
|
@@ -83,12 +578,43 @@ public abstract class VoxelShape {
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4519,7 +4556,7 @@ index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..b9aa58d5209c244fe255ab258bb29a82
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double min(Direction.Axis axis, double from, double to) {
|
public double min(Direction.Axis axis, double from, double to) {
|
||||||
@@ -115,37 +604,85 @@ public abstract class VoxelShape {
|
@@ -115,37 +641,85 @@ public abstract class VoxelShape {
|
||||||
}) - 1;
|
}) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4575,11 +4612,11 @@ index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..b9aa58d5209c244fe255ab258bb29a82
|
|||||||
+ return new BlockHitResult(fromBehind, Direction.getNearest(directionOpposite.x, directionOpposite.y, directionOpposite.z).getOpposite(), pos, true);
|
+ return new BlockHitResult(fromBehind, Direction.getNearest(directionOpposite.x, directionOpposite.y, directionOpposite.z).getOpposite(), pos, true);
|
||||||
}
|
}
|
||||||
+ return clip(singleAABB, start, end, pos);
|
+ return clip(singleAABB, start, end, pos);
|
||||||
+ }
|
}
|
||||||
+
|
+
|
||||||
+ if (io.papermc.paper.util.CollisionUtil.strictlyContains(this, fromBehindOffsetX, fromBehindOffsetY, fromBehindOffsetZ)) {
|
+ if (io.papermc.paper.util.CollisionUtil.strictlyContains(this, fromBehindOffsetX, fromBehindOffsetY, fromBehindOffsetZ)) {
|
||||||
+ return new BlockHitResult(fromBehind, Direction.getNearest(directionOpposite.x, directionOpposite.y, directionOpposite.z).getOpposite(), pos, true);
|
+ return new BlockHitResult(fromBehind, Direction.getNearest(directionOpposite.x, directionOpposite.y, directionOpposite.z).getOpposite(), pos, true);
|
||||||
}
|
+ }
|
||||||
+
|
+
|
||||||
+ return AABB.clip(this.toAabbs(), start, end, pos);
|
+ return AABB.clip(this.toAabbs(), start, end, pos);
|
||||||
+ // Paper end - optimise collisions
|
+ // Paper end - optimise collisions
|
||||||
@ -4625,7 +4662,7 @@ index 15e2dfa9a17b4f19768c0cde0ad8031f0122cd33..b9aa58d5209c244fe255ab258bb29a82
|
|||||||
}
|
}
|
||||||
|
|
||||||
public VoxelShape getFaceShape(Direction facing) {
|
public VoxelShape getFaceShape(Direction facing) {
|
||||||
@@ -180,7 +717,28 @@ public abstract class VoxelShape {
|
@@ -180,7 +754,28 @@ public abstract class VoxelShape {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double collide(Direction.Axis axis, AABB box, double maxDist) {
|
public double collide(Direction.Axis axis, AABB box, double maxDist) {
|
||||||
|
Loading…
Reference in New Issue
Block a user