9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 03:19:21 +00:00

PWT: fix chained updates

This commit is contained in:
Taiyou06
2025-06-07 00:13:40 +02:00
parent 6cd4ebd40d
commit 87db40b4b1

View File

@@ -41,6 +41,27 @@ index be820c6093dd2ae7642b9bee11edf65e3a8d7242..06ac3537f5655d048d770bb004243f20
boolean ret = false;
final boolean canProcessFullUpdates = processFullUpdates & isTickThread;
diff --git a/io/papermc/paper/redstone/RedstoneWireTurbo.java b/io/papermc/paper/redstone/RedstoneWireTurbo.java
index ff747a1ecdf3c888bca0d69de4f85dcd810b6139..62ecbbf7c167beaa3b67fc4c30e901c5d359d6b8 100644
--- a/io/papermc/paper/redstone/RedstoneWireTurbo.java
+++ b/io/papermc/paper/redstone/RedstoneWireTurbo.java
@@ -829,14 +829,8 @@ public final class RedstoneWireTurbo {
j = getMaxCurrentStrength(upd, j);
int l = 0;
- wire.shouldSignal = false;
- // Unfortunately, World.isBlockIndirectlyGettingPowered is complicated,
- // and I'm not ready to try to replicate even more functionality from
- // elsewhere in Minecraft into this accelerator. So sadly, we must
- // suffer the performance hit of this very expensive call. If there
- // is consistency to what this call returns, we may be able to cache it.
- final int k = worldIn.getBestNeighborSignal(upd.self);
- wire.shouldSignal = true;
+ // This now correctly calls the (conditionally) thread-safe method in RedStoneWireBlock
+ final int k = wire.getBlockSignal(worldIn, upd.self);
// The variable 'k' holds the maximum redstone power value of any adjacent blocks.
// If 'k' has the highest level of all neighbors, then the power level of this
diff --git a/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java b/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java
index 4a881636ba21fae9e50950bbba2b4321b71d35ab..9b01cc21a7e7411b8d112b5b7d7061e66c9bde06 100644
--- a/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java
@@ -1340,10 +1361,21 @@ index 904369f4d7db41026183f2de7c96c2f0f4dc204d..afd952ddc8942818ec01d1c750413776
return true;
} else {
diff --git a/net/minecraft/world/level/block/RedStoneWireBlock.java b/net/minecraft/world/level/block/RedStoneWireBlock.java
index 12c9d60314c99fb65e640d255a2d0c6b7790ad4d..33a096ca7d175a714f874901d0152d0ecbc7f2a5 100644
index 12c9d60314c99fb65e640d255a2d0c6b7790ad4d..5a60c5e4fe122d37a0aed1269128aa5e6e5e87b8 100644
--- a/net/minecraft/world/level/block/RedStoneWireBlock.java
+++ b/net/minecraft/world/level/block/RedStoneWireBlock.java
@@ -308,7 +308,12 @@ public class RedStoneWireBlock extends Block {
@@ -91,7 +91,10 @@ public class RedStoneWireBlock extends Block {
private static final float PARTICLE_DENSITY = 0.2F;
private final BlockState crossState;
private final RedstoneWireEvaluator evaluator = new DefaultRedstoneWireEvaluator(this);
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
public boolean shouldSignal = true;
+ private final ThreadLocal<Boolean> shouldSignalTL = ThreadLocal.withInitial(() -> true);
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
@Override
public MapCodec<RedStoneWireBlock> codec() {
@@ -308,7 +311,12 @@ public class RedStoneWireBlock extends Block {
if (orientation != null) {
source = pos.relative(orientation.getFront().getOpposite());
}
@@ -1357,7 +1389,7 @@ index 12c9d60314c99fb65e640d255a2d0c6b7790ad4d..33a096ca7d175a714f874901d0152d0e
return;
}
updatePowerStrength(worldIn, pos, state, orientation, blockAdded);
@@ -336,7 +341,12 @@ public class RedStoneWireBlock extends Block {
@@ -336,7 +344,12 @@ public class RedStoneWireBlock extends Block {
// [Space Walker] suppress shape updates and emit those manually to
// bypass the new neighbor update stack.
if (level.setBlock(pos, state, Block.UPDATE_KNOWN_SHAPE | Block.UPDATE_CLIENTS)) {
@@ -1371,6 +1403,82 @@ index 12c9d60314c99fb65e640d255a2d0c6b7790ad4d..33a096ca7d175a714f874901d0152d0e
}
}
}
@@ -353,10 +366,19 @@ public class RedStoneWireBlock extends Block {
}
public int getBlockSignal(Level level, BlockPos pos) {
- this.shouldSignal = false;
- int bestNeighborSignal = level.getBestNeighborSignal(pos);
- this.shouldSignal = true;
- return bestNeighborSignal;
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) {
+ this.shouldSignalTL.set(false);
+ int bestNeighborSignal = level.getBestNeighborSignal(pos);
+ this.shouldSignalTL.set(true);
+ return bestNeighborSignal;
+ } else {
+ this.shouldSignal = false;
+ int bestNeighborSignal = level.getBestNeighborSignal(pos);
+ this.shouldSignal = true;
+ return bestNeighborSignal;
+ }
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
private void checkCornerChangeAt(Level level, BlockPos pos) {
@@ -450,24 +472,34 @@ public class RedStoneWireBlock extends Block {
@Override
protected int getDirectSignal(BlockState blockState, BlockGetter blockAccess, BlockPos pos, Direction side) {
- return !this.shouldSignal ? 0 : blockState.getSignal(blockAccess, pos, side);
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ boolean signal = org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled ? this.shouldSignalTL.get() : this.shouldSignal;
+ return !signal ? 0 : blockState.getSignal(blockAccess, pos, side);
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
@Override
protected int getSignal(BlockState blockState, BlockGetter blockAccess, BlockPos pos, Direction side) {
- if (this.shouldSignal && side != Direction.DOWN) {
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ boolean signal;
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled)
+ signal = this.shouldSignalTL.get();
+ else
+ signal = this.shouldSignal;
+ if (signal && side != Direction.DOWN) {
int powerValue = blockState.getValue(POWER);
if (powerValue == 0) {
return 0;
} else {
return side != Direction.UP
- && !this.getConnectionState(blockAccess, blockState, pos).getValue(PROPERTY_BY_DIRECTION.get(side.getOpposite())).isConnected()
+ && !this.getConnectionState(blockAccess, blockState, pos).getValue(PROPERTY_BY_DIRECTION.get(side.getOpposite())).isConnected()
? 0
: powerValue;
}
} else {
return 0;
}
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
protected static boolean shouldConnectTo(BlockState state) {
@@ -487,7 +519,12 @@ public class RedStoneWireBlock extends Block {
@Override
protected boolean isSignalSource(BlockState state) {
- return this.shouldSignal;
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled)
+ return this.shouldSignalTL.get();
+ else
+ return this.shouldSignal;
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
public static int getColorForPower(int power) {
diff --git a/net/minecraft/world/level/block/SaplingBlock.java b/net/minecraft/world/level/block/SaplingBlock.java
index e014f052e9b0f5ca6b28044e2389782b7d0e0cb8..5485e27b881ab0e4d6d00c088bae094d1232eec7 100644
--- a/net/minecraft/world/level/block/SaplingBlock.java