2021-06-11 14:02:28 +02: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/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
2024-03-03 23:05:34 +01:00
index 217018dbdd78af4b89d9d4e7154956593dfa8dae..093c814d6835f20b1208236db96bb40b4611936c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
2023-12-05 23:55:31 +01:00
@@ -191,6 +191,7 @@ public class Explosion {
2021-06-11 14:02:28 +02:00
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
2023-03-14 20:54:57 +01:00
BlockPos blockposition = BlockPos.containing(d4, d5, d6);
2021-06-11 14:02:28 +02:00
BlockState iblockdata = this.level.getBlockState(blockposition);
2024-01-21 12:11:43 +01:00
+ if (!iblockdata.isDestroyable()) continue; // Paper - Protect Bedrock and End Portal/Frames from being destroyed
2024-01-21 12:53:04 +01:00
FluidState fluid = iblockdata.getFluidState(); // Paper - Perf: Optimize call to getFluid for explosions
2021-06-11 14:02:28 +02:00
2021-06-14 07:32:56 +02:00
if (!this.level.isInWorldBounds(blockposition)) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2024-04-06 21:53:39 +02:00
index 983dad7ecc58033ecb6f523f7aef24de122417e8..44d81cacbe3ec878f3af02f4fad974d75fc4db9e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2024-02-01 10:15:57 +01:00
@@ -540,6 +540,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 14:02:28 +02:00
public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
// CraftBukkit start - tree generation
if (this.captureTreeGeneration) {
2024-01-21 12:11:43 +01:00
+ // Paper start - Protect Bedrock and End Portal/Frames from being destroyed
2021-06-11 14:02:28 +02:00
+ BlockState type = getBlockState(pos);
+ if (!type.isDestroyable()) return false;
2024-01-21 12:11:43 +01:00
+ // Paper end - Protect Bedrock and End Portal/Frames from being destroyed
2021-06-14 07:32:56 +02:00
CraftBlockState blockstate = this.capturedBlockStates.get(pos);
2021-06-11 14:02:28 +02: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
2024-02-01 10:15:57 +01:00
index 6896d46fce2e466ebee23ac2dc00312ec1beefdb..b60a52788e73de3dcb086c1a4628466b25c9d3ef 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
2023-12-05 23:55:31 +01:00
@@ -90,6 +90,19 @@ public class Block extends BlockBehaviour implements ItemLike {
2021-06-11 14:02:28 +02:00
protected final StateDefinition<Block, BlockState> stateDefinition;
private BlockState defaultBlockState;
// Paper start
+ public final boolean isDestroyable() {
2022-06-09 10:51:45 +02:00
+ return io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowPermanentBlockBreakExploits ||
2021-06-11 14:02:28 +02:00
+ 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
2024-01-23 12:06:27 +01:00
index 3dfe79684f662ac7cae4583bfe03a633438b4df7..be74adc86f0ca467f3b59e7b57fd47a8f381d86e 100644
2021-06-11 14:02:28 +02: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
2023-12-05 23:55:31 +01:00
@@ -212,6 +212,12 @@ public class PistonBaseBlock extends DirectionalBlock {
2021-06-11 14:02:28 +02:00
@Override
public boolean triggerEvent(BlockState state, Level world, BlockPos pos, int type, int data) {
Direction enumdirection = (Direction) state.getValue(PistonBaseBlock.FACING);
2024-01-21 12:11:43 +01:00
+ // Paper start - Protect Bedrock and End Portal/Frames from being destroyed; prevent retracting when we're facing the wrong way (we were replaced before retraction could occur)
2021-06-11 14:02:28 +02:00
+ Direction directionQueuedAs = Direction.from3DDataValue(data & 7); // Paper - copied from below
2022-06-09 10:51:45 +02:00
+ if (!io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowPermanentBlockBreakExploits && enumdirection != directionQueuedAs) {
2021-06-11 14:02:28 +02:00
+ return false;
+ }
2024-01-21 12:11:43 +01:00
+ // Paper end - Protect Bedrock and End Portal/Frames from being destroyed
2023-06-08 00:58:10 +02:00
BlockState iblockdata1 = (BlockState) state.setValue(PistonBaseBlock.EXTENDED, true);
2021-06-11 14:02:28 +02:00
if (!world.isClientSide) {
2024-01-23 12:06:27 +01:00
@@ -252,7 +258,7 @@ public class PistonBaseBlock extends DirectionalBlock {
}
// Paper end - Fix sticky pistons and BlockPistonRetractEvent
2023-06-08 00:58:10 +02:00
world.setBlock(pos, iblockdata2, 20);
- world.setBlockEntity(MovingPistonBlock.newMovingBlockEntity(pos, iblockdata2, (BlockState) this.defaultBlockState().setValue(PistonBaseBlock.FACING, Direction.from3DDataValue(data & 7)), enumdirection, false, true));
2024-01-21 12:11:43 +01:00
+ world.setBlockEntity(MovingPistonBlock.newMovingBlockEntity(pos, iblockdata2, (BlockState) this.defaultBlockState().setValue(PistonBaseBlock.FACING, Direction.from3DDataValue(data & 7)), enumdirection, false, true)); // Paper - Protect Bedrock and End Portal/Frames from being destroyed; diff on change
2023-06-08 00:58:10 +02:00
world.blockUpdated(pos, iblockdata2.getBlock());
iblockdata2.updateNeighbourShapes(world, pos, 2);
2021-06-11 14:02:28 +02:00
if (this.isSticky) {
2024-01-23 12:06:27 +01:00
@@ -288,7 +294,14 @@ public class PistonBaseBlock extends DirectionalBlock {
2021-06-11 14:02:28 +02:00
}
}
} else {
- world.removeBlock(pos.relative(enumdirection), false);
2024-01-21 12:11:43 +01:00
+ // Paper start - Protect Bedrock and End Portal/Frames from being destroyed; fix headless pistons breaking blocks
2021-06-11 14:02:28 +02:00
+ BlockPos headPos = pos.relative(enumdirection);
2022-06-09 10:51:45 +02:00
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowPermanentBlockBreakExploits || world.getBlockState(headPos) == Blocks.PISTON_HEAD.defaultBlockState().setValue(FACING, enumdirection)) { // double check to make sure we're not a headless piston.
2021-06-17 23:39:36 +02:00
+ world.removeBlock(headPos, false);
2021-06-11 14:02:28 +02:00
+ } else {
2024-01-21 12:11:43 +01:00
+ ((ServerLevel) world).getChunkSource().blockChanged(headPos); // ... fix client desync
2021-06-11 14:02:28 +02:00
+ }
2024-01-21 12:11:43 +01:00
+ // Paper end - Protect Bedrock and End Portal/Frames from being destroyed
2021-06-11 14:02:28 +02:00
}
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
2024-02-01 10:15:57 +01:00
index e28ac8f7960f648099e5f3607530a406c72e5056..e493b34aa8726ed48f8e5db2ae8ea561cc5b1f75 100644
2021-06-11 14:02:28 +02: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
2024-01-23 12:06:27 +01:00
@@ -189,7 +189,7 @@ public abstract class BlockBehaviour implements FeatureElement {
2023-12-05 23:55:31 +01:00
/** @deprecated */
@Deprecated
public void onExplosionHit(BlockState state, Level world, BlockPos pos, Explosion explosion, BiConsumer<ItemStack, BlockPos> stackMerger) {
- if (!state.isAir() && explosion.getBlockInteraction() != Explosion.BlockInteraction.TRIGGER_BLOCK) {
2024-01-21 12:11:43 +01:00
+ if (!state.isAir() && explosion.getBlockInteraction() != Explosion.BlockInteraction.TRIGGER_BLOCK && state.isDestroyable()) { // Paper - Protect Bedrock and End Portal/Frames from being destroyed
2023-12-05 23:55:31 +01:00
Block block = state.getBlock();
boolean flag = explosion.getIndirectSourceEntity() instanceof Player;
2024-01-23 12:06:27 +01:00
@@ -285,7 +285,7 @@ public abstract class BlockBehaviour implements FeatureElement {
2021-11-24 23:26:32 +01:00
/** @deprecated */
2021-06-11 14:02:28 +02:00
@Deprecated
public boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
2023-06-08 00:58:10 +02:00
- return state.canBeReplaced() && (context.getItemInHand().isEmpty() || !context.getItemInHand().is(this.asItem()));
2024-01-21 12:11:43 +01:00
+ return state.canBeReplaced() && (context.getItemInHand().isEmpty() || !context.getItemInHand().is(this.asItem())) && (state.isDestroyable() || (context.getPlayer() != null && context.getPlayer().getAbilities().instabuild)); // Paper - Protect Bedrock and End Portal/Frames from being destroyed
2021-06-11 14:02:28 +02:00
}
2021-11-24 23:26:32 +01:00
/** @deprecated */
2024-01-23 12:06:27 +01:00
@@ -965,6 +965,12 @@ public abstract class BlockBehaviour implements FeatureElement {
2023-06-08 00:58:10 +02:00
return this.legacySolid;
2021-06-11 14:02:28 +02:00
}
2022-06-08 07:02:19 +02:00
2024-01-21 12:11:43 +01:00
+ // Paper start - Protect Bedrock and End Portal/Frames from being destroyed
2021-06-11 14:02:28 +02:00
+ public final boolean isDestroyable() {
+ return getBlock().isDestroyable();
+ }
2024-01-21 12:11:43 +01:00
+ // Paper end - Protect Bedrock and End Portal/Frames from being destroyed
2022-06-08 07:02:19 +02:00
+
2023-06-08 00:58:10 +02:00
public boolean isValidSpawn(BlockGetter world, BlockPos pos, EntityType<?> type) {
return this.getBlock().properties.isValidSpawn.test(this.asState(), world, pos, type);
2021-06-11 14:02:28 +02:00
}
2024-01-23 12:06:27 +01:00
@@ -1068,7 +1074,7 @@ public abstract class BlockBehaviour implements FeatureElement {
2021-06-11 14:02:28 +02:00
}
public PushReaction getPistonPushReaction() {
2023-06-08 00:58:10 +02:00
- return this.pushReaction;
2024-01-21 12:11:43 +01:00
+ return !this.isDestroyable() ? PushReaction.BLOCK : this.pushReaction; // Paper - Protect Bedrock and End Portal/Frames from being destroyed
2021-06-11 14:02:28 +02:00
}
public boolean isSolidRender(BlockGetter world, BlockPos pos) {
2021-09-08 00:10:48 +02: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
2024-01-24 11:45:17 +01:00
index afdd4ecbff21e2172b390bcbdf74f3c1bbddafcc..bb739f8584dd3847152314aa995800f51907da2f 100644
2021-09-08 00:10:48 +02:00
--- a/src/main/java/net/minecraft/world/level/portal/PortalForcer.java
+++ b/src/main/java/net/minecraft/world/level/portal/PortalForcer.java
2022-12-07 21:16:54 +01:00
@@ -221,6 +221,13 @@ public class PortalForcer {
2021-09-08 00:10:48 +02:00
for (int j = -1; j < 3; ++j) {
for (int k = -1; k < 4; ++k) {
2021-11-24 12:38:00 +01:00
temp.setWithOffset(pos, portalDirection.getStepX() * j + enumdirection1.getStepX() * distanceOrthogonalToPortal, k, portalDirection.getStepZ() * j + enumdirection1.getStepZ() * distanceOrthogonalToPortal);
2024-01-21 12:11:43 +01:00
+ // Paper start - Protect Bedrock and End Portal/Frames from being destroyed
2022-06-09 10:51:45 +02:00
+ if (!io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowPermanentBlockBreakExploits) {
2021-09-08 00:10:48 +02:00
+ if (!this.level.getBlockState(temp).isDestroyable()) {
+ return false;
+ }
+ }
2024-01-21 12:11:43 +01:00
+ // Paper end - Protect Bedrock and End Portal/Frames from being destroyed
2023-06-08 00:58:10 +02:00
if (k < 0 && !this.level.getBlockState(temp).isSolid()) {
2021-09-08 00:10:48 +02:00
return false;
}