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<>();
|
Object2ObjectLinkedOpenHashMap<BlockPos, RedstoneWireUpdate> processedWires = new Object2ObjectLinkedOpenHashMap<>();
|
||||||
|
boolean skipWireUpdates = networkSource.redstoneImplementation() != WorldConfiguration.Misc.RedstoneImplementation.VANILLA;
|
||||||
for (RedstoneWireUpdate wireUpdate : this.wireUpdates.reversed()) {
|
for (RedstoneWireUpdate wireUpdate : this.wireUpdates.reversed()) {
|
||||||
BlockPos wirePos = wireUpdate.getPosition();
|
BlockPos wirePos = wireUpdate.getPosition();
|
||||||
//noinspection ConstantValue
|
//noinspection ConstantValue
|
||||||
@@ -89,7 +90,7 @@ public final class RedstoneNetwork {
|
|||||||
if (state.is(Blocks.PISTON_HEAD)) {
|
if (state.is(Blocks.PISTON_HEAD)) {
|
||||||
return false;
|
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
|
// Filter out wires updates that are not the first and last update
|
||||||
// This significantly reduces the amount of updates when unpowering
|
// This significantly reduces the amount of updates when unpowering
|
||||||
wireUpdate.skipWireUpdate();
|
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());
|
this.expiry.refresh(level.getGameTime());
|
||||||
if (!this.isRegistered() || !this.verifyWiresInNetwork(level)) {
|
if (!this.isRegistered() || !this.verifyWiresInNetwork(level)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -167,7 +168,7 @@ public final class RedstoneNetwork {
|
|||||||
int updateFrom = 0;
|
int updateFrom = 0;
|
||||||
|
|
||||||
for (RedstoneWireUpdate wireUpdate : this.wireUpdates) {
|
for (RedstoneWireUpdate wireUpdate : this.wireUpdates) {
|
||||||
if (wireUpdate.canSkipWireUpdate() && redstoneImplementation != WorldConfiguration.Misc.RedstoneImplementation.VANILLA) {
|
if (wireUpdate.canSkipWireUpdate()) {
|
||||||
updateFrom = wireUpdate.getUpdateIndex();
|
updateFrom = wireUpdate.getUpdateIndex();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ public final class RedstoneWireCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean tryApplyFromCache(BlockPos pos, @Nullable Orientation orientation, int newPower, int oldPower) {
|
public boolean tryApplyFromCache(BlockPos pos, @Nullable Orientation orientation, int newPower, int oldPower) {
|
||||||
if (!this.isTrackingWireUpdates()) {
|
|
||||||
LocalValueConfig localConfig = this.level.localConfig().config(pos);
|
LocalValueConfig localConfig = this.level.localConfig().config(pos);
|
||||||
if (!localConfig.redstoneCache) {
|
if (!localConfig.redstoneCache || this.isTrackingWireUpdates()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore any wire changes while updating the network.
|
||||||
if (this.updatingNetwork != null) {
|
if (this.updatingNetwork != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -56,16 +56,16 @@ public final class RedstoneWireCache {
|
|||||||
if (network != null) {
|
if (network != null) {
|
||||||
try {
|
try {
|
||||||
this.updatingNetwork = network;
|
this.updatingNetwork = network;
|
||||||
return network.applyFromCache(this.level, localConfig.redstoneImplementation);
|
return network.applyFromCache(this.level);
|
||||||
} finally {
|
} finally {
|
||||||
this.updatingNetwork = null;
|
this.updatingNetwork = null;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
// Start tracking power and neighbor updates
|
||||||
this.networkSource = networkSource;
|
this.networkSource = networkSource;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void trackWirePower(BlockPos pos, int newPower, int oldPower) {
|
public void trackWirePower(BlockPos pos, int newPower, int oldPower) {
|
||||||
if (this.isTrackingWireUpdates()) {
|
if (this.isTrackingWireUpdates()) {
|
||||||
@@ -103,17 +103,15 @@ public final class RedstoneWireCache {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.wireUpdates.isEmpty()) {
|
|
||||||
// Cache expires if it has not been used in 600 ticks
|
// Cache expires if it has not been used in 600 ticks
|
||||||
TickExpiry expiration = new TickExpiry(this.level.getGameTime(), 600);
|
TickExpiry expiration = new TickExpiry(this.level.getGameTime(), 600);
|
||||||
RedstoneNetwork redstoneNetwork = new RedstoneNetwork(
|
RedstoneNetwork redstoneNetwork = new RedstoneNetwork(
|
||||||
this.wireUpdates, this.updates, this.originalWirePower, expiration
|
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.networkCache.put(this.networkSource, redstoneNetwork);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.wireUpdates.clear();
|
this.wireUpdates.clear();
|
||||||
this.updates.clear();
|
this.updates.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user