diff options
author | Linnea Gräf <nea@nea.moe> | 2024-06-14 15:02:09 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-06-14 15:02:09 +0200 |
commit | cd1826a49822e7be0fb583e7b540270560fb657d (patch) | |
tree | 7afe995a046934cd8d35dc08ae0be36d7587420c /src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt | |
parent | db2b96bd9801d1e9f0dc108520310f9add8df4b7 (diff) | |
download | Firmament-cd1826a49822e7be0fb583e7b540270560fb657d.tar.gz Firmament-cd1826a49822e7be0fb583e7b540270560fb657d.tar.bz2 Firmament-cd1826a49822e7be0fb583e7b540270560fb657d.zip |
Fix global textures not working in hotbar
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt index c2a003a..147697b 100644 --- a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt +++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt @@ -21,6 +21,7 @@ import net.minecraft.client.util.ModelIdentifier import net.minecraft.item.ItemStack import net.minecraft.resource.ResourceManager import net.minecraft.resource.SinglePreparationResourceReloader +import net.minecraft.text.Text import net.minecraft.util.Identifier import net.minecraft.util.profiler.Profiler import moe.nea.firmament.Firmament @@ -32,7 +33,9 @@ import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.subscription.SubscriptionOwner import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.util.IdentifierSerializer +import moe.nea.firmament.util.IdentityCharacteristics import moe.nea.firmament.util.MC +import moe.nea.firmament.util.computeNullableFunction import moe.nea.firmament.util.json.SingletonSerializableList import moe.nea.firmament.util.runNull @@ -137,26 +140,32 @@ object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalText @Subscribe fun onOpenGui(event: ScreenChangeEvent) { - val newTitle = event.new?.title - matchingOverrides = - if (newTitle == null) setOf() - else guiClassOverrides.classes.filterTo(mutableSetOf()) { it.screenFilter.title.matches(newTitle) } + val newTitle = event.new?.title ?: Text.empty() + matchingOverrides = guiClassOverrides.classes + .filterTo(mutableSetOf()) { it.screenFilter.title.matches(newTitle) } } + val overrideCache = mutableMapOf<IdentityCharacteristics<ItemStack>, Any>() + @JvmStatic fun replaceGlobalModel( models: ItemModels, stack: ItemStack, cir: CallbackInfoReturnable<BakedModel> ) { - for (guiClassOverride in matchingOverrides) { - for (override in guiClassOverride.overrides) { - if (override.predicate.test(stack)) { - cir.returnValue = models.modelManager.getModel(ModelIdentifier(override.model, "inventory")) - return + val value = overrideCache.computeNullableFunction(IdentityCharacteristics(stack)) { + for (guiClassOverride in matchingOverrides) { + for (override in guiClassOverride.overrides) { + if (override.predicate.test(stack)) { + return@computeNullableFunction models.modelManager.getModel( + ModelIdentifier(override.model, "inventory")) + } } } + null } + if (value != null) + cir.returnValue = value } |