Fix CapabilityCache not calling "invalidated" listeners on first cache initialization

This commit is contained in:
DBotThePony 2024-08-30 19:39:20 +07:00
parent 83baf5a8a0
commit bc75b61852
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -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()