Update Eigencraft patch to 1.21.3 (#11553)

This commit is contained in:
Space Walker 2024-11-10 00:52:51 +01:00
parent 16f8d0f984
commit d399542266

View File

@ -467,7 +467,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // UpdateNode object. + // UpdateNode object.
+ BlockState newState; + BlockState newState;
+ if (old_current_change) { + if (old_current_change) {
+ newState = wire.calculateCurrentChanges(worldIn, pos, pos, oldState); + newState = wire.calculateCurrentChanges(worldIn, pos, oldState);
+ } else { + } else {
+ // Looking up block state is slow. This accelerator includes a version of + // Looking up block state is slow. This accelerator includes a version of
+ // calculateCurrentChanges that uses cahed wire values for a + // calculateCurrentChanges that uses cahed wire values for a
@ -692,7 +692,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // call BlockStateBase#neighborChanged directly. This change mostly + // call BlockStateBase#neighborChanged directly. This change mostly
+ // restores old behavior, at the cost of bypassing the + // restores old behavior, at the cost of bypassing the
+ // max-chained-neighbor-updates server property. + // 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 + // Check this block's neighbors and see if its power level needs to change
+ // Use the calculateCurrentChanges method in BlockRedstoneWire since we have no + // Use the calculateCurrentChanges method in BlockRedstoneWire since we have no
+ // cached block states at this point. + // 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 no change, exit
+ if (newState == state) { + if (newState == state) {
@ -972,7 +975,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ BlockPos neighborPos = pos.relative(dir); + BlockPos neighborPos = pos.relative(dir);
+ BlockState neighborState = level.getBlockState(neighborPos); + 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); + 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. + * this.neighborChanged and a few other methods in this class.
+ * Note: Added 'source' argument so as to help determine direction of information flow + * 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) { + 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); + turbo.updateSurroundingRedstone(worldIn, pos, state, source);
+ return; + return;
+ } + }
+ updatePowerStrength(worldIn, pos, state); + updatePowerStrength(worldIn, pos, state, orientation, blockAdded);
+ } + }
+ +
+ /* + /*
+ * Slightly modified method to compute redstone wire power levels from neighboring blocks. + * This method computes a wire's target strength and updates the given block state.
+ * Modifications cut the number of power level changes by about 45% from vanilla, and this + * It uses the DefaultRedstoneWireEvaluator for this, which is identical to code
+ * optimization synergizes well with the breadth-first search implemented in + * that was present in this class prior to the introduction of the experimental redstone
+ * RedstoneWireTurbo. + * changes in 24w33a.
+ * Note: RedstoneWireTurbo contains a faster version of this code. + * The previous implementation of this method in this patch had optimizations that have
+ * Note: Made this public so that RedstoneWireTurbo can access it. + * not been relevant since 1.13, thus it has been greatly simplified.
+ */ + */
+ public BlockState calculateCurrentChanges(Level worldIn, BlockPos pos1, BlockPos pos2, BlockState state) { + public BlockState calculateCurrentChanges(Level level, BlockPos pos, BlockState state) {
+ BlockState iblockstate = state; + int oldPower = state.getValue(POWER);
+ int i = state.getValue(POWER); + int newPower = ((DefaultRedstoneWireEvaluator) evaluator).calculateTargetStrength(level, pos);
+ int j = 0; + if (oldPower != newPower) {
+ j = this.getPower(j, worldIn.getBlockState(pos2)); + org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), oldPower, newPower);
+ this.shouldSignal = false; + level.getCraftServer().getPluginManager().callEvent(event);
+ int k = worldIn.getBestNeighborSignal(pos1);
+ this.shouldSignal = true;
+ +
+ if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA) { + newPower = event.getNewCurrent();
+ // This code is totally redundant to if statements just below the loop.
+ if (k > 0 && k > j - 1) {
+ j = k;
+ }
+ }
+ +
+ int l = 0; + if (level.getBlockState(pos) == state) {
+ + state = state.setValue(POWER, newPower);
+ // 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) {
+ // [Space Walker] suppress shape updates and emit those manually to + // [Space Walker] suppress shape updates and emit those manually to
+ // bypass the new neighbor update stack. + // bypass the new neighbor update stack.
+ if (worldIn.setBlock(pos1, state, Block.UPDATE_KNOWN_SHAPE | Block.UPDATE_CLIENTS)) + if (level.setBlock(pos, state, Block.UPDATE_KNOWN_SHAPE | Block.UPDATE_CLIENTS)) {
+ turbo.updateNeighborShapes(worldIn, pos1, state); + turbo.updateNeighborShapes(level, pos, state);
+ }
+ } + }
+ } + }
+
+ return state; + return state;
+ } + }
+ // Paper end + // Paper end
+ +
private void updatePowerStrength(Level world, BlockPos pos, BlockState state) { private void updatePowerStrength(Level world, BlockPos pos, BlockState state, @Nullable Orientation orientation, boolean blockAdded) {
int i = this.calculateTargetStrength(world, pos); if (useExperimentalEvaluator(world)) {
new ExperimentalRedstoneWireEvaluator(this).updatePowerStrength(world, pos, state, orientation, blockAdded);
@@ -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;
}
@@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block { @@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block {
@Override @Override
protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) { protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
if (!oldState.is(state.getBlock()) && !world.isClientSide) { if (!oldState.is(state.getBlock()) && !world.isClientSide) {
- this.updatePowerStrength(world, pos, state); - this.updatePowerStrength(world, pos, state, null, true);
+ this.updateSurroundingRedstone(world, pos, state, null); // Paper - Optimize redstone + this.updateSurroundingRedstone(world, pos, state, null, true); // Paper - Optimize redstone
Iterator iterator = Direction.Plane.VERTICAL.iterator();
while (iterator.hasNext()) { for (Direction direction : Direction.Plane.VERTICAL) {
world.updateNeighborsAt(pos.relative(direction), this);
@@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block { @@ -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.updatePowerStrength(world, pos, state, null, false);
+ this.updateSurroundingRedstone(world, pos, state, null); // Paper - Optimize redstone + this.updateSurroundingRedstone(world, pos, state, null, false); // Paper - Optimize redstone
this.updateNeighborsOfNeighboringWires(world, pos); this.updateNeighborsOfNeighboringWires(world, pos);
} }
} }
@@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block { @@ -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 (!world.isClientSide) {
if (state.canSurvive(world, pos)) { if (sourceBlock != this || !useExperimentalEvaluator(world)) {
- this.updatePowerStrength(world, pos, state); if (state.canSurvive(world, pos)) {
+ this.updateSurroundingRedstone(world, pos, state, sourcePos); // Paper - Optimize redstone - this.updatePowerStrength(world, pos, state, wireOrientation, false);
} else { + this.updateSurroundingRedstone(world, pos, state, wireOrientation, false); // Paper - Optimize redstone
dropResources(state, world, pos); } else {
world.removeBlock(pos, false); 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));