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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ 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) {
|
||||
if (!localConfig.redstoneCache || this.isTrackingWireUpdates()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ignore any wire changes while updating the network.
|
||||
if (this.updatingNetwork != null) {
|
||||
return true;
|
||||
}
|
||||
@@ -56,16 +56,16 @@ public final class RedstoneWireCache {
|
||||
if (network != null) {
|
||||
try {
|
||||
this.updatingNetwork = network;
|
||||
return network.applyFromCache(this.level, localConfig.redstoneImplementation);
|
||||
return network.applyFromCache(this.level);
|
||||
} finally {
|
||||
this.updatingNetwork = null;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Start tracking power and neighbor updates
|
||||
this.networkSource = networkSource;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void trackWirePower(BlockPos pos, int newPower, int oldPower) {
|
||||
if (this.isTrackingWireUpdates()) {
|
||||
@@ -103,17 +103,15 @@ 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
|
||||
);
|
||||
|
||||
if (redstoneNetwork.prepareAndRegister(this.level)) {
|
||||
if (redstoneNetwork.prepareAndRegisterListeners(this.level, this.networkSource)) {
|
||||
this.networkCache.put(this.networkSource, redstoneNetwork);
|
||||
}
|
||||
}
|
||||
|
||||
this.wireUpdates.clear();
|
||||
this.updates.clear();
|
||||
|
||||
Reference in New Issue
Block a user