2023-04-18 04:51:21 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
|
|
Date: Mon, 17 Apr 2023 19:47:57 -0700
|
|
|
|
Subject: [PATCH] Prevent block updates in non-loaded or non-owned chunks
|
|
|
|
|
|
|
|
This is to prevent block physics from tripping thread checks by
|
|
|
|
far exceeding the bounds of the current region. While this does
|
|
|
|
add explicit block update suppression techniques, it's better
|
|
|
|
than the server crashing.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
2024-07-31 05:09:52 +02:00
|
|
|
index b0ad25daf2d3c1727c61686e35eb4c03e1c60122..d963e8a6a498232a9ae760b2befaa17578a192f8 100644
|
2023-04-18 04:51:21 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
2024-07-31 05:09:52 +02:00
|
|
|
@@ -1919,7 +1919,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
2023-04-18 04:51:21 +02:00
|
|
|
Direction enumdirection = (Direction) iterator.next();
|
|
|
|
BlockPos blockposition1 = pos.relative(enumdirection);
|
|
|
|
|
|
|
|
- if (this.hasChunkAt(blockposition1)) {
|
2024-07-31 05:09:52 +02:00
|
|
|
+ if (ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor((ServerLevel)this, blockposition1) && this.hasChunkAt(blockposition1)) { // Folia - block updates in unloaded chunks
|
2023-04-18 04:51:21 +02:00
|
|
|
BlockState iblockdata = this.getBlockState(blockposition1);
|
|
|
|
|
|
|
|
if (iblockdata.is(Blocks.COMPARATOR)) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/DetectorRailBlock.java b/src/main/java/net/minecraft/world/level/block/DetectorRailBlock.java
|
2024-07-31 05:09:52 +02:00
|
|
|
index 9d69e439ff853465303c2abd896e6c5314752e1e..69e1748d9d40a8cbf672ba49a8a01e9ff847efd9 100644
|
2023-04-18 04:51:21 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/DetectorRailBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/DetectorRailBlock.java
|
2023-12-17 00:32:48 +01:00
|
|
|
@@ -134,9 +134,9 @@ public class DetectorRailBlock extends BaseRailBlock {
|
2023-04-18 04:51:21 +02:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
BlockPos blockposition1 = (BlockPos) iterator.next();
|
|
|
|
- BlockState iblockdata1 = world.getBlockState(blockposition1);
|
2024-07-31 05:09:52 +02:00
|
|
|
+ BlockState iblockdata1 = !ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor((ServerLevel)world, blockposition1) ? null : world.getBlockStateIfLoaded(blockposition1); // Folia - block updates in unloaded chunks
|
2023-04-18 04:51:21 +02:00
|
|
|
|
|
|
|
- world.neighborChanged(iblockdata1, blockposition1, iblockdata1.getBlock(), pos, false);
|
|
|
|
+ if (iblockdata1 != null) world.neighborChanged(iblockdata1, blockposition1, iblockdata1.getBlock(), pos, false); // Folia - block updates in unloaded chunks
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/PoweredRailBlock.java b/src/main/java/net/minecraft/world/level/block/PoweredRailBlock.java
|
2024-07-31 05:09:52 +02:00
|
|
|
index 9603d8c84ff483030dc08e82d3579b89e5c1f6e9..e2d1f25010d4ec8051c8635440b6c9bfa1e6ae88 100644
|
2023-04-18 04:51:21 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/PoweredRailBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/PoweredRailBlock.java
|
2023-12-17 00:32:48 +01:00
|
|
|
@@ -104,9 +104,9 @@ public class PoweredRailBlock extends BaseRailBlock {
|
2023-04-18 04:51:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean isSameRailWithPower(Level world, BlockPos pos, boolean flag, int distance, RailShape shape) {
|
|
|
|
- BlockState iblockdata = world.getBlockState(pos);
|
2024-07-31 05:09:52 +02:00
|
|
|
+ BlockState iblockdata = !ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor((net.minecraft.server.level.ServerLevel)world, pos) ? null : world.getBlockStateIfLoaded(pos); // Folia - block updates in unloaded chunks
|
2023-04-18 04:51:21 +02:00
|
|
|
|
|
|
|
- if (!iblockdata.is((Block) this)) {
|
|
|
|
+ if (iblockdata == null || !iblockdata.is((Block) this)) { // Folia - block updates in unloaded chunks
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
RailShape blockpropertytrackposition1 = (RailShape) iblockdata.getValue(PoweredRailBlock.SHAPE);
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
|
2024-07-31 05:09:52 +02:00
|
|
|
index c4471342eea4f9e2b0916fc1c5f1b24bc07757fd..25b4764358f0a20418d268625609d05c4aa01037 100644
|
2023-04-18 04:51:21 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
|
2024-05-10 06:07:34 +02:00
|
|
|
@@ -199,8 +199,9 @@ public class RedStoneWireBlock extends Block {
|
2023-04-18 04:51:21 +02:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Direction enumdirection = (Direction) iterator.next();
|
|
|
|
RedstoneSide blockpropertyredstoneside = (RedstoneSide) state.getValue((Property) RedStoneWireBlock.PROPERTY_BY_DIRECTION.get(enumdirection));
|
|
|
|
+ BlockState currState; blockposition_mutableblockposition.setWithOffset(pos, enumdirection); // Folia - block updates in unloaded chunks
|
|
|
|
|
|
|
|
- if (blockpropertyredstoneside != RedstoneSide.NONE && !world.getBlockState(blockposition_mutableblockposition.setWithOffset(pos, enumdirection)).is((Block) this)) {
|
2024-07-31 05:09:52 +02:00
|
|
|
+ if (blockpropertyredstoneside != RedstoneSide.NONE && (currState = (world instanceof net.minecraft.server.level.ServerLevel serverLevel && !ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(serverLevel, pos) ? null : world.getBlockStateIfLoaded(blockposition_mutableblockposition))) != null && !currState.is((Block) this)) { // Folia - block updates in unloaded chunks
|
2023-04-18 04:51:21 +02:00
|
|
|
blockposition_mutableblockposition.move(Direction.DOWN);
|
|
|
|
BlockState iblockdata1 = world.getBlockState(blockposition_mutableblockposition);
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java b/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
|
2024-07-31 05:09:52 +02:00
|
|
|
index 2c9640001dba727981ad336eefade6d438eeb0ac..67bd721c4f9b22e07f9ab75ca019b4c9e9080a4c 100644
|
2023-04-18 04:51:21 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
|
|
|
|
@@ -119,7 +119,8 @@ public class CollectingNeighborUpdater implements NeighborUpdater {
|
|
|
|
@Override
|
|
|
|
public boolean runNext(Level world) {
|
|
|
|
BlockPos blockPos = this.sourcePos.relative(NeighborUpdater.UPDATE_ORDER[this.idx++]);
|
|
|
|
- BlockState blockState = world.getBlockState(blockPos);
|
2024-07-31 05:09:52 +02:00
|
|
|
+ BlockState blockState = !ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor((net.minecraft.server.level.ServerLevel)world, blockPos) ? null : world.getBlockStateIfLoaded(blockPos); // Folia - block updates in unloaded chunks
|
2023-04-18 04:51:21 +02:00
|
|
|
+ if (blockState != null) { // Folia - block updates in unloaded chunks
|
2024-01-21 05:33:21 +01:00
|
|
|
// Paper start - Call BlockPhysicsEvent
|
2023-04-18 04:51:21 +02:00
|
|
|
try {
|
2024-02-05 20:41:39 +01:00
|
|
|
org.bukkit.event.block.BlockPhysicsEvent event = new org.bukkit.event.block.BlockPhysicsEvent(
|
|
|
|
@@ -134,6 +135,7 @@ public class CollectingNeighborUpdater implements NeighborUpdater {
|
|
|
|
world.lastPhysicsProblem = blockPos;
|
2023-04-18 04:51:21 +02:00
|
|
|
}
|
2024-01-21 05:33:21 +01:00
|
|
|
// Paper end - Call BlockPhysicsEvent
|
2023-04-18 04:51:21 +02:00
|
|
|
+ } // Folia - block updates in unloaded chunks
|
|
|
|
if (this.idx < NeighborUpdater.UPDATE_ORDER.length && NeighborUpdater.UPDATE_ORDER[this.idx] == this.skipDirection) {
|
2024-05-10 01:36:04 +02:00
|
|
|
this.idx++;
|
2023-04-18 04:51:21 +02:00
|
|
|
}
|
2024-05-10 01:36:04 +02:00
|
|
|
@@ -150,7 +152,9 @@ public class CollectingNeighborUpdater implements NeighborUpdater {
|
|
|
|
implements CollectingNeighborUpdater.NeighborUpdates {
|
2023-04-18 04:51:21 +02:00
|
|
|
@Override
|
|
|
|
public boolean runNext(Level world) {
|
2024-07-31 05:09:52 +02:00
|
|
|
+ if (ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor((net.minecraft.server.level.ServerLevel)world, this.pos) && world.getChunkIfLoaded(this.pos) != null) { // Folia - block updates in unloaded chunks
|
2023-06-09 05:15:55 +02:00
|
|
|
NeighborUpdater.executeShapeUpdate(world, this.direction, this.state, this.pos, this.neighborPos, this.updateFlags, this.updateLimit);
|
2023-04-18 04:51:21 +02:00
|
|
|
+ } // Folia - block updates in unloaded chunks
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-05-10 01:36:04 +02:00
|
|
|
@@ -158,8 +162,8 @@ public class CollectingNeighborUpdater implements NeighborUpdater {
|
2023-04-18 04:51:21 +02:00
|
|
|
static record SimpleNeighborUpdate(BlockPos pos, Block block, BlockPos neighborPos) implements CollectingNeighborUpdater.NeighborUpdates {
|
|
|
|
@Override
|
|
|
|
public boolean runNext(Level world) {
|
|
|
|
- BlockState blockState = world.getBlockState(this.pos);
|
|
|
|
- NeighborUpdater.executeUpdate(world, blockState, this.pos, this.block, this.neighborPos, false);
|
2024-07-31 05:09:52 +02:00
|
|
|
+ BlockState blockState = !ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor((net.minecraft.server.level.ServerLevel)world, this.pos) ? null : world.getBlockStateIfLoaded(this.pos); // Folia - block updates in unloaded chunks
|
2023-04-18 04:51:21 +02:00
|
|
|
+ if (blockState != null) NeighborUpdater.executeUpdate(world, blockState, this.pos, this.block, this.neighborPos, false); // Folia - block updates in unloaded chunks
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|