Add built in LazyOptional to EnergyStorageImpl
This commit is contained in:
parent
f12ccc84e2
commit
6e02402f06
@ -41,7 +41,6 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
}
|
||||
|
||||
private var valid = true
|
||||
private var resolver = LazyOptional.of {energy}
|
||||
|
||||
@JvmField
|
||||
val energy = GeneratorEnergyStorage(this::setChangedLight, MAX_ENERGY, THROUGHPUT)
|
||||
@ -53,7 +52,7 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
if (valid && (cap === MatteryCapability.ENERGY || cap === CapabilityEnergy.ENERGY) && side !== blockState.getValue(BlockMatteryRotatable.FACING))
|
||||
return resolver.cast()
|
||||
return energy.resolver.cast()
|
||||
|
||||
if (valid && cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
return itemHandler.get().cast()
|
||||
@ -64,15 +63,15 @@ class BlockEntityChemicalGenerator(pos: BlockPos, state: BlockState) : BlockEnti
|
||||
override fun invalidateCaps() {
|
||||
super.invalidateCaps()
|
||||
itemHandler.invalidate()
|
||||
energy.invalidate()
|
||||
valid = false
|
||||
resolver.invalidate()
|
||||
}
|
||||
|
||||
override fun reviveCaps() {
|
||||
super.reviveCaps()
|
||||
itemHandler.revive()
|
||||
energy.revive()
|
||||
valid = true
|
||||
resolver = LazyOptional.of {energy}
|
||||
}
|
||||
|
||||
override fun setLevel(level: Level) {
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.capability
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
import net.minecraftforge.common.util.INBTSerializable
|
||||
import net.minecraftforge.common.util.LazyOptional
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.ifHas
|
||||
import ru.dbotthepony.mc.otm.set
|
||||
@ -86,6 +87,17 @@ sealed class EnergyStorageImpl constructor(
|
||||
// nbt.ifHas("max_output") { maxOutput = deserializeNBT(it) }
|
||||
}
|
||||
|
||||
var resolver: LazyOptional<IMatteryEnergyStorage> = LazyOptional.of { this }
|
||||
private set
|
||||
|
||||
fun invalidate() {
|
||||
resolver.invalidate()
|
||||
}
|
||||
|
||||
fun revive() {
|
||||
resolver = LazyOptional.of { this }
|
||||
}
|
||||
|
||||
companion object {
|
||||
val DEFAULT_MAX_IO = ImpreciseFraction(200)
|
||||
val DEFAULT_MAX_CAPACITY = ImpreciseFraction(60_000)
|
||||
|
Loading…
Reference in New Issue
Block a user