aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-01-21 13:17:01 +0100
committerLinnea Gräf <nea@nea.moe>2025-01-21 13:17:01 +0100
commit36cf26be6d783d56ecff22af753def8e6ee5aa62 (patch)
treea5f9046e8ab882bc01d2cbea9b974fa7aa233d2c /src/main/kotlin
parent2a3a4c07f5db951169adfc5626e8cf28c0812cf6 (diff)
downloadFirmament-36cf26be6d783d56ecff22af753def8e6ee5aa62.tar.gz
Firmament-36cf26be6d783d56ecff22af753def8e6ee5aa62.tar.bz2
Firmament-36cf26be6d783d56ecff22af753def8e6ee5aa62.zip
fix: Don't hide global overrides for textures with extra attributes idsHEADmaster
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/events/CustomItemModelEvent.kt21
-rw-r--r--src/main/kotlin/features/debug/PowerUserTools.kt7
-rw-r--r--src/main/kotlin/util/mc/IntrospectableItemModelManager.kt7
3 files changed, 29 insertions, 6 deletions
diff --git a/src/main/kotlin/events/CustomItemModelEvent.kt b/src/main/kotlin/events/CustomItemModelEvent.kt
index e7b6eb8..21ee326 100644
--- a/src/main/kotlin/events/CustomItemModelEvent.kt
+++ b/src/main/kotlin/events/CustomItemModelEvent.kt
@@ -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
}
}
diff --git a/src/main/kotlin/features/debug/PowerUserTools.kt b/src/main/kotlin/features/debug/PowerUserTools.kt
index 225bc13..ac7a6fb 100644
--- a/src/main/kotlin/features/debug/PowerUserTools.kt
+++ b/src/main/kotlin/features/debug/PowerUserTools.kt
@@ -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
diff --git a/src/main/kotlin/util/mc/IntrospectableItemModelManager.kt b/src/main/kotlin/util/mc/IntrospectableItemModelManager.kt
new file mode 100644
index 0000000..e546fd3
--- /dev/null
+++ b/src/main/kotlin/util/mc/IntrospectableItemModelManager.kt
@@ -0,0 +1,7 @@
+package moe.nea.firmament.util.mc
+
+import net.minecraft.util.Identifier
+
+interface IntrospectableItemModelManager {
+ fun hasModel_firmament(identifier: Identifier): Boolean
+}