Skip to content

Commit 1a67430

Browse files
committed
Fix floating point issue on legacy physics versions pre-1.17
1 parent be2aa6f commit 1a67430

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Diff for: patches/server/0040-Configure-cannon-physics-by-version.patch

+24-6
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ index 50259042ebafe520342bdb1a4b7e6b9138b8acbd..adf8be12b754c3d9b16ef4a7c675dd2c
217217
if (this.level().hasChunksAt(blockposition, blockposition1)) {
218218
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
219219
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
220-
index bf52aafe542ca735181e461d1f9cbc39b8d88220..80168d32a95bd960e781751fcf05ff591276e991 100644
220+
index bf52aafe542ca735181e461d1f9cbc39b8d88220..87ef8f4953c7d9fddfc9ddbdb027e76145b645c8 100644
221221
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
222222
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
223223
@@ -89,6 +89,8 @@ public class FallingBlockEntity extends Entity {
@@ -242,7 +242,7 @@ index bf52aafe542ca735181e461d1f9cbc39b8d88220..80168d32a95bd960e781751fcf05ff59
242242
world.addFreshEntity(entityfallingblock, spawnReason); // CraftBukkit
243243
return entityfallingblock;
244244
}
245-
@@ -188,7 +194,37 @@ public class FallingBlockEntity extends Entity {
245+
@@ -188,7 +194,43 @@ public class FallingBlockEntity extends Entity {
246246
// Sakura start
247247
@Override
248248
public final double getEyeY() {
@@ -261,6 +261,12 @@ index bf52aafe542ca735181e461d1f9cbc39b8d88220..80168d32a95bd960e781751fcf05ff59
261261
+ return x * x + y * y + z * z;
262262
+ }
263263
+
264+
+ private BlockPos patchedBlockPosition() {
265+
+ // mitigate the floating point issue for sand breaking below y-0
266+
+ // 1.0e-12 allows tech that uses indirect collision clipping to still function
267+
+ return BlockPos.containing(this.getX(), this.getY() + 1.0e-12, this.getZ());
268+
+ }
269+
+
264270
+ private void removeBlockOnFall(Block block) {
265271
+ BlockPos blockposition = this.blockPosition();
266272
+ // Paper start - fix cancelling block falling causing client desync
@@ -281,7 +287,7 @@ index bf52aafe542ca735181e461d1f9cbc39b8d88220..80168d32a95bd960e781751fcf05ff59
281287
}
282288
// Sakura end
283289

284-
@@ -204,9 +240,16 @@ public class FallingBlockEntity extends Entity {
290+
@@ -204,9 +246,16 @@ public class FallingBlockEntity extends Entity {
285291
} else {
286292
Block block = this.blockState.getBlock();
287293

@@ -299,7 +305,7 @@ index bf52aafe542ca735181e461d1f9cbc39b8d88220..80168d32a95bd960e781751fcf05ff59
299305
}
300306

301307
this.moveBasic(MoverType.SELF, this.getDeltaMovement()); // Sakura
302-
@@ -227,6 +270,11 @@ public class FallingBlockEntity extends Entity {
308+
@@ -227,8 +276,23 @@ public class FallingBlockEntity extends Entity {
303309
return;
304310
}
305311
// Paper end
@@ -310,8 +316,20 @@ index bf52aafe542ca735181e461d1f9cbc39b8d88220..80168d32a95bd960e781751fcf05ff59
310316
+ // Sakura end
311317
if (!this.level().isClientSide) {
312318
BlockPos blockposition = this.blockPosition();
319+
+
320+
+ // Sakura start
321+
+ // Patching this on modern versions can break some cannons that utilise
322+
+ // the floating point issue. But it makes sense on legacy versions where
323+
+ // that is seemingly not an issue.
324+
+ if (this.physics.before(1_17_0)) {
325+
+ blockposition = this.patchedBlockPosition();
326+
+ }
327+
+ // Sakura end
328+
+
313329
boolean flag = this.blockState.getBlock() instanceof ConcretePowderBlock;
314-
@@ -253,7 +301,20 @@ public class FallingBlockEntity extends Entity {
330+
boolean flag1 = flag && this.level().getFluidState(blockposition).is(FluidTags.WATER);
331+
double d0 = this.getDeltaMovement().lengthSqr();
332+
@@ -253,7 +317,20 @@ public class FallingBlockEntity extends Entity {
315333
} else {
316334
BlockState iblockdata = this.level().getBlockState(blockposition);
317335

@@ -333,7 +351,7 @@ index bf52aafe542ca735181e461d1f9cbc39b8d88220..80168d32a95bd960e781751fcf05ff59
333351
if (!iblockdata.is(Blocks.MOVING_PISTON)) {
334352
if (!this.cancelDrop) {
335353
boolean flag2 = iblockdata.canBeReplaced((BlockPlaceContext) (new DirectionalPlaceContext(this.level(), blockposition, Direction.DOWN, ItemStack.EMPTY, Direction.UP)));
336-
@@ -321,7 +382,12 @@ public class FallingBlockEntity extends Entity {
354+
@@ -321,7 +398,12 @@ public class FallingBlockEntity extends Entity {
337355
}
338356
}
339357

0 commit comments

Comments
 (0)