aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events/CustomItemModelEvent.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/events/CustomItemModelEvent.kt')
-rw-r--r--src/main/kotlin/events/CustomItemModelEvent.kt31
1 files changed, 8 insertions, 23 deletions
diff --git a/src/main/kotlin/events/CustomItemModelEvent.kt b/src/main/kotlin/events/CustomItemModelEvent.kt
index 4328d77..7abdaf7 100644
--- a/src/main/kotlin/events/CustomItemModelEvent.kt
+++ b/src/main/kotlin/events/CustomItemModelEvent.kt
@@ -1,38 +1,23 @@
package moe.nea.firmament.events
-import java.util.Optional
-import kotlin.jvm.optionals.getOrNull
-import net.minecraft.client.render.item.ItemModels
-import net.minecraft.client.render.model.BakedModel
-import net.minecraft.client.util.ModelIdentifier
import net.minecraft.item.ItemStack
-import moe.nea.firmament.util.ErrorUtil
-import moe.nea.firmament.util.collections.WeakCache
+import net.minecraft.util.Identifier
+// TODO: assert an order on these events
data class CustomItemModelEvent(
val itemStack: ItemStack,
- var overrideModel: ModelIdentifier? = null,
+ var overrideModel: Identifier? = null,
) : FirmamentEvent() {
companion object : FirmamentEventBus<CustomItemModelEvent>() {
- val cache =
- WeakCache.memoize<ItemStack, ItemModels, Optional<BakedModel>>("CustomItemModels") { stack, models ->
- val modelId = getModelIdentifier(stack) ?: return@memoize Optional.empty()
- ErrorUtil.softCheck("Model Id needs to have an inventory variant", modelId.variant() == "inventory")
- val bakedModel = models.getModel(modelId.id)
- if (bakedModel == null || bakedModel === models.missingModelSupplier.get()) return@memoize Optional.empty()
- Optional.of(bakedModel)
- }
-
@JvmStatic
- fun getModelIdentifier(itemStack: ItemStack?): ModelIdentifier? {
+ fun getModelIdentifier(itemStack: ItemStack?): Identifier? {
+ // TODO: Re-add memoization and add an error / warning if the model does not exist
if (itemStack == null) return null
return publish(CustomItemModelEvent(itemStack)).overrideModel
}
+ }
- @JvmStatic
- fun getModel(itemStack: ItemStack?, thing: ItemModels): BakedModel? {
- if (itemStack == null) return null
- return cache.invoke(itemStack, thing).getOrNull()
- }
+ fun overrideIfExists(overrideModel: Identifier) {
+ TODO()
}
}