diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt index b7a3bcc7b..75517e9c3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt @@ -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(0) + private val listeners = ArrayList>>(0) - fun addListener(listener: Runnable) { + fun addListener(listener: Consumer>) { listeners.add(listener) if (value.isPresent) - listener.run() + listener.accept(value) } override fun get(): LazyOptional { @@ -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