From bc75b6185259a65f31f3ff9408751df3a6d4e246 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 30 Aug 2024 19:39:20 +0700 Subject: [PATCH] Fix CapabilityCache not calling "invalidated" listeners on first cache initialization --- .../dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 20a66630e..df53e1acf 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 @@ -331,6 +331,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc init { capabilityCaches.add(this) + waitForServerLevel { rebuildCache() } } override fun get(): T? { @@ -361,6 +362,10 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc // IllegalStateException("Do not call getCapability on an invalid cache or from the invalidation listener!") // what a shame. { onceServer { if (!isRemoved && creationVersion == currentVersion) listeners.accept(cache?.capability) } }) + + onceServer { + if (!isRemoved && creationVersion == currentVersion) listeners.accept(cache?.capability) + } } } @@ -376,7 +381,6 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc if (!level.isClientSide) { subscribe() waitForServerLevel.forEach { it.invoke() } - capabilityCaches.forEach { it.rebuildCache() } waitForServerLevel.clear() } else { waitForServerLevel.clear()