fix: Missing cache for custom item models causing lags
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
package moe.nea.firmament.events
|
package moe.nea.firmament.events
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
|
import kotlin.jvm.optionals.getOrNull
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
|
import moe.nea.firmament.util.collections.WeakCache
|
||||||
|
|
||||||
// TODO: assert an order on these events
|
// TODO: assert an order on these events
|
||||||
data class CustomItemModelEvent(
|
data class CustomItemModelEvent(
|
||||||
@@ -9,11 +12,17 @@ data class CustomItemModelEvent(
|
|||||||
var overrideModel: Identifier? = null,
|
var overrideModel: Identifier? = null,
|
||||||
) : FirmamentEvent() {
|
) : FirmamentEvent() {
|
||||||
companion object : FirmamentEventBus<CustomItemModelEvent>() {
|
companion object : FirmamentEventBus<CustomItemModelEvent>() {
|
||||||
|
val cache = WeakCache.memoize("ItemModelIdentifier", ::getModelIdentifier0)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getModelIdentifier(itemStack: ItemStack?): Identifier? {
|
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
|
if (itemStack == null) return null
|
||||||
return publish(CustomItemModelEvent(itemStack)).overrideModel
|
return cache.invoke(itemStack).getOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getModelIdentifier0(itemStack: ItemStack): Optional<Identifier> {
|
||||||
|
// TODO: add an error / warning if the model does not exist
|
||||||
|
return Optional.ofNullable(publish(CustomItemModelEvent(itemStack)).overrideModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ object CustomSkyBlockTextures : FirmamentFeature {
|
|||||||
val allItemCaches by lazy {
|
val allItemCaches by lazy {
|
||||||
listOf(
|
listOf(
|
||||||
skullTextureCache.cache,
|
skullTextureCache.cache,
|
||||||
|
CustomItemModelEvent.cache.cache,
|
||||||
CustomGlobalArmorOverrides.overrideCache.cache
|
CustomGlobalArmorOverrides.overrideCache.cache
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ public class ReplaceItemModelPatch {
|
|||||||
@Final
|
@Final
|
||||||
private Function<Identifier, ItemModel> modelGetter;
|
private Function<Identifier, ItemModel> modelGetter;
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("TAIL"))
|
|
||||||
private void saveMissingModel(BakedModelManager bakedModelManager, CallbackInfo ci) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private boolean hasModel(Identifier identifier) {
|
private boolean hasModel(Identifier identifier) {
|
||||||
return !(modelGetter.apply(identifier) instanceof MissingItemModel);
|
return !(modelGetter.apply(identifier) instanceof MissingItemModel);
|
||||||
|
|||||||
Reference in New Issue
Block a user