diff options
Diffstat (limited to 'src/texturePacks/java/moe/nea')
17 files changed, 208 insertions, 97 deletions
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/Compat.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/Compat.kt new file mode 100644 index 0000000..d95712b --- /dev/null +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/Compat.kt @@ -0,0 +1,11 @@ +package moe.nea.firmament.features.texturepack + +import moe.nea.firmament.util.compatloader.CompatMeta +import moe.nea.firmament.util.compatloader.ICompatMeta + +@CompatMeta +object Compat : ICompatMeta { + override fun shouldLoad(): Boolean { + return true + } +} diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt index e7c379b..dc3b109 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomBlockTextures.kt @@ -30,7 +30,6 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.profiler.Profiler import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe -import moe.nea.firmament.events.BakeExtraModelsEvent import moe.nea.firmament.events.EarlyResourceReloadEvent import moe.nea.firmament.events.FinalizeResourceManagerEvent import moe.nea.firmament.events.SkyblockServerUpdateEvent @@ -238,15 +237,6 @@ object CustomBlockTextures { { prepare(event.resourceManager) }, event.preparationExecutor) } - @Subscribe - fun bakeExtraModels(event: BakeExtraModelsEvent) { - preparationFuture.join().data.values - .flatMap { it.lookup.values } - .flatten() - .mapTo(mutableSetOf()) { it.replacement.blockModelIdentifier } - .forEach { event.addNonItemModel(it, it.id) } - } - private fun prepare(manager: ResourceManager): BakedReplacements { val resources = manager.findResources("overrides/blocks") { it.namespace == "firmskyblock" && it.path.endsWith(".json") diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt index 85dfa32..1fe1e08 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt @@ -85,16 +85,19 @@ object CustomGlobalArmorOverrides { ) } + // TODO: BipedEntityRenderer.getEquippedStack create copies of itemstacks for rendering. This means this cache is essentially useless + // If i figure out how to circumvent this (maybe track the origin of those copied itemstacks in some sort of variable in the itemstack to track back the original instance) i should reenable this cache. + // Then also re add this to the cache clearing function val overrideCache = - WeakCache.memoize<ItemStack, EquipmentSlot, Optional<EquippableComponent>>("ArmorOverrides") { stack, slot -> - val id = stack.skyBlockId ?: return@memoize Optional.empty() - val override = overrides[id.neuItem] ?: return@memoize Optional.empty() + WeakCache.dontMemoize<ItemStack, EquipmentSlot, Optional<EquippableComponent>>("ArmorOverrides") { stack, slot -> + val id = stack.skyBlockId ?: return@dontMemoize Optional.empty() + val override = overrides[id.neuItem] ?: return@dontMemoize Optional.empty() for (suboverride in override.overrides) { if (suboverride.predicate.test(stack)) { - return@memoize resolveComponent(slot, suboverride.modelIdentifier).intoOptional() + return@dontMemoize resolveComponent(slot, suboverride.modelIdentifier).intoOptional() } } - return@memoize resolveComponent(slot, override.modelIdentifier).intoOptional() + return@dontMemoize resolveComponent(slot, override.modelIdentifier).intoOptional() } var overrides: Map<String, ArmorOverride> = mapOf() @@ -145,6 +148,7 @@ object CustomGlobalArmorOverrides { null } } + bakedOverrides.clear() val associatedMap = overrides.flatMap { obj -> obj.itemIds.map { it to obj } } .toMap() associatedMap.forEach { it.value.bake(manager) } @@ -152,7 +156,6 @@ object CustomGlobalArmorOverrides { } override fun apply(prepared: Map<String, ArmorOverride>, manager: ResourceManager, profiler: Profiler) { - bakedOverrides.clear() overrides = prepared } }) @@ -160,11 +163,13 @@ object CustomGlobalArmorOverrides { @JvmStatic fun overrideArmor(itemStack: ItemStack, slot: EquipmentSlot): Optional<EquippableComponent> { + if (!CustomSkyBlockTextures.TConfig.enableArmorOverrides) return Optional.empty() return overrideCache.invoke(itemStack, slot) } @JvmStatic fun overrideArmorLayer(id: Identifier): EquipmentModel? { + if (!CustomSkyBlockTextures.TConfig.enableArmorOverrides) return null return bakedOverrides[id] } diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt index ad44b03..20f1fb6 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalTextures.kt @@ -16,7 +16,6 @@ import net.minecraft.util.Identifier import net.minecraft.util.profiler.Profiler import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe -import moe.nea.firmament.events.BakeExtraModelsEvent import moe.nea.firmament.events.CustomItemModelEvent import moe.nea.firmament.events.EarlyResourceReloadEvent import moe.nea.firmament.events.FinalizeResourceManagerEvent @@ -69,15 +68,6 @@ object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalText }, event.preparationExecutor) } - @Subscribe - fun onBakeModels(event: BakeExtraModelsEvent) { - for (guiClassOverride in preparationFuture.join().classes) { - for (override in guiClassOverride.overrides) { - event.addItemModel(ModelIdentifier(override.model, "inventory")) - } - } - } - @Volatile var preparationFuture: CompletableFuture<CustomGuiTextureOverride> = CompletableFuture.completedFuture( CustomGuiTextureOverride(listOf())) @@ -110,12 +100,12 @@ object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalText manager.getResource(Identifier.of(key.namespace, "filters/screen/${key.path}.json")) .getOrNull() ?: return@mapNotNull runNull { - ErrorUtil.softError("Failed to locate screen filter at $key") + ErrorUtil.softError("Failed to locate screen filter at $key used by ${it.value.map { it.first }}") } val screenFilter = Firmament.tryDecodeJsonFromStream<ScreenFilter>(guiClassResource.inputStream) .getOrElse { ex -> - ErrorUtil.softError("Failed to load screen filter at $key", ex) + ErrorUtil.softError("Failed to load screen filter at $key used by ${it.value.map { it.first }}", ex) return@mapNotNull null } ItemOverrideCollection(screenFilter, it.value.map { it.second }) diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt index 6472993..4529d1d 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt @@ -14,6 +14,7 @@ import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.FinalizeResourceManagerEvent import moe.nea.firmament.features.texturepack.predicates.AndPredicate +import moe.nea.firmament.features.texturepack.predicates.CastPredicate import moe.nea.firmament.features.texturepack.predicates.DisplayNamePredicate import moe.nea.firmament.features.texturepack.predicates.ExtraAttributesPredicate import moe.nea.firmament.features.texturepack.predicates.ItemPredicate @@ -21,6 +22,7 @@ import moe.nea.firmament.features.texturepack.predicates.LorePredicate import moe.nea.firmament.features.texturepack.predicates.NotPredicate import moe.nea.firmament.features.texturepack.predicates.OrPredicate import moe.nea.firmament.features.texturepack.predicates.PetPredicate +import moe.nea.firmament.features.texturepack.predicates.PullingPredicate import moe.nea.firmament.util.json.KJsonOps object CustomModelOverrideParser { @@ -71,9 +73,19 @@ object CustomModelOverrideParser { } ) - fun parsePredicates(predicates: JsonObject): List<FirmamentModelPredicate> { + fun parsePredicates(predicates: JsonObject?): List<FirmamentModelPredicate> { + if (predicates == null) return neverPredicate val parsedPredicates = mutableListOf<FirmamentModelPredicate>() for (predicateName in predicates.keySet()) { + if (predicateName == "cast") { // 1.21.4 + parsedPredicates.add(CastPredicate.Parser.parse(predicates[predicateName]) ?: return neverPredicate) + } + if (predicateName == "pull") { + parsedPredicates.add(PullingPredicate.Parser.parse(predicates[predicateName]) ?: return neverPredicate) + } + if (predicateName == "pulling") { + parsedPredicates.add(PullingPredicate.AnyPulling) + } if (!predicateName.startsWith("firmament:")) continue val identifier = Identifier.of(predicateName) val parser = predicateParsers[identifier] ?: return neverPredicate diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt index d9ca5b4..cf2a232 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomSkyBlockTextures.kt @@ -3,7 +3,6 @@ package moe.nea.firmament.features.texturepack import com.mojang.authlib.minecraft.MinecraftProfileTexture import com.mojang.authlib.properties.Property import java.util.Optional -import org.jetbrains.annotations.Nullable import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable import kotlin.jvm.optionals.getOrNull import net.minecraft.block.SkullBlock @@ -34,6 +33,7 @@ object CustomSkyBlockTextures : FirmamentFeature { val enableModelOverrides by toggle("model-overrides") { true } val enableArmorOverrides by toggle("armor-overrides") { true } val enableBlockOverrides by toggle("block-overrides") { true } + val enableLegacyMinecraftCompat by toggle("legacy-minecraft-path-support") { true } val enableLegacyCIT by toggle("legacy-cit") { true } val allowRecoloringUiText by toggle("recolor-text") { true } } @@ -44,7 +44,8 @@ object CustomSkyBlockTextures : FirmamentFeature { val allItemCaches by lazy { listOf( skullTextureCache.cache, - CustomGlobalArmorOverrides.overrideCache.cache + CustomItemModelEvent.cache.cache, + // TODO: re-add this once i figure out how to make the cache useful again CustomGlobalArmorOverrides.overrideCache.cache ) } @@ -75,7 +76,7 @@ object CustomSkyBlockTextures : FirmamentFeature { fun onCustomModelId(it: CustomItemModelEvent) { if (!TConfig.enabled) return val id = it.itemStack.skyBlockId ?: return - it.overrideIfExists(Identifier.of("firmskyblock", id.identifier.path)) + it.overrideIfEmpty(Identifier.of("firmskyblock", id.identifier.path)) } private val skullTextureCache = diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/FirmamentModelPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/FirmamentModelPredicate.kt index d11fec0..6cef4ca 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/FirmamentModelPredicate.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/FirmamentModelPredicate.kt @@ -1,8 +1,9 @@ - package moe.nea.firmament.features.texturepack +import net.minecraft.entity.LivingEntity import net.minecraft.item.ItemStack interface FirmamentModelPredicate { - fun test(stack: ItemStack): Boolean + fun test(stack: ItemStack, holder: LivingEntity?): Boolean = test(stack) + fun test(stack: ItemStack): Boolean = test(stack, null) } 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..0edad4c 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( @@ -34,7 +39,7 @@ class PredicateModel { ) { val model = overrides - .find { it.predicate.test(stack) } + .findLast { it.predicate.test(stack, user) } ?.model ?: fallback model.update(state, stack, resolver, transformationMode, world, user, seed) @@ -46,6 +51,22 @@ class PredicateModel { val overrides: List<Override>, ) : ItemModel.Unbaked { companion object { + @JvmStatic + fun fromLegacyJson(jsonObject: JsonObject, fallback: ItemModel.Unbaked): ItemModel.Unbaked { + val legacyOverrides = jsonObject.getAsJsonArray("overrides") ?: return fallback + val newOverrides = ArrayList<Override>() + 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<Override> = RecordCodecBuilder.create { it.group( ItemModelTypes.CODEC.fieldOf("model").forGetter(Override::model), diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/AndPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/AndPredicate.kt index 99abaaa..70eb814 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/AndPredicate.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/AndPredicate.kt @@ -3,15 +3,16 @@ package moe.nea.firmament.features.texturepack.predicates import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject +import net.minecraft.entity.LivingEntity import moe.nea.firmament.features.texturepack.CustomModelOverrideParser import moe.nea.firmament.features.texturepack.FirmamentModelPredicate import moe.nea.firmament.features.texturepack.FirmamentModelPredicateParser import net.minecraft.item.ItemStack class AndPredicate(val children: Array<FirmamentModelPredicate>) : FirmamentModelPredicate { - override fun test(stack: ItemStack): Boolean { - return children.all { it.test(stack) } - } + override fun test(stack: ItemStack, holder: LivingEntity?): Boolean { + return children.all { it.test(stack, holder) } + } object Parser : FirmamentModelPredicateParser { override fun parse(jsonElement: JsonElement): FirmamentModelPredicate { diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/CastPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/CastPredicate.kt new file mode 100644 index 0000000..2b79c1a --- /dev/null +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/CastPredicate.kt @@ -0,0 +1,25 @@ +package moe.nea.firmament.features.texturepack.predicates + +import com.google.gson.JsonElement +import net.minecraft.entity.LivingEntity +import net.minecraft.entity.player.PlayerEntity +import net.minecraft.item.ItemStack +import moe.nea.firmament.features.texturepack.FirmamentModelPredicate +import moe.nea.firmament.features.texturepack.FirmamentModelPredicateParser + +class CastPredicate : FirmamentModelPredicate { + object Parser : FirmamentModelPredicateParser { + override fun parse(jsonElement: JsonElement): FirmamentModelPredicate? { + if (jsonElement.asDouble >= 1) return CastPredicate() + return NotPredicate(arrayOf(CastPredicate())) + } + } + + override fun test(stack: ItemStack, holder: LivingEntity?): Boolean { + return (holder as? PlayerEntity)?.fishHook != null && holder.activeItem === stack + } + + override fun test(stack: ItemStack): Boolean { + return false + } +} diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/ItemPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/ItemPredicate.kt index 3cb80c7..4833dc0 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/ItemPredicate.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/ItemPredicate.kt @@ -17,7 +17,7 @@ class ItemPredicate( val item: Item ) : FirmamentModelPredicate { override fun test(stack: ItemStack): Boolean { - return stack.item == item + return stack.isOf(item) } object Parser : FirmamentModelPredicateParser { diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/PullingPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/PullingPredicate.kt new file mode 100644 index 0000000..fa46a70 --- /dev/null +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/PullingPredicate.kt @@ -0,0 +1,26 @@ +package moe.nea.firmament.features.texturepack.predicates + +import com.google.gson.JsonElement +import net.minecraft.entity.LivingEntity +import net.minecraft.item.BowItem +import net.minecraft.item.ItemStack +import moe.nea.firmament.features.texturepack.FirmamentModelPredicate +import moe.nea.firmament.features.texturepack.FirmamentModelPredicateParser + +class PullingPredicate(val percentage: Double) : FirmamentModelPredicate { + companion object { + val AnyPulling = PullingPredicate(0.1) + } + + object Parser : FirmamentModelPredicateParser { + override fun parse(jsonElement: JsonElement): FirmamentModelPredicate? { + return PullingPredicate(jsonElement.asDouble) + } + } + + override fun test(stack: ItemStack, holder: LivingEntity?): Boolean { + if (holder == null) return false + return BowItem.getPullProgress(holder.itemUseTime) >= percentage + } + +} diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java index cf5cf59..4665829 100644 --- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java +++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java @@ -1,11 +1,23 @@ package moe.nea.firmament.mixins.custommodels; -import net.minecraft.client.item.ItemModelManager; +import net.minecraft.client.render.entity.LivingEntityRenderer; +import net.minecraft.client.render.entity.model.EntityModel; +import net.minecraft.client.render.entity.state.LivingEntityRenderState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.decoration.DisplayEntity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ItemModelManager.class) -public class ApplyHeadModelInItemRenderer { +@Mixin(LivingEntityRenderer.class) +public class ApplyHeadModelInItemRenderer<T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> { // TODO: replace head_model with a condition model (if possible, automatically) // TODO: ItemAsset.CODEC should upgrade partials + @Inject(method = "updateRenderState(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/client/render/entity/state/LivingEntityRenderState;F)V", + at = @At("TAIL")) + private void updateHeadState(T livingEntity, S livingEntityRenderState, float f, CallbackInfo ci) { + + } } diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/PatchLegacyTexturePathsIntoArmorLayers.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/PatchLegacyTexturePathsIntoArmorLayers.java new file mode 100644 index 0000000..f829da0 --- /dev/null +++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/PatchLegacyTexturePathsIntoArmorLayers.java @@ -0,0 +1,38 @@ +package moe.nea.firmament.mixins.custommodels; + + +import moe.nea.firmament.features.texturepack.CustomSkyBlockTextures; +import moe.nea.firmament.util.MC; +import net.minecraft.client.render.entity.equipment.EquipmentModel; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(EquipmentModel.Layer.class) +public class PatchLegacyTexturePathsIntoArmorLayers { + @Shadow + @Final + private Identifier textureId; + + @Inject(method = "getFullTextureId", at = @At("HEAD"), cancellable = true) + private void replaceWith1201TextureIfExists(EquipmentModel.LayerType layerType, CallbackInfoReturnable<Identifier> cir) { + if (!CustomSkyBlockTextures.TConfig.INSTANCE.getEnableLegacyMinecraftCompat()) + return; + var resourceManager = MC.INSTANCE.getResourceManager(); + // legacy format: "assets/{identifier.namespace}/textures/models/armor/{identifier.path}_layer_{isLegs ? 2 : 1}{suffix}.png" + // suffix is sadly not available to us here. this means leather armor will look a bit shite + var legacyIdentifier = this.textureId.withPath((textureName) -> { + String var10000 = layerType.asString(); + return "textures/models/armor/" + textureName + "_layer_" + + (layerType == EquipmentModel.LayerType.HUMANOID_LEGGINGS ? 2 : 1) + + ".png"; + }); + if (resourceManager.getResource(legacyIdentifier).isPresent()) { + cir.setReturnValue(legacyIdentifier); + } + } +} diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReferenceCustomModelsPatch.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReferenceCustomModelsPatch.java deleted file mode 100644 index bbabeb5..0000000 --- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReferenceCustomModelsPatch.java +++ /dev/null @@ -1,31 +0,0 @@ -package moe.nea.firmament.mixins.custommodels; - -import com.llamalad7.mixinextras.sugar.Local; -import moe.nea.firmament.events.BakeExtraModelsEvent; -import net.minecraft.client.item.ItemAssetsLoader; -import net.minecraft.client.render.model.BakedModelManager; -import net.minecraft.client.render.model.BlockStatesLoader; -import net.minecraft.client.render.model.ReferencedModelsCollector; -import net.minecraft.client.render.model.UnbakedModel; -import net.minecraft.client.util.ModelIdentifier; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Map; - -@Mixin(BakedModelManager.class) -public abstract class ReferenceCustomModelsPatch { - @Inject(method = "collect", at = @At("RETURN")) - private static void addFirmamentReferencedModels( - UnbakedModel missingModel, Map<Identifier, UnbakedModel> models, BlockStatesLoader.BlockStateDefinition blockStates, ItemAssetsLoader.Result itemAssets, CallbackInfoReturnable<ReferencedModelsCollector> cir, - @Local ReferencedModelsCollector collector) { - // TODO: Insert fake models based on firmskyblock models for a smoother transition - - } -} diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java index ffa23f7..97abd1f 100644 --- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java +++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceItemModelPatch.java @@ -4,47 +4,40 @@ package moe.nea.firmament.mixins.custommodels; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import moe.nea.firmament.events.CustomItemModelEvent; +import moe.nea.firmament.util.mc.IntrospectableItemModelManager; import net.minecraft.client.item.ItemModelManager; import net.minecraft.client.render.item.model.ItemModel; import net.minecraft.client.render.item.model.MissingItemModel; -import net.minecraft.client.render.model.BakedModelManager; import net.minecraft.component.ComponentType; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.function.Function; @Mixin(ItemModelManager.class) -public class ReplaceItemModelPatch { +public class ReplaceItemModelPatch implements IntrospectableItemModelManager { @Shadow @Final private Function<Identifier, ItemModel> modelGetter; - @Inject(method = "<init>", at = @At("TAIL")) - private void saveMissingModel(BakedModelManager bakedModelManager, CallbackInfo ci) { - } - - @Unique - // TODO: Fix scissors - private boolean hasModel(Identifier identifier) { - return !(modelGetter.apply(identifier) instanceof MissingItemModel); - } - @WrapOperation( method = "update(Lnet/minecraft/client/render/item/ItemRenderState;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;get(Lnet/minecraft/component/ComponentType;)Ljava/lang/Object;")) private Object replaceItemModelByIdentifier(ItemStack instance, ComponentType componentType, Operation<Object> original) { - var override = CustomItemModelEvent.getModelIdentifier(instance); - if (override != null && hasModel(override)) { + var override = CustomItemModelEvent.getModelIdentifier(instance, this); + if (override != null && hasModel_firmament(override)) { return override; } return original.call(instance, componentType); } + + @Override + public boolean hasModel_firmament(@NotNull Identifier identifier) { + return !(modelGetter.apply(identifier) instanceof MissingItemModel); + } } diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java index 3f4cc44..850ea53 100644 --- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java +++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java @@ -1,10 +1,16 @@ package moe.nea.firmament.mixins.custommodels; +import com.google.gson.JsonObject; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.Firmament; +import moe.nea.firmament.features.texturepack.CustomSkyBlockTextures; +import moe.nea.firmament.features.texturepack.PredicateModel; +import moe.nea.firmament.util.ErrorUtil; import net.minecraft.client.item.ItemAsset; import net.minecraft.client.item.ItemAssetsLoader; import net.minecraft.client.render.item.model.BasicItemModel; +import net.minecraft.client.render.item.model.ItemModel; import net.minecraft.resource.Resource; import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourcePack; @@ -12,6 +18,7 @@ import net.minecraft.util.Identifier; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import java.io.InputStreamReader; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,23 +44,32 @@ public class SupplyFakeModelPatch { } private static ItemAssetsLoader.Result supplyExtraModels(ResourceManager resourceManager, ItemAssetsLoader.Result oldModels) { + if (!CustomSkyBlockTextures.TConfig.INSTANCE.getEnableLegacyMinecraftCompat()) return oldModels; Map<Identifier, ItemAsset> newModels = new HashMap<>(oldModels.contents()); var resources = resourceManager.findResources( "models/item", - id -> id.getNamespace().equals("firmskyblock") - && id.getPath().endsWith(".json") - && !id.getPath().substring("models/item/".length()).contains("/")); + id -> (id.getNamespace().equals("firmskyblock") || id.getNamespace().equals("cittofirmgenerated")) + && id.getPath().endsWith(".json")); for (Map.Entry<Identifier, Resource> model : resources.entrySet()) { var resource = model.getValue(); var itemModelId = model.getKey().withPath(it -> it.substring("models/item/".length(), it.length() - ".json".length())); - // TODO: parse json file here and make use of it in order to generate predicate files. var genericModelId = itemModelId.withPrefixedPath("item/"); - if (resourceManager.getResource(itemModelId) + var itemAssetId = itemModelId.withPrefixedPath("items/"); + // TODO: inject tint indexes based on the json data here + ItemModel.Unbaked unbakedModel = new BasicItemModel.Unbaked(genericModelId, List.of()); + // TODO: add a filter using the pack.mcmeta to opt out of this behaviour + try (var is = resource.getInputStream()) { + var jsonObject = Firmament.INSTANCE.getGson().fromJson(new InputStreamReader(is), JsonObject.class); + unbakedModel = PredicateModel.Unbaked.fromLegacyJson(jsonObject, unbakedModel); + } catch (Exception e) { + ErrorUtil.INSTANCE.softError("Could not create resource for fake model supplication: " + model.getKey(), e); + } + if (resourceManager.getResource(itemAssetId.withSuffixedPath(".json")) .map(Resource::getPack) .map(it -> isResourcePackNewer(resourceManager, it, resource.getPack())) .orElse(true)) { newModels.put(itemModelId, new ItemAsset( - new BasicItemModel.Unbaked(genericModelId, List.of()), + unbakedModel, new ItemAsset.Properties(true) )); } @@ -67,7 +83,7 @@ public class SupplyFakeModelPatch { var pack = manager.streamResourcePacks() .filter(it -> it == null_ || it == proposal) .collect(findLast()); - return pack.orElse(null) == proposal; + return pack.orElse(null_) != null_; } private static <T> Collector<T, ?, Optional<T>> findLast() { |