Fix crash related to tracking mekanism energy
This commit is contained in:
parent
e8d7f0225c
commit
d2c2fbd3d2
@ -64,6 +64,7 @@ import ru.dbotthepony.mc.otm.once
|
||||
import ru.dbotthepony.mc.otm.onceServer
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
import java.util.stream.Stream
|
||||
import kotlin.NoSuchElementException
|
||||
@ -220,17 +221,17 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
|
||||
if (value.isPresent)
|
||||
for (tracker in listeners)
|
||||
tracker.run()
|
||||
tracker.accept(value)
|
||||
}
|
||||
}
|
||||
|
||||
private val listeners = ArrayList<Runnable>(0)
|
||||
private val listeners = ArrayList<Consumer<LazyOptional<T>>>(0)
|
||||
|
||||
fun addListener(listener: Runnable) {
|
||||
fun addListener(listener: Consumer<LazyOptional<T>>) {
|
||||
listeners.add(listener)
|
||||
|
||||
if (value.isPresent)
|
||||
listener.run()
|
||||
listener.accept(value)
|
||||
}
|
||||
|
||||
override fun get(): LazyOptional<T> {
|
||||
@ -266,7 +267,12 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
|
||||
mekanism.addListener {
|
||||
actualMekanism?.invalidate()
|
||||
actualMekanism = LazyOptional.of { Mekanism2MatteryEnergyWrapper(mekanism.value.orElseThrow { NoSuchElementException() }) }
|
||||
|
||||
if (it.isPresent) {
|
||||
actualMekanism = LazyOptional.of { Mekanism2MatteryEnergyWrapper(it.orElseThrow { NoSuchElementException("No mekanism energy was present, and tracker did not call back in time") }) }
|
||||
} else {
|
||||
actualMekanism = null
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mekanism = null
|
||||
|
Loading…
Reference in New Issue
Block a user