From d399542266bd12f270064755b972c0f3dad05df2 Mon Sep 17 00:00:00 2001 From: Space Walker <48224626+SpaceWalkerRS@users.noreply.github.com> Date: Sun, 10 Nov 2024 00:52:51 +0100 Subject: [PATCH] Update Eigencraft patch to 1.21.3 (#11553) --- .../Eigencraft-redstone-implementation.patch | 176 +++++++----------- 1 file changed, 64 insertions(+), 112 deletions(-) rename patches/{unapplied => }/server/Eigencraft-redstone-implementation.patch (89%) diff --git a/patches/unapplied/server/Eigencraft-redstone-implementation.patch b/patches/server/Eigencraft-redstone-implementation.patch similarity index 89% rename from patches/unapplied/server/Eigencraft-redstone-implementation.patch rename to patches/server/Eigencraft-redstone-implementation.patch index c70360deb8..87c9d93cc3 100644 --- a/patches/unapplied/server/Eigencraft-redstone-implementation.patch +++ b/patches/server/Eigencraft-redstone-implementation.patch @@ -467,7 +467,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // UpdateNode object. + BlockState newState; + if (old_current_change) { -+ newState = wire.calculateCurrentChanges(worldIn, pos, pos, oldState); ++ newState = wire.calculateCurrentChanges(worldIn, pos, oldState); + } else { + // Looking up block state is slow. This accelerator includes a version of + // calculateCurrentChanges that uses cahed wire values for a @@ -692,7 +692,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // call BlockStateBase#neighborChanged directly. This change mostly + // restores old behavior, at the cost of bypassing the + // max-chained-neighbor-updates server property. -+ worldIn.getBlockState(upd.self).handleNeighborChanged(worldIn, upd.self, wire, upd.parent, false); ++ // The Orientation parameter is (for now) only used by redstone wire ++ // while these updates are dispatched to non-wires only, so we can ++ // pass null. ++ worldIn.getBlockState(upd.self).handleNeighborChanged(worldIn, upd.self, wire, null, false); + } + } + @@ -793,7 +796,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Check this block's neighbors and see if its power level needs to change + // Use the calculateCurrentChanges method in BlockRedstoneWire since we have no + // cached block states at this point. -+ final BlockState newState = wire.calculateCurrentChanges(worldIn, pos, pos, state); ++ final BlockState newState = wire.calculateCurrentChanges(worldIn, pos, state); + + // If no change, exit + if (newState == state) { @@ -972,7 +975,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + BlockPos neighborPos = pos.relative(dir); + BlockState neighborState = level.getBlockState(neighborPos); + -+ BlockState newState = neighborState.updateShape(dir.getOpposite(), state, level, neighborPos, pos); ++ BlockState newState = neighborState.updateShape(level, level, neighborPos, dir.getOpposite(), pos, state, level.getRandom()); + Block.updateOrDestroy(neighborState, newState, level, neighborPos, Block.UPDATE_CLIENTS); + } + } @@ -1004,142 +1007,91 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * this.neighborChanged and a few other methods in this class. + * Note: Added 'source' argument so as to help determine direction of information flow + */ -+ private void updateSurroundingRedstone(Level worldIn, BlockPos pos, BlockState state, BlockPos source) { ++ private void updateSurroundingRedstone(Level worldIn, BlockPos pos, BlockState state, @Nullable Orientation orientation, boolean blockAdded) { + if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.EIGENCRAFT) { ++ // since 24w33a the source pos is no longer given, but instead an Orientation parameter ++ // when this is not null, it can be used to find the source pos, which the turbo uses ++ // to find the direction of information flow ++ BlockPos source = null; ++ if (orientation != null) { ++ source = pos.relative(orientation.getFront().getOpposite()); ++ } + turbo.updateSurroundingRedstone(worldIn, pos, state, source); + return; + } -+ updatePowerStrength(worldIn, pos, state); ++ updatePowerStrength(worldIn, pos, state, orientation, blockAdded); + } + + /* -+ * Slightly modified method to compute redstone wire power levels from neighboring blocks. -+ * Modifications cut the number of power level changes by about 45% from vanilla, and this -+ * optimization synergizes well with the breadth-first search implemented in -+ * RedstoneWireTurbo. -+ * Note: RedstoneWireTurbo contains a faster version of this code. -+ * Note: Made this public so that RedstoneWireTurbo can access it. ++ * This method computes a wire's target strength and updates the given block state. ++ * It uses the DefaultRedstoneWireEvaluator for this, which is identical to code ++ * that was present in this class prior to the introduction of the experimental redstone ++ * changes in 24w33a. ++ * The previous implementation of this method in this patch had optimizations that have ++ * not been relevant since 1.13, thus it has been greatly simplified. + */ -+ public BlockState calculateCurrentChanges(Level worldIn, BlockPos pos1, BlockPos pos2, BlockState state) { -+ BlockState iblockstate = state; -+ int i = state.getValue(POWER); -+ int j = 0; -+ j = this.getPower(j, worldIn.getBlockState(pos2)); -+ this.shouldSignal = false; -+ int k = worldIn.getBestNeighborSignal(pos1); -+ this.shouldSignal = true; ++ public BlockState calculateCurrentChanges(Level level, BlockPos pos, BlockState state) { ++ int oldPower = state.getValue(POWER); ++ int newPower = ((DefaultRedstoneWireEvaluator) evaluator).calculateTargetStrength(level, pos); ++ if (oldPower != newPower) { ++ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), oldPower, newPower); ++ level.getCraftServer().getPluginManager().callEvent(event); + -+ if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA) { -+ // This code is totally redundant to if statements just below the loop. -+ if (k > 0 && k > j - 1) { -+ j = k; -+ } -+ } ++ newPower = event.getNewCurrent(); + -+ int l = 0; -+ -+ // 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 -+ // redstone wire will be set to 'k'. If 'k' is already 15, then nothing inside the -+ // following loop can affect the power level of the wire. Therefore, the loop is -+ // skipped if k is already 15. -+ if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA || k < 15) { -+ for (Direction enumfacing : Direction.Plane.HORIZONTAL) { -+ BlockPos blockpos = pos1.relative(enumfacing); -+ boolean flag = blockpos.getX() != pos2.getX() || blockpos.getZ() != pos2.getZ(); -+ -+ if (flag) { -+ l = this.getPower(l, worldIn.getBlockState(blockpos)); -+ } -+ -+ if (worldIn.getBlockState(blockpos).isRedstoneConductor(worldIn, blockpos) && !worldIn.getBlockState(pos1.above()).isRedstoneConductor(worldIn, pos1)) { -+ if (flag && pos1.getY() >= pos2.getY()) { -+ l = this.getPower(l, worldIn.getBlockState(blockpos.above())); -+ } -+ } else if (!worldIn.getBlockState(blockpos).isRedstoneConductor(worldIn, blockpos) && flag && pos1.getY() <= pos2.getY()) { -+ l = this.getPower(l, worldIn.getBlockState(blockpos.below())); -+ } -+ } -+ } -+ -+ if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA) { -+ // The old code would decrement the wire value only by 1 at a time. -+ if (l > j) { -+ j = l - 1; -+ } else if (j > 0) { -+ --j; -+ } else { -+ j = 0; -+ } -+ -+ if (k > j - 1) { -+ j = k; -+ } -+ } else { -+ // The new code sets this RedstoneWire block's power level to the highest neighbor -+ // minus 1. This usually results in wire power levels dropping by 2 at a time. -+ // This optimization alone has no impact on update order, only the number of updates. -+ j = l - 1; -+ -+ // If 'l' turns out to be zero, then j will be set to -1, but then since 'k' will -+ // always be in the range of 0 to 15, the following if will correct that. -+ if (k > j) j = k; -+ } -+ -+ if (i != j) { -+ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(worldIn, pos1), i, j); -+ worldIn.getCraftServer().getPluginManager().callEvent(event); -+ -+ j = event.getNewCurrent(); -+ state = state.setValue(POWER, j); -+ -+ if (worldIn.getBlockState(pos1) == iblockstate) { ++ if (level.getBlockState(pos) == state) { ++ state = state.setValue(POWER, newPower); + // [Space Walker] suppress shape updates and emit those manually to + // bypass the new neighbor update stack. -+ if (worldIn.setBlock(pos1, state, Block.UPDATE_KNOWN_SHAPE | Block.UPDATE_CLIENTS)) -+ turbo.updateNeighborShapes(worldIn, pos1, state); ++ if (level.setBlock(pos, state, Block.UPDATE_KNOWN_SHAPE | Block.UPDATE_CLIENTS)) { ++ turbo.updateNeighborShapes(level, pos, state); ++ } + } + } -+ + return state; + } + // Paper end + - private void updatePowerStrength(Level world, BlockPos pos, BlockState state) { - int i = this.calculateTargetStrength(world, pos); - -@@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block { - return Math.max(i, j - 1); - } - -+ private int getPower(int min, BlockState iblockdata) { return Math.max(min, getWireSignal(iblockdata)); } // Paper - Optimize redstone - private int getWireSignal(BlockState state) { - return state.is((Block) this) ? (Integer) state.getValue(RedStoneWireBlock.POWER) : 0; - } + private void updatePowerStrength(Level world, BlockPos pos, BlockState state, @Nullable Orientation orientation, boolean blockAdded) { + if (useExperimentalEvaluator(world)) { + new ExperimentalRedstoneWireEvaluator(this).updatePowerStrength(world, pos, state, orientation, blockAdded); @@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block { @Override protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) { if (!oldState.is(state.getBlock()) && !world.isClientSide) { -- this.updatePowerStrength(world, pos, state); -+ this.updateSurroundingRedstone(world, pos, state, null); // Paper - Optimize redstone - Iterator iterator = Direction.Plane.VERTICAL.iterator(); +- this.updatePowerStrength(world, pos, state, null, true); ++ this.updateSurroundingRedstone(world, pos, state, null, true); // Paper - Optimize redstone - while (iterator.hasNext()) { + for (Direction direction : Direction.Plane.VERTICAL) { + world.updateNeighborsAt(pos.relative(direction), this); @@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block { - world.updateNeighborsAt(pos.relative(enumdirection), this); + world.updateNeighborsAt(pos.relative(direction), this); } -- this.updatePowerStrength(world, pos, state); -+ this.updateSurroundingRedstone(world, pos, state, null); // Paper - Optimize redstone +- this.updatePowerStrength(world, pos, state, null, false); ++ this.updateSurroundingRedstone(world, pos, state, null, false); // Paper - Optimize redstone this.updateNeighborsOfNeighboringWires(world, pos); } } @@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block { - protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { if (!world.isClientSide) { - if (state.canSurvive(world, pos)) { -- this.updatePowerStrength(world, pos, state); -+ this.updateSurroundingRedstone(world, pos, state, sourcePos); // Paper - Optimize redstone - } else { - dropResources(state, world, pos); - world.removeBlock(pos, false); + if (sourceBlock != this || !useExperimentalEvaluator(world)) { + if (state.canSurvive(world, pos)) { +- this.updatePowerStrength(world, pos, state, wireOrientation, false); ++ this.updateSurroundingRedstone(world, pos, state, wireOrientation, false); // Paper - Optimize redstone + } else { + dropResources(state, world, pos); + world.removeBlock(pos, false); +diff --git a/src/main/java/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java b/src/main/java/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java ++++ b/src/main/java/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java +@@ -0,0 +0,0 @@ public class DefaultRedstoneWireEvaluator extends RedstoneWireEvaluator { + + } + +- private int calculateTargetStrength(Level world, BlockPos pos) { ++ public int calculateTargetStrength(Level world, BlockPos pos) { // Paper - Optimize redstone + int i = this.getBlockSignal(world, pos); + + return i == 15 ? i : Math.max(i, this.getIncomingWireSignal(world, pos));