diff --git a/src/net/bdew/gendustry/machines/apiary/TileApiary.scala b/src/net/bdew/gendustry/machines/apiary/TileApiary.scala index 9cf68a9..b7a6e39 100644 --- a/src/net/bdew/gendustry/machines/apiary/TileApiary.scala +++ b/src/net/bdew/gendustry/machines/apiary/TileApiary.scala @@ -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) + } } } diff --git a/src/net/bdew/gendustry/misc/DataSlotErrorStates.scala b/src/net/bdew/gendustry/misc/DataSlotErrorStates.scala index 152d923..fec632c 100644 --- a/src/net/bdew/gendustry/misc/DataSlotErrorStates.scala +++ b/src/net/bdew/gendustry/misc/DataSlotErrorStates.scala @@ -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._