aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features/texturepack
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-06-14 15:02:09 +0200
committerLinnea Gräf <nea@nea.moe>2024-06-14 15:02:09 +0200
commitcd1826a49822e7be0fb583e7b540270560fb657d (patch)
tree7afe995a046934cd8d35dc08ae0be36d7587420c /src/main/kotlin/moe/nea/firmament/features/texturepack
parentdb2b96bd9801d1e9f0dc108520310f9add8df4b7 (diff)
downloadfirmament-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')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt18
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt27
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt4
3 files changed, 34 insertions, 15 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt
index c28c0c8..99e0683 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt
@@ -25,6 +25,8 @@ import moe.nea.firmament.events.subscription.SubscriptionOwner
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.features.texturepack.CustomGlobalTextures.logger
import moe.nea.firmament.util.IdentifierSerializer
+import moe.nea.firmament.util.IdentityCharacteristics
+import moe.nea.firmament.util.computeNullableFunction
import moe.nea.firmament.util.skyBlockId
object CustomGlobalArmorOverrides : SubscriptionOwner {
@@ -62,17 +64,21 @@ object CustomGlobalArmorOverrides : SubscriptionOwner {
override val delegateFeature: FirmamentFeature
get() = CustomSkyBlockTextures
+ val overrideCache = mutableMapOf<IdentityCharacteristics<ItemStack>, Any>()
+
@JvmStatic
fun overrideArmor(stack: ItemStack): List<ArmorMaterial.Layer>? {
if (!CustomSkyBlockTextures.TConfig.enableArmorOverrides) return null
- val id = stack.skyBlockId ?: return null
- val override = overrides[id.neuItem] ?: return null
- for (suboverride in override.overrides) {
- if (suboverride.predicate.test(stack)) {
- return suboverride.bakedLayers
+ return overrideCache.computeNullableFunction(IdentityCharacteristics(stack)) {
+ val id = stack.skyBlockId ?: return@computeNullableFunction null
+ val override = overrides[id.neuItem] ?: return@computeNullableFunction null
+ for (suboverride in override.overrides) {
+ if (suboverride.predicate.test(stack)) {
+ return@computeNullableFunction suboverride.bakedLayers
+ }
}
+ return@computeNullableFunction override.bakedLayers
}
- return override.bakedLayers
}
var overrides: Map<String, ArmorOverride> = mapOf()
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
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
index 63ebf89..82989e4 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt
@@ -9,6 +9,7 @@ package moe.nea.firmament.features.texturepack
import com.mojang.authlib.minecraft.MinecraftProfileTexture
import com.mojang.authlib.properties.Property
+import net.fabricmc.fabric.api.entity.event.v1.EntityElytraEvents.Custom
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
import net.minecraft.block.SkullBlock
import net.minecraft.client.MinecraftClient
@@ -44,8 +45,11 @@ object CustomSkyBlockTextures : FirmamentFeature {
@Subscribe
fun onTick(it: TickEvent) {
if (TConfig.cacheDuration < 1 || it.tickCount % TConfig.cacheDuration == 0) {
+ // TODO: unify all of those caches somehow
CustomItemModelEvent.clearCache()
skullTextureCache.clear()
+ CustomGlobalTextures.overrideCache.clear()
+ CustomGlobalArmorOverrides.overrideCache.clear()
}
}