Skip to content

Commit f8dabbe

Browse files
committed
Clean up cannon physics in falling block entity
1 parent 4141a42 commit f8dabbe

2 files changed

+31
-44
lines changed

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

+28-41
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ index ae2eede559bd9fe7e500ce180f2ac102a95d3856..7ced5ae768cbea9ee0a7bab2365fbaef
3636
if (xSmaller && z != 0.0) {
3737
z = performAABBCollisionsZ(axisalignedbb, z, aabbs);
3838
diff --git a/src/main/java/me/samsuik/sakura/explosion/SakuraExplosion.java b/src/main/java/me/samsuik/sakura/explosion/SakuraExplosion.java
39-
index 90540b3c8c695e24419b0e0460f0c42f949142b0..a41a831d0e8340312e7c0abeb5da35bf6a8a9d65 100644
39+
index 4f9880d35347dd008aa2ee6e67f35301ff37a4c0..79d5cd8f90fda2390a64c2d1e0cfca6b66ad83ac 100644
4040
--- a/src/main/java/me/samsuik/sakura/explosion/SakuraExplosion.java
4141
+++ b/src/main/java/me/samsuik/sakura/explosion/SakuraExplosion.java
4242
@@ -244,10 +244,17 @@ public class SakuraExplosion extends Explosion {
@@ -217,7 +217,7 @@ index 4c97c47e00fec68ef2e87bc981ccb811bbff6516..7e00e47fe01b996bf6a2f16dc4998ab8
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 0f1c9eb07c19dd0926521418390855f4bc1bc399..12eed2d1972de15e4d4b953517d47f2b567d3866 100644
220+
index 0f1c9eb07c19dd0926521418390855f4bc1bc399..99887ed1044cff244074a4584729df50239e9e9a 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 0f1c9eb07c19dd0926521418390855f4bc1bc399..12eed2d1972de15e4d4b953517d47f2b
242242
world.addFreshEntity(entityfallingblock, spawnReason); // CraftBukkit
243243
return entityfallingblock;
244244
}
245-
@@ -188,7 +194,43 @@ public class FallingBlockEntity extends Entity {
245+
@@ -188,7 +194,44 @@ public class FallingBlockEntity extends Entity {
246246
// Sakura start
247247
@Override
248248
public final double getEyeY() {
@@ -267,27 +267,28 @@ index 0f1c9eb07c19dd0926521418390855f4bc1bc399..12eed2d1972de15e4d4b953517d47f2b
267267
+ return BlockPos.containing(this.getX(), this.getY() + 1.0e-12, this.getZ());
268268
+ }
269269
+
270+
+ private boolean isAbleToStackOnBlock() {
271+
+ BlockPos pos = BlockPos.containing(this.getX(), this.getY() - 0.001f, this.getZ());
272+
+ BlockState state = this.level().getBlockState(pos);
273+
+ return FallingBlock.isFree(state);
274+
+ }
275+
+
270276
+ private void removeBlockOnFall(Block block) {
271277
+ BlockPos blockposition = this.blockPosition();
272-
+ // Paper start - fix cancelling block falling causing client desync
273-
+ if (!this.level().getBlockState(blockposition).is(block) || !CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR.defaultBlockState())) {
274-
+ if (this.level().getBlockState(blockposition).is(block)) { //if listener didn't update the block
278+
+ BlockState blockstate = this.level().getBlockState(blockposition);
279+
+
280+
+ if (blockstate.is(block) && CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR.defaultBlockState())) {
281+
+ this.level().removeBlock(blockposition, false);
282+
+ } else {
283+
+ if (blockstate.is(block)) {
275284
+ ((ServerLevel) level()).getChunkSource().blockChanged(blockposition);
276285
+ }
277286
+ this.discard();
278-
+ } else {
279-
+ this.level().removeBlock(blockposition, false);
280287
+ }
281-
+ // Paper end - fix cancelling block falling causing client desync
282-
+ }
283-
+
284-
+ // Why was this special cased for sand in the first place?
285-
+ private static boolean isInAir(BlockState state) {
286-
+ return state.is(Blocks.FIRE) || state.is(Blocks.AIR) || !state.getFluidState().isEmpty() || state.is(Blocks.WATER) || state.is(Blocks.LAVA);
287288
}
288289
// Sakura end
289290

290-
@@ -204,9 +246,16 @@ public class FallingBlockEntity extends Entity {
291+
@@ -204,9 +247,16 @@ public class FallingBlockEntity extends Entity {
291292
} else {
292293
Block block = this.blockState.getBlock();
293294

@@ -305,53 +306,39 @@ index 0f1c9eb07c19dd0926521418390855f4bc1bc399..12eed2d1972de15e4d4b953517d47f2b
305306
}
306307

307308
this.moveBasic(MoverType.SELF, this.getDeltaMovement()); // Sakura
308-
@@ -227,8 +276,23 @@ public class FallingBlockEntity extends Entity {
309+
@@ -227,8 +277,16 @@ public class FallingBlockEntity extends Entity {
309310
return;
310311
}
311312
// Paper end
312313
+ // Sakura start - physics version api
313314
+ if (this.physics.before(1_12_0)) {
314315
+ this.scaleDeltaMovement(0.98F);
315316
+ }
316-
+ // Sakura end
317317
if (!this.level().isClientSide) {
318-
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-
+ }
318+
- BlockPos blockposition = this.blockPosition();
319+
+ // Patching the floating point issue on modern versions can break some cannons that rely on it.
320+
+ // However, it makes sense for legacy versions pre-1.17 before the world height change.
321+
+ BlockPos blockposition = this.physics.before(1_17_0) ? this.patchedBlockPosition() : this.blockPosition();
327322
+ // Sakura end
328323
+
329324
boolean flag = this.blockState.getBlock() instanceof ConcretePowderBlock;
330325
boolean flag1 = flag && this.level().getFluidState(blockposition).is(FluidTags.WATER);
331326
double d0 = this.getDeltaMovement().lengthSqr();
332-
@@ -253,7 +317,20 @@ public class FallingBlockEntity extends Entity {
327+
@@ -253,8 +311,11 @@ public class FallingBlockEntity extends Entity {
333328
} else {
334329
BlockState iblockdata = this.level().getBlockState(blockposition);
335330

336331
- this.multiplyDeltaMovement(0.7D, -0.5D, 0.7D); // Sakura - reduce movement allocations
332+
- if (!iblockdata.is(Blocks.MOVING_PISTON)) {
337333
+ // Sakura start - physics version api
338-
+ if (!flag1 && this.physics.isWithin(1_9_0, 1_12_0)) {
339-
+ BlockPos pos = BlockPos.containing(this.getX(), this.getY() - 0.001f, this.getZ());
340-
+ BlockState state = this.level().getBlockState(pos);
341-
+ this.onGround = !isInAir(state); // this is how it's implemented between 1.9 and 1.12
342-
+
343-
+ if (!this.onGround) {
344-
+ iblockdata = Blocks.MOVING_PISTON.defaultBlockState(); // prevent it turning into a solid
345-
+ }
346-
+ }
347-
+
348334
+ double friction = this.physics.before(1_14_0) ? 0.7F : 0.7D;
349335
+ this.multiplyDeltaMovement(friction, -0.5D, friction); // Sakura - reduce movement allocations
350-
+ // Sakura end
351-
if (!iblockdata.is(Blocks.MOVING_PISTON)) {
336+
+ if (!iblockdata.is(Blocks.MOVING_PISTON) && (flag1 || !this.physics.isWithin(1_9_0, 1_12_0) || this.isAbleToStackOnBlock())) {
337+
+ // Sakura end
352338
if (!this.cancelDrop) {
353339
boolean flag2 = iblockdata.canBeReplaced((BlockPlaceContext) (new DirectionalPlaceContext(this.level(), blockposition, Direction.DOWN, ItemStack.EMPTY, Direction.UP)));
354-
@@ -321,7 +398,12 @@ public class FallingBlockEntity extends Entity {
340+
boolean flag3 = FallingBlock.isFree(this.level().getBlockState(blockposition.below())) && (!flag || !flag1);
341+
@@ -321,7 +382,12 @@ public class FallingBlockEntity extends Entity {
355342
}
356343
}
357344

@@ -459,7 +446,7 @@ index 545c15a5bc92450de75e931794c2289da7004617..5010c994dae5aa189b2c02f9b9fc9715
459446
// Paper end
460447
}
461448
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
462-
index d13ba91f2c633517d46f59eaa938fd81d441fedb..7bef41c62d6c96062532233c80b96d6e65a523c8 100644
449+
index 4c570ea162f0dec00960705ef615d6e9f4a210a7..8a2d9f6526b62080c4b35ff856b8125c32983364 100644
463450
--- a/src/main/java/net/minecraft/world/level/Explosion.java
464451
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
465452
@@ -74,6 +74,7 @@ public class Explosion {

patches/server/0042-Configure-concrete-solidifying-in-water.patch

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Subject: [PATCH] Configure concrete solidifying in water
55

66

77
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
8-
index 87ef8f4953c7d9fddfc9ddbdb027e76145b645c8..7f01adefebb98edaa035711bcb18b695d167fe97 100644
8+
index 99887ed1044cff244074a4584729df50239e9e9a..bdea4539bd3c0448c16ccb19bb4a7a932fcef9e1 100644
99
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
1010
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
11-
@@ -293,7 +293,7 @@ public class FallingBlockEntity extends Entity {
12-
}
11+
@@ -287,7 +287,7 @@ public class FallingBlockEntity extends Entity {
12+
BlockPos blockposition = this.physics.before(1_17_0) ? this.patchedBlockPosition() : this.blockPosition();
1313
// Sakura end
1414

1515
- boolean flag = this.blockState.getBlock() instanceof ConcretePowderBlock;

0 commit comments

Comments
 (0)