From cd1826a49822e7be0fb583e7b540270560fb657d Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 14 Jun 2024 15:02:09 +0200 Subject: Fix global textures not working in hotbar --- .../features/texturepack/CustomGlobalTextures.kt | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt') 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, Any>() + @JvmStatic fun replaceGlobalModel( models: ItemModels, stack: ItemStack, cir: CallbackInfoReturnable ) { - 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 } -- cgit