Reduced block updates when a controller is turning on and off constantly. Fixes part of #3468

This commit is contained in:
raoulvdberge
2023-03-30 16:53:29 +02:00
parent ba2eda5c68
commit fbf2d6760b
2 changed files with 12 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Fixed
- Fixed not being able to search with JEI when the Grid is open.
- Reduced block updates when a controller is turning on and off constantly.
## [v1.11.5] - 2023-02-12

View File

@@ -56,6 +56,7 @@ import java.util.function.Predicate;
public class Network implements INetwork, IRedstoneConfigurable {
private static final int THROTTLE_INACTIVE_TO_ACTIVE = 20;
private static final int THROTTLE_ACTIVE_TO_INACTIVE = 4;
private static final int THROTTLE_ENERGY_TYPE_CHANGE = 20;
private static final String NBT_ENERGY = "Energy";
private static final String NBT_ITEM_STORAGE_TRACKER_ID = "ItemStorageTrackerId";
@@ -89,6 +90,7 @@ public class Network implements INetwork, IRedstoneConfigurable {
private boolean throttlingDisabled = true; // Will be enabled after first update
private boolean couldRun;
private int ticksSinceUpdateChanged;
private int ticksSinceEnergyTypeChanged;
private int ticks;
private long[] tickTimes = new long[100];
private int tickCounter = 0;
@@ -213,13 +215,17 @@ public class Network implements INetwork, IRedstoneConfigurable {
ControllerBlock.EnergyType energyType = getEnergyType();
if (lastEnergyType != energyType) {
++ticksSinceEnergyTypeChanged;
if (ticksSinceEnergyTypeChanged > THROTTLE_ENERGY_TYPE_CHANGE) {
lastEnergyType = energyType;
BlockState state = level.getBlockState(pos);
if (state.getBlock() instanceof ControllerBlock) {
level.setBlockAndUpdate(pos, state.setValue(ControllerBlock.ENERGY_TYPE, energyType));
}
}
} else {
ticksSinceEnergyTypeChanged = 0;
}
tickTimes[tickCounter % tickTimes.length] = Util.getNanos() - tickStart;
tickCounter++;