mirror of
https://github.com/GTNewHorizons/gendustry.git
synced 2026-11-22 05:02:26 +00:00
Fixed apiary chunk update spam due to errorstate changes (#107)
This commit is contained in:
1 parent
fd92e83b47
commit
55706e90e2
2 files changed
+31
-15
No files matched your search
@@ -118,18 +118,18 @@ with IIndustrialApiary {
|
||||
|
||||
movePrincess = false
|
||||
|
||||
val canWork = logic.canWork()
|
||||
|
||||
val powered = getWorldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)
|
||||
setErrorCondition((rsmode :== RSMode.RS_OFF) && powered, ForestryErrorStates.disabledRedstone)
|
||||
setErrorCondition((rsmode :== RSMode.RS_ON) && !powered, ForestryErrorStates.noRedstone)
|
||||
setErrorCondition(rsmode :== RSMode.NEVER, GendustryErrorStates.Disabled)
|
||||
setErrorCondition(power.stored < cfg.baseMjPerTick * mods.energy, ForestryErrorStates.noPower)
|
||||
|
||||
if (errorConditions.isOk && canWork) {
|
||||
logic.doWork()
|
||||
if (errorConditions.isOk && (logic.getQueen != null || logic.getBreedingTime > 0)) {
|
||||
power.extract(cfg.baseMjPerTick * mods.energy, false)
|
||||
errorConditions.withSuspendedUpdates {
|
||||
val canWork = logic.canWork
|
||||
val powered = getWorldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)
|
||||
setErrorCondition((rsmode :== RSMode.RS_OFF) && powered, ForestryErrorStates.disabledRedstone)
|
||||
setErrorCondition((rsmode :== RSMode.RS_ON) && !powered, ForestryErrorStates.noRedstone)
|
||||
setErrorCondition(rsmode :== RSMode.NEVER, GendustryErrorStates.Disabled)
|
||||
setErrorCondition(power.stored < cfg.baseMjPerTick * mods.energy, ForestryErrorStates.noPower)
|
||||
if (errorConditions.isOk && canWork) {
|
||||
logic.doWork()
|
||||
if (errorConditions.isOk && (logic.getQueen != null || logic.getBreedingTime > 0)) {
|
||||
power.extract(cfg.baseMjPerTick * mods.energy, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,22 +13,29 @@ import forestry.api.core.{ErrorStateRegistry, IErrorState}
|
||||
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
import scala.util.DynamicVariable
|
||||
|
||||
case class DataSlotErrorStates(name: String, parent: DataSlotContainer) extends DataSlotVal[Set[IErrorState]] {
|
||||
override var value: Set[IErrorState] = Set.empty
|
||||
|
||||
val suspendUpdates = new DynamicVariable(false)
|
||||
|
||||
def set(v: IErrorState): Unit = {
|
||||
value += v
|
||||
parent.dataSlotChanged(this)
|
||||
if (!suspendUpdates.value)
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
|
||||
def clear(v: IErrorState): Unit = {
|
||||
value -= v
|
||||
parent.dataSlotChanged(this)
|
||||
if (!suspendUpdates.value)
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
|
||||
def clearAll(): Unit = {
|
||||
value = Set.empty
|
||||
parent.dataSlotChanged(this)
|
||||
if (!suspendUpdates.value)
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
|
||||
def toggle(v: IErrorState, on: Boolean): Unit = {
|
||||
@@ -38,6 +45,15 @@ case class DataSlotErrorStates(name: String, parent: DataSlotContainer) extends
|
||||
clear(v)
|
||||
}
|
||||
|
||||
def withSuspendedUpdates(f: => Unit) = {
|
||||
val oldValue = value
|
||||
suspendUpdates.withValue(true) {
|
||||
f
|
||||
}
|
||||
if (value != oldValue)
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
|
||||
def isOk = value.isEmpty
|
||||
|
||||
import net.bdew.lib.nbt._
|
||||
|
||||
Reference in new issue
Block a user