fix: Don't hide global overrides for textures with extra attributes ids

This commit is contained in:
Linnea Gräf
2025-01-21 13:17:01 +01:00
parent 2a3a4c07f5
commit 36cf26be6d
8 changed files with 79 additions and 23 deletions

View File

@@ -5,28 +5,39 @@ import kotlin.jvm.optionals.getOrNull
import net.minecraft.item.ItemStack
import net.minecraft.util.Identifier
import moe.nea.firmament.util.collections.WeakCache
import moe.nea.firmament.util.mc.IntrospectableItemModelManager
// TODO: assert an order on these events
data class CustomItemModelEvent(
val itemStack: ItemStack,
val itemModelManager: IntrospectableItemModelManager,
var overrideModel: Identifier? = null,
) : FirmamentEvent() {
companion object : FirmamentEventBus<CustomItemModelEvent>() {
val cache = WeakCache.memoize("ItemModelIdentifier", ::getModelIdentifier0)
@JvmStatic
fun getModelIdentifier(itemStack: ItemStack?): Identifier? {
fun getModelIdentifier(itemStack: ItemStack?, itemModelManager: IntrospectableItemModelManager): Identifier? {
if (itemStack == null) return null
return cache.invoke(itemStack).getOrNull()
return cache.invoke(itemStack, itemModelManager).getOrNull()
}
fun getModelIdentifier0(itemStack: ItemStack): Optional<Identifier> {
fun getModelIdentifier0(
itemStack: ItemStack,
itemModelManager: IntrospectableItemModelManager
): Optional<Identifier> {
// TODO: add an error / warning if the model does not exist
return Optional.ofNullable(publish(CustomItemModelEvent(itemStack)).overrideModel)
return Optional.ofNullable(publish(CustomItemModelEvent(itemStack, itemModelManager)).overrideModel)
}
}
fun overrideIfExists(overrideModel: Identifier) {
this.overrideModel = overrideModel
if (itemModelManager.hasModel_firmament(overrideModel))
this.overrideModel = overrideModel
}
fun overrideIfEmpty(identifier: Identifier) {
if (overrideModel == null)
overrideModel = identifier
}
}

View File

@@ -30,6 +30,7 @@ import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
import moe.nea.firmament.util.ClipboardUtils
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.focusedItemStack
import moe.nea.firmament.util.mc.IntrospectableItemModelManager
import moe.nea.firmament.util.mc.SNbtFormatter.Companion.toPrettyString
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
import moe.nea.firmament.util.mc.loreAccordingToNbt
@@ -119,7 +120,11 @@ object PowerUserTools : FirmamentFeature {
lastCopiedStack =
Pair(item, Text.stringifiedTranslatable("firmament.tooltip.copied.skyblockid", sbId.neuItem))
} else if (it.matches(TConfig.copyTexturePackId)) {
val model = CustomItemModelEvent.getModelIdentifier(item) // TODO: remove global texture overrides, maybe
val model = CustomItemModelEvent.getModelIdentifier0(item, object : IntrospectableItemModelManager {
override fun hasModel_firmament(identifier: Identifier): Boolean {
return true
}
}).getOrNull() // TODO: remove global texture overrides, maybe
if (model == null) {
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.modelid.fail"))
return

View File

@@ -0,0 +1,7 @@
package moe.nea.firmament.util.mc
import net.minecraft.util.Identifier
interface IntrospectableItemModelManager {
fun hasModel_firmament(identifier: Identifier): Boolean
}