Paper/patches/server/0409-Fix-piston-physics-inconsistency-MC-188840.patch
Nassim Jahnke c0936a71bd
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9440)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
01aa02eb PR-858: Add LivingEntity#playHurtAnimation()
9421320f PR-884: Refinements to new ban API for improved compatibility and correctness
37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API
4eeb174b All smithing inventories are now the new smithing inventory
f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop
e7a807fa PR-879: Add Player#sendHealthUpdate()
692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml
2d033390 SPIGOT-7403: Add direct API for waxed signs
16a08373 PR-876: Add missing Raider API and 'no action ticks'

CraftBukkit Changes:
b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation()
95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities
0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness
0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit
648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API
31fe848d6 All smithing inventories are now the new smithing inventory
9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table
9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop
3be9ac171 PR-1220: Add Player#sendHealthUpdate()
c1279f775 PR-1209: Clean up various patches
c432e4397 Fix Raider#setCelebrating() implementation
504d96665 SPIGOT-7403: Add direct API for waxed signs
c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks'
85b89c3dd Increase outdated build delay

Spigot Changes:
9ebce8af Rebuild patches
64b565e6 Rebuild patches
2023-07-04 10:22:56 +02:00

81 lines
5.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 11 Jun 2020 17:29:42 -0700
Subject: [PATCH] Fix piston physics inconsistency - MC-188840
Pistons invoke physics when they move blocks. The physics can cause
tnt blocks to ignite. However, pistons (when storing the blocks they "moved")
don't actually go back to the world state sometimes to check if something
like that happened. As a result they end up moving the tnt like it was
never ignited. This resulted in the ability to create machines
that can duplicate tnt, called "world eaters".
This patch makes the piston logic retrieve the block state from the world
prevent this from occuring.
This patch also sets the moved pos to air immediately after creating
the moving piston TE. This prevents the block from being updated from
other physics calls by the piston.
Tested against the following tnt duper design:
https://www.youtube.com/watch?v=mS7xxNGhjxs
This patch also affects every type of machine that utilises
this mechanic. For example, dead coral is removed by a physics
update when being moved while it is attached to slimeblocks.
Standard piston machines that don't destroy or modify the
blocks they move by physics updates should be entirely
unaffected.
This patch fixes https://bugs.mojang.com/browse/MC-188840
This patch also fixes rail duping and carpet duping.
diff --git a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
index 4f6b7ed4809086811f0460544ba2ec0606f0f5da..9abae63e06c1dde9b8434d32bac8798808428d10 100644
--- a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
@@ -412,14 +412,26 @@ public class PistonBaseBlock extends DirectionalBlock {
}
for (k = list.size() - 1; k >= 0; --k) {
- blockposition3 = (BlockPos) list.get(k);
- iblockdata1 = world.getBlockState(blockposition3);
+ // Paper start - fix a variety of piston desync dupes
+ boolean allowDesync = io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowPistonDuplication;
+ BlockPos oldPos = blockposition3 = (BlockPos) list.get(k);
+ iblockdata1 = allowDesync ? world.getBlockState(oldPos) : null;
+ // Paper end - fix a variety of piston desync dupes
blockposition3 = blockposition3.relative(enumdirection1);
map.remove(blockposition3);
BlockState iblockdata2 = (BlockState) Blocks.MOVING_PISTON.defaultBlockState().setValue(PistonBaseBlock.FACING, dir);
world.setBlock(blockposition3, iblockdata2, 68);
- world.setBlockEntity(MovingPistonBlock.newMovingBlockEntity(blockposition3, iblockdata2, (BlockState) list1.get(k), dir, retract, false));
+ // Paper start - fix a variety of piston desync dupes
+ if (!allowDesync) {
+ iblockdata1 = world.getBlockState(oldPos);
+ map.replace(oldPos, iblockdata1);
+ }
+ world.setBlockEntity(MovingPistonBlock.newMovingBlockEntity(blockposition3, iblockdata2, allowDesync ? list1.get(k) : iblockdata1, dir, retract, false));
+ if (!allowDesync) {
+ world.setBlock(oldPos, Blocks.AIR.defaultBlockState(), 2 | 4 | 16 | 1024); // set air to prevent later physics updates from seeing this block
+ }
+ // Paper end - fix a variety of piston desync dupes
aiblockdata[j++] = iblockdata1;
}
diff --git a/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java b/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
index 17a6327ab7b26dfab38881bbc0689b0b25f8f025..30fafbb26a347b73c72b9f5c30da3b01e42b851c 100644
--- a/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
@@ -288,7 +288,7 @@ public class PistonMovingBlockEntity extends BlockEntity {
if (world.getBlockState(pos).is(Blocks.MOVING_PISTON)) {
BlockState blockState = Block.updateFromNeighbourShapes(blockEntity.movedState, world, pos);
if (blockState.isAir()) {
- world.setBlock(pos, blockEntity.movedState, 84);
+ world.setBlock(pos, blockEntity.movedState, io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowPistonDuplication ? 84 : (84 | 2)); // Paper - force notify (flag 2), it's possible the set type by the piston block (which doesn't notify) set this block to air
Block.updateOrDestroy(blockEntity.movedState, blockState, world, pos, 3);
} else {
if (blockState.hasProperty(BlockStateProperties.WATERLOGGED) && blockState.getValue(BlockStateProperties.WATERLOGGED)) {