From ee21f2da76ea2218ef6a0c6fefa97befa654d115 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 6 Nov 2024 16:14:10 +0100 Subject: Fix model unwrapping --- .../firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java | 4 ++-- .../nea/firmament/mixins/custommodels/HeadModelReplacerPatch.java | 6 ++++-- .../firmament/mixins/custommodels/ItemRendererTintContextPatch.java | 6 ++++-- .../firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main/java/moe/nea') diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java index ffa59c6..dac65fe 100644 --- a/src/main/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java @@ -24,8 +24,8 @@ public class ApplyHeadModelInItemRenderer { BakedModel model, boolean useInventoryModel, float z, CallbackInfo ci, @Local(argsOnly = true) LocalRef modelMut ) { - if (transformationMode == ModelTransformationMode.HEAD - && model instanceof BakedModelExtra extra) { + var extra = BakedModelExtra.cast(model); + if (transformationMode == ModelTransformationMode.HEAD && extra != null) { var headModel = extra.getHeadModel_firmament(); if (headModel != null) { modelMut.set(headModel); diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/HeadModelReplacerPatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/HeadModelReplacerPatch.java index 7518041..26c331e 100644 --- a/src/main/java/moe/nea/firmament/mixins/custommodels/HeadModelReplacerPatch.java +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/HeadModelReplacerPatch.java @@ -35,7 +35,8 @@ public class HeadModelReplacerPatch original, @Local BakedModel bakedModel) { var oldBlock = original.call(instance); if (oldBlock instanceof AbstractSkullBlock) { - if (bakedModel instanceof BakedModelExtra extra && extra.getHeadModel_firmament() != null) + var extra = BakedModelExtra.cast(bakedModel); + if (extra != null && extra.getHeadModel_firmament() != null) return Blocks.ENCHANTING_TABLE; // Any non skull block. Let's choose the enchanting table because it is very distinct. } return oldBlock; @@ -48,7 +49,8 @@ public class HeadModelReplacerPatch original, @Local BakedModel bakedModel) { - if (bakedModel instanceof BakedModelExtra extra && extra.getHeadModel_firmament() != null) + var extra = BakedModelExtra.cast(bakedModel); + if (extra != null && extra.getHeadModel_firmament() != null) return false; return original.call(stack, slot); } diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ItemRendererTintContextPatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ItemRendererTintContextPatch.java index 66feced..8c5411b 100644 --- a/src/main/java/moe/nea/firmament/mixins/custommodels/ItemRendererTintContextPatch.java +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ItemRendererTintContextPatch.java @@ -18,7 +18,8 @@ public class ItemRendererTintContextPatch { @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;ZF)V", at = @At(value = "HEAD"), allow = 1) private void onStartRendering(ItemStack stack, ModelTransformationMode transformationMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, boolean useInventoryModel, float z, CallbackInfo ci) { - if (model instanceof BakedModelExtra extra) { + var extra = BakedModelExtra.cast(model); + if (extra != null) { TintOverrides.Companion.enter(extra.getTintOverrides_firmament()); } } @@ -26,7 +27,8 @@ public class ItemRendererTintContextPatch { @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;ZF)V", at = @At("TAIL"), allow = 1) private void onEndRendering(ItemStack stack, ModelTransformationMode transformationMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, boolean useInventoryModel, float z, CallbackInfo ci) { - if (model instanceof BakedModelExtra extra) { + var extra = BakedModelExtra.cast(model); + if (extra != null) { TintOverrides.Companion.exit(extra.getTintOverrides_firmament()); } } diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java b/src/main/java/moe/nea/firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java index 2de2e5e..a5bb34f 100644 --- a/src/main/java/moe/nea/firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java @@ -84,7 +84,8 @@ public abstract class JsonUnbakedModelDataHolder implements JsonUnbakedModelFirm if (!this.toString().contains("minecraft") && this.toString().contains("crimson")) { System.out.println("Found non minecraft model " + this); } - if (bakedModel instanceof BakedModelExtra extra) { + var extra = BakedModelExtra.cast(bakedModel); + if (extra != null) { var headModel = getHeadModel_firmament(); if (headModel != null) { extra.setHeadModel_firmament(baker.bake(headModel, ModelRotation.X0_Y0)); -- cgit