2020-06-12 07:30:30 +00:00
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.
2020-06-20 18:56:08 +00:00
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.
2020-06-12 07:30:30 +00:00
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
2020-06-20 18:56:08 +00:00
This patch also fixes rail duping and carpet duping.
2020-06-15 16:29:39 +00:00
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-02-06 00:00:18 +00:00
index 456e6363758c41e1d58e178bf839e96aa6df6381..fd3b4a01c84da110d41b7224ebb38ae78b389f79 100644
2020-06-15 16:29:39 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2020-11-09 00:09:37 +00:00
@@ -429,4 +429,10 @@ public class PaperConfig {
2020-06-15 16:29:39 +00:00
consoleHasAllPermissions = getBoolean("settings.console-has-all-permissions", consoleHasAllPermissions);
}
2020-06-20 18:56:08 +00:00
+ public static boolean allowPistonDuplication;
+ private static void allowPistonDuplication() {
2020-07-05 06:12:14 +00:00
+ config.set("settings.unsupported-settings.allow-piston-duplication-readme", "This setting controls if player should be able to use TNT duplication, but this also allows duplicating carpet, rails and potentially other items");
2020-06-20 18:56:08 +00:00
+ allowPistonDuplication = getBoolean("settings.unsupported-settings.allow-piston-duplication", config.getBoolean("settings.unsupported-settings.allow-tnt-duplication", false));
+ set("settings.unsupported-settings.allow-tnt-duplication", null);
2020-06-15 16:29:39 +00:00
+ }
}
2020-06-12 07:30:30 +00:00
diff --git a/src/main/java/net/minecraft/server/BlockPiston.java b/src/main/java/net/minecraft/server/BlockPiston.java
2020-08-25 02:22:08 +00:00
index 0bab7dfb053c1aa92f5417c25fed5484e09bbec3..5d3bb5f393a1e0e4a2e8b9a466530a91279697a9 100644
2020-06-12 07:30:30 +00:00
--- a/src/main/java/net/minecraft/server/BlockPiston.java
+++ b/src/main/java/net/minecraft/server/BlockPiston.java
2020-08-25 02:22:08 +00:00
@@ -370,12 +370,24 @@ public class BlockPiston extends BlockDirectional {
2020-06-20 18:56:08 +00:00
}
2020-06-12 07:30:30 +00:00
for (k = list.size() - 1; k >= 0; --k) {
2020-06-20 18:56:08 +00:00
- blockposition3 = (BlockPosition) list.get(k);
2020-06-12 07:30:30 +00:00
- iblockdata1 = world.getType(blockposition3);
2020-06-20 18:56:08 +00:00
+ // Paper start - fix a variety of piston desync dupes
+ boolean allowDesync = com.destroystokyo.paper.PaperConfig.allowPistonDuplication;
+ BlockPosition oldPos = blockposition3 = (BlockPosition) list.get(k);
+ iblockdata1 = allowDesync ? world.getType(oldPos) : null;
+ // Paper end - fix a variety of piston desync dupes
2020-06-12 07:30:30 +00:00
blockposition3 = blockposition3.shift(enumdirection1);
map.remove(blockposition3);
world.setTypeAndData(blockposition3, (IBlockData) Blocks.MOVING_PISTON.getBlockData().set(BlockPiston.FACING, enumdirection), 68);
2020-06-26 21:36:48 +00:00
- world.setTileEntity(blockposition3, BlockPistonMoving.a((IBlockData) list1.get(k), enumdirection, flag, false));
2020-06-20 18:56:08 +00:00
+ // Paper start - fix a variety of piston desync dupes
+ if (!allowDesync) {
+ iblockdata1 = world.getType(oldPos);
+ map.replace(oldPos, iblockdata1);
+ }
2020-06-26 21:36:48 +00:00
+ world.setTileEntity(blockposition3, BlockPistonMoving.a(allowDesync ? list1.get(k) : iblockdata1, enumdirection, flag, false));
2020-06-20 18:56:08 +00:00
+ if (!allowDesync) {
2020-06-22 23:00:00 +00:00
+ world.setTypeAndData(oldPos, Blocks.AIR.getBlockData(), 2 | 4 | 16 | 1024); // set air to prevent later physics updates from seeing this block
2020-06-20 18:56:08 +00:00
+ }
+ // Paper end - fix a variety of piston desync dupes
2020-06-26 01:58:00 +00:00
aiblockdata[j++] = iblockdata1;
2020-06-12 07:30:30 +00:00
}
2020-06-26 01:58:00 +00:00
2020-06-12 07:30:30 +00:00
diff --git a/src/main/java/net/minecraft/server/TileEntityPiston.java b/src/main/java/net/minecraft/server/TileEntityPiston.java
2020-08-25 02:22:08 +00:00
index 8b2758377b70aaf7a9d21a28d4bbe16389f22403..7d86f0fe55063f6875db9c6f99f4f72ed4144536 100644
2020-06-12 07:30:30 +00:00
--- a/src/main/java/net/minecraft/server/TileEntityPiston.java
+++ b/src/main/java/net/minecraft/server/TileEntityPiston.java
2020-06-26 01:58:00 +00:00
@@ -256,7 +256,7 @@ public class TileEntityPiston extends TileEntity implements ITickable {
2020-08-25 02:22:08 +00:00
IBlockData iblockdata = Block.b(this.a, (GeneratorAccess) this.world, this.position);
2020-06-12 07:30:30 +00:00
2020-08-25 02:22:08 +00:00
if (iblockdata.isAir()) {
- this.world.setTypeAndData(this.position, this.a, 84);
2020-06-20 18:56:08 +00:00
+ this.world.setTypeAndData(this.position, this.a, com.destroystokyo.paper.PaperConfig.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
2020-08-25 02:22:08 +00:00
Block.a(this.a, iblockdata, this.world, this.position, 3);
} else {
if (iblockdata.b(BlockProperties.C) && (Boolean) iblockdata.get(BlockProperties.C)) {