Update redstone optimization and lag compensation patches

This commit is contained in:
Nassim Jahnke
2024-12-17 12:12:59 +01:00
parent ac69f75d23
commit d37b5601d2
4 changed files with 237 additions and 250 deletions

View File

@@ -20,12 +20,12 @@ Alternate Current needs the following modifications:
* RedStoneWireBlock: Replace calls to vanilla's or Eigencraft's methods for handling power changes with calls to
Alternate Current's wire handler.
diff --git a/src/main/java/alternate/current/wire/LevelHelper.java b/src/main/java/alternate/current/wire/LevelHelper.java
diff --git a/alternate/current/wire/LevelHelper.java b/alternate/current/wire/LevelHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..eda108e2df9bf7d1ddd89287b8d2c2d7f1637c96
--- /dev/null
+++ b/src/main/java/alternate/current/wire/LevelHelper.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/LevelHelper.java
@@ -0,0 +1,66 @@
+package alternate.current.wire;
+
+import org.bukkit.craftbukkit.block.CraftBlock;
@@ -92,12 +92,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return true;
+ }
+}
diff --git a/src/main/java/alternate/current/wire/Node.java b/src/main/java/alternate/current/wire/Node.java
diff --git a/alternate/current/wire/Node.java b/alternate/current/wire/Node.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..8af6c69098e64945361d116b5fd6ac21e97fcd8d
--- /dev/null
+++ b/src/main/java/alternate/current/wire/Node.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/Node.java
@@ -0,0 +1,113 @@
+package alternate.current.wire;
+
+import java.util.Arrays;
@@ -211,12 +211,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ throw new UnsupportedOperationException("Not a WireNode!");
+ }
+}
diff --git a/src/main/java/alternate/current/wire/PriorityQueue.java b/src/main/java/alternate/current/wire/PriorityQueue.java
diff --git a/alternate/current/wire/PriorityQueue.java b/alternate/current/wire/PriorityQueue.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..d71b4d0e4c44a2620b41b89475412db53bea20ed
--- /dev/null
+++ b/src/main/java/alternate/current/wire/PriorityQueue.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/PriorityQueue.java
@@ -0,0 +1,211 @@
+package alternate.current.wire;
+
+import java.util.AbstractQueue;
@@ -428,12 +428,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return prev;
+ }
+}
diff --git a/src/main/java/alternate/current/wire/SimpleQueue.java b/src/main/java/alternate/current/wire/SimpleQueue.java
diff --git a/alternate/current/wire/SimpleQueue.java b/alternate/current/wire/SimpleQueue.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..2b30074252551e1dc55d5be17d26fb4a2d8eb2e4
--- /dev/null
+++ b/src/main/java/alternate/current/wire/SimpleQueue.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/SimpleQueue.java
@@ -0,0 +1,112 @@
+package alternate.current.wire;
+
+import java.util.AbstractQueue;
@@ -546,12 +546,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ }
+}
diff --git a/src/main/java/alternate/current/wire/UpdateOrder.java b/src/main/java/alternate/current/wire/UpdateOrder.java
diff --git a/alternate/current/wire/UpdateOrder.java b/alternate/current/wire/UpdateOrder.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..29338efd16cf62bb49e81cce09fbafd9b4319e7c
--- /dev/null
+++ b/src/main/java/alternate/current/wire/UpdateOrder.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/UpdateOrder.java
@@ -0,0 +1,390 @@
+package alternate.current.wire;
+
+import java.util.Locale;
@@ -942,12 +942,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public abstract void forEachNeighbor(NodeProvider nodes, Node source, int forward, Consumer<Node> action);
+
+}
diff --git a/src/main/java/alternate/current/wire/WireConnection.java b/src/main/java/alternate/current/wire/WireConnection.java
diff --git a/alternate/current/wire/WireConnection.java b/alternate/current/wire/WireConnection.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..4fd8cb29024330397cfe4cbc1f237d285bfb7b3e
--- /dev/null
+++ b/src/main/java/alternate/current/wire/WireConnection.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/WireConnection.java
@@ -0,0 +1,30 @@
+package alternate.current.wire;
+
+/**
@@ -978,12 +978,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ this.accept = accept;
+ }
+}
diff --git a/src/main/java/alternate/current/wire/WireConnectionManager.java b/src/main/java/alternate/current/wire/WireConnectionManager.java
diff --git a/alternate/current/wire/WireConnectionManager.java b/alternate/current/wire/WireConnectionManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..f03b313e58385d626490a9e64c9616fd08aa951e
--- /dev/null
+++ b/src/main/java/alternate/current/wire/WireConnectionManager.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/WireConnectionManager.java
@@ -0,0 +1,134 @@
+package alternate.current.wire;
+
+import java.util.Arrays;
@@ -1118,12 +1118,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ }
+}
diff --git a/src/main/java/alternate/current/wire/WireHandler.java b/src/main/java/alternate/current/wire/WireHandler.java
diff --git a/alternate/current/wire/WireHandler.java b/alternate/current/wire/WireHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..259b301b2c8b64cb7974a235afb260e0e991af54
--- /dev/null
+++ b/src/main/java/alternate/current/wire/WireHandler.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/WireHandler.java
@@ -0,0 +1,1073 @@
+package alternate.current.wire;
+
+import java.util.Iterator;
@@ -2197,12 +2197,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ }
+}
diff --git a/src/main/java/alternate/current/wire/WireNode.java b/src/main/java/alternate/current/wire/WireNode.java
diff --git a/alternate/current/wire/WireNode.java b/alternate/current/wire/WireNode.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
index 0000000000000000000000000000000000000000..298076a0db4e6ee6e4775ac43bf749d9f5689bdb
--- /dev/null
+++ b/src/main/java/alternate/current/wire/WireNode.java
@@ -0,0 +0,0 @@
+++ b/alternate/current/wire/WireNode.java
@@ -0,0 +1,122 @@
+package alternate.current.wire;
+
+import net.minecraft.core.BlockPos;
@@ -2325,11 +2325,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return LevelHelper.setWireState(level, pos, state, added);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index efc18884358907661d1226409f11d19a394073b3..9cc47bda7197ca3f63b0ede9905c9a13931f84ed 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -214,6 +214,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
public final UUID uuid;
public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
public boolean hasEntityMoveEvent; // Paper - Add EntityMoveEvent
@@ -2337,7 +2337,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public LevelChunk getChunkIfLoaded(int x, int z) {
return this.chunkSource.getChunkAtIfLoadedImmediately(x, z); // Paper - Use getChunkIfLoadedImmediately
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -2213,6 +2214,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
return this.chunkSource.getGenerator().getSeaLevel();
}
@@ -2348,14 +2348,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ // Paper end - optimize redstone (Alternate Current)
+
private final class EntityCallbacks implements LevelCallback<Entity> {
EntityCallbacks() {}
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
final class EntityCallbacks implements LevelCallback<Entity> {
@Override
public void onCreated(Entity entity) {
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index 872c3b8826f436b15f6ab0a3619692c5202eadc3..cb6ca60af3d3f90501e4693a78466b9f7462362d 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -1401,6 +1401,17 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
public abstract FuelValues fuelValues();
@@ -2371,74 +2371,75 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end - optimize redstone (Alternate Current)
+
public static enum ExplosionInteraction implements StringRepresentable {
NONE("none"), BLOCK("block"), MOB("mob"), TNT("tnt"), TRIGGER("trigger"), STANDARD("standard"); // CraftBukkit - Add STANDARD which will always use Explosion.Effect.DESTROY
diff --git a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
@@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block {
return floor.isFaceSturdy(world, pos, Direction.UP) || floor.is(Blocks.HOPPER);
NONE("none"),
BLOCK("block"),
diff --git a/net/minecraft/world/level/block/RedStoneWireBlock.java b/net/minecraft/world/level/block/RedStoneWireBlock.java
index f02232ce97779db0d12a5d5da1d767326d78ea4c..12c9d60314c99fb65e640d255a2d0c6b7790ad4d 100644
--- a/net/minecraft/world/level/block/RedStoneWireBlock.java
+++ b/net/minecraft/world/level/block/RedStoneWireBlock.java
@@ -290,7 +290,7 @@ public class RedStoneWireBlock extends Block {
return state.isFaceSturdy(level, pos, Direction.UP) || state.is(Blocks.HOPPER);
}
- // Paper start - Optimize redstone
+ // Paper start - Optimize redstone (Eigencraft)
// The bulk of the new functionality is found in RedstoneWireTurbo.java
com.destroystokyo.paper.util.RedstoneWireTurbo turbo = new com.destroystokyo.paper.util.RedstoneWireTurbo(this);
io.papermc.paper.redstone.RedstoneWireTurbo turbo = new io.papermc.paper.redstone.RedstoneWireTurbo(this);
@@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block {
@@ -372,7 +372,13 @@ 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.updateSurroundingRedstone(world, pos, state, null, true); // Paper - Optimize redstone
protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) {
if (!oldState.is(state.getBlock()) && !level.isClientSide) {
- this.updateSurroundingRedstone(level, pos, state, null, true); // Paper - Optimize redstone
+ // Paper start - optimize redstone - replace call to updatePowerStrength
+ if (world.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ world.getWireHandler().onWireAdded(pos, state); // Alternate Current
+ if (level.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ level.getWireHandler().onWireAdded(pos, state); // Alternate Current
+ } else {
+ this.updateSurroundingRedstone(world, pos, state, null, true); // Vanilla/Eigencraft
+ this.updateSurroundingRedstone(level, pos, state, null, true); // Vanilla/Eigencraft
+ }
+ // Paper end
+ // Paper end - optimize redstone
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(direction), this);
level.updateNeighborsAt(pos.relative(direction), this);
@@ -391,7 +397,13 @@ public class RedStoneWireBlock extends Block {
level.updateNeighborsAt(pos.relative(direction), this);
}
- this.updateSurroundingRedstone(world, pos, state, null, false); // Paper - Optimize redstone
- this.updateSurroundingRedstone(level, pos, state, null, false); // Paper - Optimize redstone
+ // Paper start - optimize redstone - replace call to updatePowerStrength
+ if (world.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ world.getWireHandler().onWireRemoved(pos, state); // Alternate Current
+ if (level.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ level.getWireHandler().onWireRemoved(pos, state); // Alternate Current
+ } else {
+ this.updateSurroundingRedstone(world, pos, state, null, false); // Vanilla/Eigencraft
+ this.updateSurroundingRedstone(level, pos, state, null, false); // Vanilla/Eigencraft
+ }
this.updateNeighborsOfNeighboringWires(world, pos);
+ // Paper end - optimize redstone
this.updateNeighborsOfNeighboringWires(level, pos);
}
}
@@ -0,0 +0,0 @@ public class RedStoneWireBlock extends Block {
@@ -415,9 +427,15 @@ public class RedStoneWireBlock extends Block {
@Override
protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, @Nullable Orientation wireOrientation, boolean notify) {
if (!world.isClientSide) {
protected void neighborChanged(BlockState state, Level level, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston) {
if (!level.isClientSide) {
+ // Paper start - optimize redstone (Alternate Current)
+ // Alternate Current handles breaking of redstone wires in the WireHandler.
+ if (world.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ world.getWireHandler().onWireUpdated(pos, state, wireOrientation);
+ if (level.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ level.getWireHandler().onWireUpdated(pos, state, orientation);
+ } else
+ // Paper end - optimize redstone (Alternate Current)
if (sourceBlock != this || !useExperimentalEvaluator(world)) {
if (state.canSurvive(world, pos)) {
- this.updateSurroundingRedstone(world, pos, state, wireOrientation, false); // Paper - Optimize redstone
+ this.updateSurroundingRedstone(world, pos, state, wireOrientation, false); // Paper - Optimize redstone (Eigencraft)
+ // Paper end - optimize redstone (Alternate Current)
if (neighborBlock != this || !useExperimentalEvaluator(level)) {
if (state.canSurvive(level, pos)) {
- this.updateSurroundingRedstone(level, pos, state, orientation, false); // Paper - Optimize redstone
+ this.updateSurroundingRedstone(level, pos, state, orientation, false); // Paper - Optimize redstone (Eigencraft)
} else {
dropResources(state, world, pos);
world.removeBlock(pos, false);
diff --git a/src/main/java/net/minecraft/world/level/redstone/ExperimentalRedstoneUtils.java b/src/main/java/net/minecraft/world/level/redstone/ExperimentalRedstoneUtils.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/redstone/ExperimentalRedstoneUtils.java
+++ b/src/main/java/net/minecraft/world/level/redstone/ExperimentalRedstoneUtils.java
@@ -0,0 +0,0 @@ public class ExperimentalRedstoneUtils {
if (up != null) {
orientation = orientation.withFront(up);
dropResources(state, level, pos);
level.removeBlock(pos, false);
diff --git a/net/minecraft/world/level/redstone/ExperimentalRedstoneUtils.java b/net/minecraft/world/level/redstone/ExperimentalRedstoneUtils.java
index 83f5da3e24834882193b9d7e3a788517e4b12b55..db7a7b091d2eb0f5b7efbe0db2b91709dee688e8 100644
--- a/net/minecraft/world/level/redstone/ExperimentalRedstoneUtils.java
+++ b/net/minecraft/world/level/redstone/ExperimentalRedstoneUtils.java
@@ -17,6 +17,11 @@ public class ExperimentalRedstoneUtils {
if (front != null) {
orientation = orientation.withFront(front);
}
+ // Paper start - Optimize redstone (Alternate Current) - use default front instead of random
+ else if (world.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {