From 86cbf9d4221e85dec14300c11393abb325bffcef Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 17 Nov 2024 19:41:18 +0100 Subject: fix: Item predicates not applying unless a vanilla predicate is present --- .../firmament/mixins/CustomModelEventPatch.java | 11 ++++++-- .../custommodels/GlobalModelOverridePatch.java | 31 ---------------------- .../TestForFirmamentOverridePredicatesPatch.java | 23 ++++++++++++++-- 3 files changed, 30 insertions(+), 35 deletions(-) delete mode 100644 src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java (limited to 'src/main/java/moe') diff --git a/src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java b/src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java index e7207f4..e0a7544 100644 --- a/src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java +++ b/src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java @@ -3,9 +3,11 @@ package moe.nea.firmament.mixins; import moe.nea.firmament.events.CustomItemModelEvent; +import moe.nea.firmament.features.texturepack.CustomGlobalTextures; import net.minecraft.client.render.item.ItemModels; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.BakedModelManager; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import org.spongepowered.asm.mixin.Final; @@ -22,8 +24,13 @@ public class CustomModelEventPatch { @Inject(method = "getModel(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/client/render/model/BakedModel;", at = @At("HEAD"), cancellable = true) public void onGetModel(ItemStack stack, CallbackInfoReturnable cir) { - var model = CustomItemModelEvent.getModel(stack, (ItemModels) (Object) this); - if (model != null) + var $this = (ItemModels) (Object) this; + var model = CustomItemModelEvent.getModel(stack, $this); + if (model == null) { + model = CustomGlobalTextures.replaceGlobalModel($this, stack); + } + if (model != null) { cir.setReturnValue(model); + } } } diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java deleted file mode 100644 index c708862..0000000 --- a/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java +++ /dev/null @@ -1,31 +0,0 @@ - -package moe.nea.firmament.mixins.custommodels; - -import moe.nea.firmament.features.texturepack.CustomGlobalTextures; -import net.minecraft.client.render.item.ItemModels; -import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -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(ItemRenderer.class) -public abstract class GlobalModelOverridePatch { - - @Shadow - @Final - private ItemModels models; - - @Inject(method = "getModel(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)Lnet/minecraft/client/render/model/BakedModel;", at = @At("HEAD"), cancellable = true) - private void overrideGlobalModel( - ItemStack stack, World world, LivingEntity entity, - int seed, CallbackInfoReturnable cir) { - CustomGlobalTextures.replaceGlobalModel(this.models, stack, cir); - } -} diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java index 81ae3b8..63f3cf0 100644 --- a/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java @@ -2,7 +2,10 @@ package moe.nea.firmament.mixins.custommodels; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.Firmament; import moe.nea.firmament.features.texturepack.BakedOverrideData; import moe.nea.firmament.features.texturepack.CustomSkyBlockTextures; import moe.nea.firmament.features.texturepack.FirmamentModelPredicate; @@ -10,13 +13,23 @@ import moe.nea.firmament.features.texturepack.ModelOverrideData; import net.minecraft.client.render.model.json.ModelOverride; import net.minecraft.client.render.model.json.ModelOverrideList; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import org.objectweb.asm.Opcodes; +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.ModifyArg; +import java.util.List; +import java.util.Objects; + @Mixin(ModelOverrideList.class) public class TestForFirmamentOverridePredicatesPatch { + @Shadow + private Identifier[] conditionTypes; + @ModifyArg(method = "(Lnet/minecraft/client/render/model/Baker;Ljava/util/List;)V", at = @At( value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z" @@ -26,8 +39,14 @@ public class TestForFirmamentOverridePredicatesPatch { @Local ModelOverride modelOverride ) { var bakedOverride = (ModelOverrideList.BakedOverride) element; - ((BakedOverrideData) (Object) bakedOverride) - .setFirmamentOverrides(((ModelOverrideData) (Object) modelOverride).getFirmamentOverrides()); + var modelOverrideData = ModelOverrideData.cast(modelOverride); + BakedOverrideData.cast(bakedOverride) + .setFirmamentOverrides(modelOverrideData.getFirmamentOverrides()); + if (conditionTypes.length == 0 && + modelOverrideData.getFirmamentOverrides() != null && + modelOverrideData.getFirmamentOverrides().length > 0) { + conditionTypes = new Identifier[]{Firmament.INSTANCE.identifier("sentinel/enforce_model_override_evaluation")}; + } return element; } -- cgit