Make exopack smelter not start new job when no power is present, and make exopack power changes notify smelters
This commit is contained in:
parent
5800ddc9ad
commit
2ac990c82d
@ -431,6 +431,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
|
||||
private val cache = RecipeManager.createCheck(RecipeType.SMELTING)
|
||||
|
||||
override fun computeNextJob(): JobContainer<MachineItemJob> {
|
||||
if (!exoPackEnergy.batteryLevel.isPositive) return JobContainer.noEnergy()
|
||||
val level = ply.level() as? ServerLevel ?: return JobContainer.failure()
|
||||
val recipe = cache.getRecipeFor(input, level)
|
||||
|
||||
@ -470,7 +471,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
|
||||
/**
|
||||
* [IMatteryEnergyStorage] instance, representing Exopack battery charge
|
||||
*/
|
||||
val exoPackEnergy = ProfiledEnergyStorage(BatteryBackedEnergyStorage(ply, synchronizer, Decimal.ZERO, ExopackConfig.ENERGY_CAPACITY, false))
|
||||
val exoPackEnergy = ProfiledEnergyStorage(BatteryBackedEnergyStorage(ply, synchronizer, Decimal.ZERO, ExopackConfig.ENERGY_CAPACITY, false, onChange = { for (v in smelters) v.notify(MachineJobEventLoop.IdleReason.POWER) }))
|
||||
|
||||
val exoPackChargeSlots = MatteryContainer(4)
|
||||
|
||||
|
@ -25,7 +25,8 @@ class BatteryBackedEnergyStorage(
|
||||
synchronizer: FieldSynchronizer,
|
||||
initialCharge: Decimal,
|
||||
maxCharge: Decimal,
|
||||
val isAndroid: Boolean
|
||||
val isAndroid: Boolean,
|
||||
val onChange: Runnable? = null
|
||||
) : IMatteryEnergyStorage, INBTSerializable<CompoundTag?>, ContainerSingleItem {
|
||||
override val energyFlow: FlowDirection
|
||||
get() = FlowDirection.INPUT
|
||||
@ -41,6 +42,8 @@ class BatteryBackedEnergyStorage(
|
||||
} else if (ply is ServerPlayer && !isAndroid) {
|
||||
ExopackBatterySlotTrigger.trigger(ply, value)
|
||||
}
|
||||
|
||||
onChange?.run()
|
||||
})
|
||||
|
||||
override fun getItem(slot: Int): ItemStack {
|
||||
@ -105,6 +108,7 @@ class BatteryBackedEnergyStorage(
|
||||
ply.awardStat(StatNames.POWER_CONSUMED, drained.toInt() * 10)
|
||||
}
|
||||
|
||||
onChange?.run()
|
||||
return drained
|
||||
}
|
||||
}
|
||||
@ -119,6 +123,8 @@ class BatteryBackedEnergyStorage(
|
||||
if (ply is ServerPlayer && isAndroid) {
|
||||
ply.awardStat(StatNames.POWER_CONSUMED, drained.toInt() * 10)
|
||||
}
|
||||
|
||||
onChange?.run()
|
||||
}
|
||||
|
||||
return drained
|
||||
@ -137,6 +143,7 @@ class BatteryBackedEnergyStorage(
|
||||
}
|
||||
|
||||
if (howMuch.isZero) {
|
||||
onChange?.run()
|
||||
return received
|
||||
}
|
||||
}
|
||||
@ -146,6 +153,7 @@ class BatteryBackedEnergyStorage(
|
||||
|
||||
if (!simulate) {
|
||||
battery = new
|
||||
onChange?.run()
|
||||
}
|
||||
|
||||
return received
|
||||
@ -167,6 +175,7 @@ class BatteryBackedEnergyStorage(
|
||||
}
|
||||
set(value) {
|
||||
battery = value
|
||||
onChange?.run()
|
||||
}
|
||||
|
||||
override var maxBatteryLevel: Decimal
|
||||
@ -185,5 +194,6 @@ class BatteryBackedEnergyStorage(
|
||||
}
|
||||
set(value) {
|
||||
maxBattery = value
|
||||
onChange?.run()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user