From 533fd68e2be8236c842f53fd0cafa52341226226 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 31 Dec 2024 16:50:19 +0100 Subject: feat: Add forward port for legacy predicates --- .../features/texturepack/PredicateModel.kt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt') diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt index e21e69d..b52e96b 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt @@ -1,17 +1,22 @@ package moe.nea.firmament.features.texturepack +import com.google.gson.JsonObject import com.mojang.serialization.Codec import com.mojang.serialization.MapCodec import com.mojang.serialization.codecs.RecordCodecBuilder import net.minecraft.client.item.ItemModelManager import net.minecraft.client.render.item.ItemRenderState +import net.minecraft.client.render.item.model.BasicItemModel import net.minecraft.client.render.item.model.ItemModel import net.minecraft.client.render.item.model.ItemModelTypes +import net.minecraft.client.render.item.tint.TintSource import net.minecraft.client.render.model.ResolvableModel import net.minecraft.client.world.ClientWorld import net.minecraft.entity.LivingEntity import net.minecraft.item.ItemStack import net.minecraft.item.ModelTransformationMode +import net.minecraft.util.Identifier +import moe.nea.firmament.features.texturepack.predicates.AndPredicate class PredicateModel { data class Baked( @@ -46,6 +51,22 @@ class PredicateModel { val overrides: List, ) : ItemModel.Unbaked { companion object { + @JvmStatic + fun fromLegacyJson(jsonObject: JsonObject, fallback: ItemModel.Unbaked): ItemModel.Unbaked { + val legacyOverrides = jsonObject.getAsJsonArray("overrides") ?: return fallback + val newOverrides = ArrayList() + for (legacyOverride in legacyOverrides) { + legacyOverride as JsonObject + val overrideModel = Identifier.tryParse(legacyOverride.get("model")?.asString ?: continue) ?: continue + val predicate = CustomModelOverrideParser.parsePredicates(legacyOverride.getAsJsonObject("predicate")) + newOverrides.add(Override( + BasicItemModel.Unbaked(overrideModel, listOf()), + AndPredicate(predicate.toTypedArray()) + )) + } + return Unbaked(fallback, newOverrides) + } + val OVERRIDE_CODEC: Codec = RecordCodecBuilder.create { it.group( ItemModelTypes.CODEC.fieldOf("model").forGetter(Override::model), -- cgit