aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-01-12 14:53:29 +0100
committerLinnea Gräf <nea@nea.moe>2025-01-12 14:53:29 +0100
commitf828a6c9ec9d7219f58d11a5c260ae3897500f69 (patch)
tree2eeaf136220c146e43e98a5b10e4c50ef361fddd /src
parent4562d294bb19aace4479e68a425b092ba401242f (diff)
downloadFirmament-f828a6c9ec9d7219f58d11a5c260ae3897500f69.tar.gz
Firmament-f828a6c9ec9d7219f58d11a5c260ae3897500f69.tar.bz2
Firmament-f828a6c9ec9d7219f58d11a5c260ae3897500f69.zip
fix: Missing cache for custom item models causing lags
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/events/CustomItemModelEvent.kt13
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt1
-rw-r--r--src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java4
3 files changed, 12 insertions, 6 deletions
diff --git a/src/main/kotlin/events/CustomItemModelEvent.kt b/src/main/kotlin/events/CustomItemModelEvent.kt
index 11528fd..e7b6eb8 100644
--- a/src/main/kotlin/events/CustomItemModelEvent.kt
+++ b/src/main/kotlin/events/CustomItemModelEvent.kt
@@ -1,7 +1,10 @@
package moe.nea.firmament.events
+import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
import net.minecraft.item.ItemStack
import net.minecraft.util.Identifier
+import moe.nea.firmament.util.collections.WeakCache
// TODO: assert an order on these events
data class CustomItemModelEvent(
@@ -9,11 +12,17 @@ data class CustomItemModelEvent(
var overrideModel: Identifier? = null,
) : FirmamentEvent() {
companion object : FirmamentEventBus<CustomItemModelEvent>() {
+ val cache = WeakCache.memoize("ItemModelIdentifier", ::getModelIdentifier0)
+
@JvmStatic
fun getModelIdentifier(itemStack: ItemStack?): Identifier? {
- // TODO: Re-add memoization and add an error / warning if the model does not exist
if (itemStack == null) return null
- return publish(CustomItemModelEvent(itemStack)).overrideModel
+ return cache.invoke(itemStack).getOrNull()
+ }
+
+ fun getModelIdentifier0(itemStack: ItemStack): Optional<Identifier> {
+ // TODO: add an error / warning if the model does not exist
+ return Optional.ofNullable(publish(CustomItemModelEvent(itemStack)).overrideModel)
}
}
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
index d9ca5b4..0de9eb5 100644
--- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
@@ -44,6 +44,7 @@ object CustomSkyBlockTextures : FirmamentFeature {
val allItemCaches by lazy {
listOf(
skullTextureCache.cache,
+ CustomItemModelEvent.cache.cache,
CustomGlobalArmorOverrides.overrideCache.cache
)
}
diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java
index dfc87a0..a71ad92 100644
--- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java
+++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java
@@ -27,10 +27,6 @@ public class ReplaceItemModelPatch {
@Final
private Function<Identifier, ItemModel> modelGetter;
- @Inject(method = "<init>", at = @At("TAIL"))
- private void saveMissingModel(BakedModelManager bakedModelManager, CallbackInfo ci) {
- }
-
@Unique
private boolean hasModel(Identifier identifier) {
return !(modelGetter.apply(identifier) instanceof MissingItemModel);