9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-19 14:59:30 +00:00

Move skipWireUpdate redstone implementation check

This commit is contained in:
Samsuik
2025-03-06 18:17:31 +00:00
parent 6c49e8527f
commit 072ee3b51f
2 changed files with 35 additions and 36 deletions

View File

@@ -78,8 +78,9 @@ public final class RedstoneNetwork {
}
}
public boolean prepareAndRegister(Level level) {
public boolean prepareAndRegisterListeners(Level level, RedstoneNetworkSource networkSource) {
Object2ObjectLinkedOpenHashMap<BlockPos, RedstoneWireUpdate> processedWires = new Object2ObjectLinkedOpenHashMap<>();
boolean skipWireUpdates = networkSource.redstoneImplementation() != WorldConfiguration.Misc.RedstoneImplementation.VANILLA;
for (RedstoneWireUpdate wireUpdate : this.wireUpdates.reversed()) {
BlockPos wirePos = wireUpdate.getPosition();
//noinspection ConstantValue
@@ -89,7 +90,7 @@ public final class RedstoneNetwork {
if (state.is(Blocks.PISTON_HEAD)) {
return false;
}
} else if (this.originalWirePower.get(wirePos).firstPower() != wireUpdate.getPower()) {
} else if (skipWireUpdates && this.originalWirePower.get(wirePos).firstPower() != wireUpdate.getPower()) {
// Filter out wires updates that are not the first and last update
// This significantly reduces the amount of updates when unpowering
wireUpdate.skipWireUpdate();
@@ -156,7 +157,7 @@ public final class RedstoneNetwork {
}
}
public boolean applyFromCache(Level level, WorldConfiguration.Misc.RedstoneImplementation redstoneImplementation) {
public boolean applyFromCache(Level level) {
this.expiry.refresh(level.getGameTime());
if (!this.isRegistered() || !this.verifyWiresInNetwork(level)) {
return false;
@@ -167,7 +168,7 @@ public final class RedstoneNetwork {
int updateFrom = 0;
for (RedstoneWireUpdate wireUpdate : this.wireUpdates) {
if (wireUpdate.canSkipWireUpdate() && redstoneImplementation != WorldConfiguration.Misc.RedstoneImplementation.VANILLA) {
if (wireUpdate.canSkipWireUpdate()) {
updateFrom = wireUpdate.getUpdateIndex();
continue;
}

View File

@@ -41,30 +41,30 @@ public final class RedstoneWireCache {
}
public boolean tryApplyFromCache(BlockPos pos, @Nullable Orientation orientation, int newPower, int oldPower) {
if (!this.isTrackingWireUpdates()) {
LocalValueConfig localConfig = this.level.localConfig().config(pos);
if (!localConfig.redstoneCache) {
return false;
}
if (this.updatingNetwork != null) {
return true;
}
RedstoneNetworkSource networkSource = RedstoneNetworkSource.createNetworkSource(this.level, localConfig, pos, orientation, newPower, oldPower);
RedstoneNetwork network = this.networkCache.get(networkSource);
if (network != null) {
try {
this.updatingNetwork = network;
return network.applyFromCache(this.level, localConfig.redstoneImplementation);
} finally {
this.updatingNetwork = null;
}
}
this.networkSource = networkSource;
LocalValueConfig localConfig = this.level.localConfig().config(pos);
if (!localConfig.redstoneCache || this.isTrackingWireUpdates()) {
return false;
}
// Ignore any wire changes while updating the network.
if (this.updatingNetwork != null) {
return true;
}
RedstoneNetworkSource networkSource = RedstoneNetworkSource.createNetworkSource(this.level, localConfig, pos, orientation, newPower, oldPower);
RedstoneNetwork network = this.networkCache.get(networkSource);
if (network != null) {
try {
this.updatingNetwork = network;
return network.applyFromCache(this.level);
} finally {
this.updatingNetwork = null;
}
} else {
// Start tracking power and neighbor updates
this.networkSource = networkSource;
return false;
}
return false;
}
public void trackWirePower(BlockPos pos, int newPower, int oldPower) {
@@ -103,16 +103,14 @@ public final class RedstoneWireCache {
return;
}
if (!this.wireUpdates.isEmpty()) {
// Cache expires if it has not been used in 600 ticks
TickExpiry expiration = new TickExpiry(this.level.getGameTime(), 600);
RedstoneNetwork redstoneNetwork = new RedstoneNetwork(
this.wireUpdates, this.updates, this.originalWirePower, expiration
);
// Cache expires if it has not been used in 600 ticks
TickExpiry expiration = new TickExpiry(this.level.getGameTime(), 600);
RedstoneNetwork redstoneNetwork = new RedstoneNetwork(
this.wireUpdates, this.updates, this.originalWirePower, expiration
);
if (redstoneNetwork.prepareAndRegister(this.level)) {
this.networkCache.put(this.networkSource, redstoneNetwork);
}
if (redstoneNetwork.prepareAndRegisterListeners(this.level, this.networkSource)) {
this.networkCache.put(this.networkSource, redstoneNetwork);
}
this.wireUpdates.clear();