2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 13 May 2020 23:01:26 -0400
Subject: [PATCH] Protect Bedrock and End Portal/Frames from being destroyed
This fixes exploits that let players destroy bedrock by Pistons, explosions
and Mushrooom/Tree generation.
These blocks are designed to not be broken except by creative players/commands.
So protect them from a multitude of methods of destroying them.
A config is provided if you rather let players use these exploits, and let
them destroy the worlds End Portals and get on top of the nether easy.
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2022-06-03 04:26:56 +00:00
index 52ba4797d0f27b8aaac262fd5a33dab63e28ebab..855db893080fc8784dc402a4fd7c3080dc9cdc15 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-12-28 08:10:38 +00:00
@@ -435,4 +435,15 @@ public class PaperConfig {
2021-09-09 16:57:16 +00:00
private static void loggerSettings() {
deobfuscateStacktraces = getBoolean("settings.loggers.deobfuscate-stacktraces", deobfuscateStacktraces);
2021-06-11 12:02:28 +00:00
}
+
+ public static boolean allowBlockPermanentBreakingExploits = false;
+ private static void allowBlockPermanentBreakingExploits() {
+ if (config.contains("allow-perm-block-break-exploits")) {
+ allowBlockPermanentBreakingExploits = config.getBoolean("allow-perm-block-break-exploits", false);
+ config.set("allow-perm-block-break-exploits", null);
+ }
+
+ config.set("settings.unsupported-settings.allow-permanent-block-break-exploits-readme", "This setting controls if players should be able to break bedrock, end portals and other intended to be permanent blocks.");
+ allowBlockPermanentBreakingExploits = getBoolean("settings.unsupported-settings.allow-permanent-block-break-exploits", allowBlockPermanentBreakingExploits);
+ }
}
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
2022-06-08 05:02:19 +00:00
index 85e9c23b8dde4266696c6c62fc124b7508a0bb4f..acb94f0dd47e292446c74958667becdc8087f505 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
2022-06-08 05:02:19 +00:00
@@ -172,6 +172,7 @@ public class Explosion {
2021-06-11 12:02:28 +00:00
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockposition = new BlockPos(d4, d5, d6);
BlockState iblockdata = this.level.getBlockState(blockposition);
+ if (!iblockdata.isDestroyable()) continue; // Paper
FluidState fluid = iblockdata.getFluidState(); // Paper
2021-06-14 05:32:56 +00:00
if (!this.level.isInWorldBounds(blockposition)) {
2022-06-08 05:02:19 +00:00
@@ -350,7 +351,7 @@ public class Explosion {
2021-06-11 12:02:28 +00:00
BlockState iblockdata = this.level.getBlockState(blockposition);
Block block = iblockdata.getBlock();
- if (!iblockdata.isAir()) {
+ if (!iblockdata.isAir() && iblockdata.isDestroyable()) { // Paper
BlockPos blockposition1 = blockposition.immutable();
this.level.getProfiler().push("explosion_blocks");
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2022-06-08 05:02:19 +00:00
index 6f04f79832b52fc898ec2b13af03bc28d4e0bbc1..b1cd5781620514533cf0f4d3c518ad461f98f23b 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2022-06-08 05:02:19 +00:00
@@ -425,6 +425,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 12:02:28 +00:00
public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
// CraftBukkit start - tree generation
if (this.captureTreeGeneration) {
+ // Paper start
+ BlockState type = getBlockState(pos);
+ if (!type.isDestroyable()) return false;
+ // Paper end
2021-06-14 05:32:56 +00:00
CraftBlockState blockstate = this.capturedBlockStates.get(pos);
2021-06-11 12:02:28 +00:00
if (blockstate == null) {
blockstate = CapturedBlockState.getTreeBlockState(this, pos, flags);
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
2022-06-08 05:02:19 +00:00
index 0422e389e5b9577417d09490a15584ed5b885209..24556481bf72dae526eb0f13826d693d6516bfb4 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
2022-06-08 05:02:19 +00:00
@@ -92,6 +92,19 @@ public class Block extends BlockBehaviour implements ItemLike {
2021-06-11 12:02:28 +00:00
protected final StateDefinition<Block, BlockState> stateDefinition;
private BlockState defaultBlockState;
// Paper start
+ public final boolean isDestroyable() {
+ return com.destroystokyo.paper.PaperConfig.allowBlockPermanentBreakingExploits ||
+ this != Blocks.BEDROCK &&
+ this != Blocks.END_PORTAL_FRAME &&
+ this != Blocks.END_PORTAL &&
+ this != Blocks.END_GATEWAY &&
+ this != Blocks.COMMAND_BLOCK &&
+ this != Blocks.REPEATING_COMMAND_BLOCK &&
+ this != Blocks.CHAIN_COMMAND_BLOCK &&
+ this != Blocks.BARRIER &&
+ this != Blocks.STRUCTURE_BLOCK &&
+ this != Blocks.JIGSAW;
+ }
public co.aikar.timings.Timing timing;
public co.aikar.timings.Timing getTiming() {
if (timing == null) {
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
2022-06-08 05:02:19 +00:00
index 76720517cd2d82065eb8430cf854b536295341db..272279244f558c8ea298b35605c0421c037aad48 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java
2022-06-08 05:02:19 +00:00
@@ -199,6 +199,12 @@ public class PistonBaseBlock extends DirectionalBlock {
2021-06-11 12:02:28 +00:00
@Override
public boolean triggerEvent(BlockState state, Level world, BlockPos pos, int type, int data) {
Direction enumdirection = (Direction) state.getValue(PistonBaseBlock.FACING);
+ // Paper start - prevent retracting when we're facing the wrong way (we were replaced before retraction could occur)
+ Direction directionQueuedAs = Direction.from3DDataValue(data & 7); // Paper - copied from below
+ if (!com.destroystokyo.paper.PaperConfig.allowBlockPermanentBreakingExploits && enumdirection != directionQueuedAs) {
+ return false;
+ }
+ // Paper end - prevent retracting when we're facing the wrong way
if (!world.isClientSide) {
boolean flag = this.getNeighborSignal(world, pos, enumdirection);
2022-06-08 05:02:19 +00:00
@@ -231,7 +237,7 @@ public class PistonBaseBlock extends DirectionalBlock {
2021-06-11 12:02:28 +00:00
BlockState iblockdata1 = (BlockState) ((BlockState) Blocks.MOVING_PISTON.defaultBlockState().setValue(MovingPistonBlock.FACING, enumdirection)).setValue(MovingPistonBlock.TYPE, this.isSticky ? PistonType.STICKY : PistonType.DEFAULT);
world.setBlock(pos, iblockdata1, 20);
2021-06-14 05:32:56 +00:00
- world.setBlockEntity(MovingPistonBlock.newMovingBlockEntity(pos, iblockdata1, (BlockState) this.defaultBlockState().setValue(PistonBaseBlock.FACING, Direction.from3DDataValue(data & 7)), enumdirection, false, true));
+ world.setBlockEntity(MovingPistonBlock.newMovingBlockEntity(pos, iblockdata1, (BlockState) this.defaultBlockState().setValue(PistonBaseBlock.FACING, Direction.from3DDataValue(data & 7)), enumdirection, false, true)); // Paper - diff on change
2021-06-11 12:02:28 +00:00
world.blockUpdated(pos, iblockdata1.getBlock());
iblockdata1.updateNeighbourShapes(world, pos, 2);
if (this.isSticky) {
2022-06-08 05:02:19 +00:00
@@ -260,7 +266,14 @@ public class PistonBaseBlock extends DirectionalBlock {
2021-06-11 12:02:28 +00:00
}
}
} else {
- world.removeBlock(pos.relative(enumdirection), false);
+ // Paper start - fix headless pistons breaking blocks
+ BlockPos headPos = pos.relative(enumdirection);
+ if (com.destroystokyo.paper.PaperConfig.allowBlockPermanentBreakingExploits || world.getBlockState(headPos) == Blocks.PISTON_HEAD.defaultBlockState().setValue(FACING, enumdirection)) { // double check to make sure we're not a headless piston.
2021-06-17 21:39:36 +00:00
+ world.removeBlock(headPos, false);
2021-06-11 12:02:28 +00:00
+ } else {
+ ((ServerLevel)world).getChunkSource().blockChanged(headPos); // ... fix client desync
+ }
+ // Paper end - fix headless pistons breaking blocks
}
world.playSound((Player) null, pos, SoundEvents.PISTON_CONTRACT, SoundSource.BLOCKS, 0.5F, world.random.nextFloat() * 0.15F + 0.6F);
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
2022-06-08 05:02:19 +00:00
index 942dae5116840a2e8a992f0830574ab2a315bdf1..0ff34d2c569fbeae95509abed343b1e2f593378a 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
2022-06-08 05:02:19 +00:00
@@ -222,7 +222,7 @@ public abstract class BlockBehaviour {
2021-11-24 22:26:32 +00:00
/** @deprecated */
2021-06-11 12:02:28 +00:00
@Deprecated
public boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
2021-06-14 05:32:56 +00:00
- return this.material.isReplaceable() && (context.getItemInHand().isEmpty() || !context.getItemInHand().is(this.asItem()));
+ return this.material.isReplaceable() && (context.getItemInHand().isEmpty() || !context.getItemInHand().is(this.asItem())) && (state.isDestroyable() || (context.getPlayer() != null && context.getPlayer().getAbilities().instabuild)); // Paper
2021-06-11 12:02:28 +00:00
}
2021-11-24 22:26:32 +00:00
/** @deprecated */
2022-06-08 05:02:19 +00:00
@@ -726,6 +726,12 @@ public abstract class BlockBehaviour {
return ((Block) this.owner).builtInRegistryHolder();
2021-06-11 12:02:28 +00:00
}
2022-06-08 05:02:19 +00:00
2021-06-11 12:02:28 +00:00
+ // Paper start
+ public final boolean isDestroyable() {
+ return getBlock().isDestroyable();
+ }
+ // Paper end
2022-06-08 05:02:19 +00:00
+
2021-06-11 12:02:28 +00:00
public Material getMaterial() {
return this.material;
}
2022-06-08 05:02:19 +00:00
@@ -823,7 +829,7 @@ public abstract class BlockBehaviour {
2021-06-11 12:02:28 +00:00
}
public PushReaction getPistonPushReaction() {
- return this.getBlock().getPistonPushReaction(this.asState());
+ return !isDestroyable() ? PushReaction.BLOCK : this.getBlock().getPistonPushReaction(this.asState()); // Paper
}
public boolean isSolidRender(BlockGetter world, BlockPos pos) {
2021-09-07 22:10:48 +00:00
diff --git a/src/main/java/net/minecraft/world/level/portal/PortalForcer.java b/src/main/java/net/minecraft/world/level/portal/PortalForcer.java
2022-06-08 05:02:19 +00:00
index 8672545ba07205ef362442e1342f2ee5281f62cb..504f5d98d4a3d6b5bbd0998b495196aa6b39f47a 100644
2021-09-07 22:10:48 +00:00
--- a/src/main/java/net/minecraft/world/level/portal/PortalForcer.java
+++ b/src/main/java/net/minecraft/world/level/portal/PortalForcer.java
2021-11-24 11:38:00 +00:00
@@ -210,6 +210,13 @@ public class PortalForcer {
2021-09-07 22:10:48 +00:00
for (int j = -1; j < 3; ++j) {
for (int k = -1; k < 4; ++k) {
2021-11-24 11:38:00 +00:00
temp.setWithOffset(pos, portalDirection.getStepX() * j + enumdirection1.getStepX() * distanceOrthogonalToPortal, k, portalDirection.getStepZ() * j + enumdirection1.getStepZ() * distanceOrthogonalToPortal);
2021-09-07 22:10:48 +00:00
+ // Paper start - prevent destroying unbreakable blocks
+ if (!com.destroystokyo.paper.PaperConfig.allowBlockPermanentBreakingExploits) {
+ if (!this.level.getBlockState(temp).isDestroyable()) {
+ return false;
+ }
+ }
+ // Paper end - prevent destroying unbreakable blocks
if (k < 0 && !this.level.getBlockState(temp).getMaterial().isSolid()) {
return false;
}