From ae4d8b067c33c7b28d0178ef84d84f5aff26a507 Mon Sep 17 00:00:00 2001 From: CleverNucleus Date: Tue, 30 Aug 2022 22:53:58 +0100 Subject: [PATCH] Fixes and versioning *HOPEFULLY we fixed the compat issue with Geckolib. I only know it exists because may player's have provided error logs that show as much, however I still cannot replicate the crash for testing purposes. So while I THINK this fixes it, I cannot actually verify this. +Incremented version *Now uses VersionDependency instead of ModDependency --- .../impl/ArmorRenderLibImpl.java | 4 ++-- .../impl/ArmorTextureCache.java | 5 +++- .../mixin/ArmorFeatureRendererInvoker.java | 2 -- .../mixin/ArmorFeatureRendererMixin.java | 24 +++++++++++++++++-- src/main/resources/fabric.mod.json | 4 ++-- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/clevernucleus/armorrenderlib/impl/ArmorRenderLibImpl.java b/src/main/java/com/github/clevernucleus/armorrenderlib/impl/ArmorRenderLibImpl.java index 3517fc8..76a9984 100644 --- a/src/main/java/com/github/clevernucleus/armorrenderlib/impl/ArmorRenderLibImpl.java +++ b/src/main/java/com/github/clevernucleus/armorrenderlib/impl/ArmorRenderLibImpl.java @@ -34,7 +34,7 @@ private static , A extends if(item.getSlotType() != slot) return; var entityRenderer = MinecraftClient.getInstance().getEntityRenderDispatcher().getRenderer(entity); ArmorFeatureRenderer armorFeatureRenderer = (ArmorFeatureRenderer)((FeatureRendererAccessor)entityRenderer).getFeatureRenderer(); - A model = ((ArmorFeatureRendererInvoker)armorFeatureRenderer).invokeGetArmor(slot); + A model = ((ArmorTextureCache)armorFeatureRenderer).getArmorCustom(slot); contextModel.setAttributes((BipedEntityModel)model); ((ArmorFeatureRendererInvoker)armorFeatureRenderer).invokeSetVisible(model, slot); @@ -44,7 +44,7 @@ private static , A extends float green = (float)(color >> 8 & 0xFF) / 255.0F; float blue = (float)(color & 0xFF) / 255.0F; - VertexConsumer vertexConsumer = ItemRenderer.getArmorGlintConsumer(vertexConsumers, RenderLayer.getArmorCutoutNoCull(((ArmorTextureCache)armorFeatureRenderer).getOrCache(path)), false, glint); + VertexConsumer vertexConsumer = ItemRenderer.getArmorGlintConsumer(vertexConsumers, RenderLayer.getArmorCutoutNoCull(((ArmorTextureCache)armorFeatureRenderer).getOrCache(path)), false, glint); model.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV, red, green, blue, 1.0F); }); } diff --git a/src/main/java/com/github/clevernucleus/armorrenderlib/impl/ArmorTextureCache.java b/src/main/java/com/github/clevernucleus/armorrenderlib/impl/ArmorTextureCache.java index 492415a..29fb42d 100644 --- a/src/main/java/com/github/clevernucleus/armorrenderlib/impl/ArmorTextureCache.java +++ b/src/main/java/com/github/clevernucleus/armorrenderlib/impl/ArmorTextureCache.java @@ -1,7 +1,10 @@ package com.github.clevernucleus.armorrenderlib.impl; +import net.minecraft.entity.EquipmentSlot; import net.minecraft.util.Identifier; -public interface ArmorTextureCache { +public interface ArmorTextureCache { + A getArmorCustom(EquipmentSlot slot); + Identifier getOrCache(final String path); } diff --git a/src/main/java/com/github/clevernucleus/armorrenderlib/mixin/ArmorFeatureRendererInvoker.java b/src/main/java/com/github/clevernucleus/armorrenderlib/mixin/ArmorFeatureRendererInvoker.java index 541d6e5..ca2a948 100644 --- a/src/main/java/com/github/clevernucleus/armorrenderlib/mixin/ArmorFeatureRendererInvoker.java +++ b/src/main/java/com/github/clevernucleus/armorrenderlib/mixin/ArmorFeatureRendererInvoker.java @@ -10,8 +10,6 @@ @Mixin(ArmorFeatureRenderer.class) public interface ArmorFeatureRendererInvoker, A extends BipedEntityModel> { - @Invoker("getArmor") - public A invokeGetArmor(EquipmentSlot slot); @Invoker("setVisible") public void invokeSetVisible(A bipedModel, EquipmentSlot slot); diff --git a/src/main/java/com/github/clevernucleus/armorrenderlib/mixin/ArmorFeatureRendererMixin.java b/src/main/java/com/github/clevernucleus/armorrenderlib/mixin/ArmorFeatureRendererMixin.java index bf0e49e..f4b1334 100644 --- a/src/main/java/com/github/clevernucleus/armorrenderlib/mixin/ArmorFeatureRendererMixin.java +++ b/src/main/java/com/github/clevernucleus/armorrenderlib/mixin/ArmorFeatureRendererMixin.java @@ -9,15 +9,35 @@ import com.github.clevernucleus.armorrenderlib.impl.ArmorTextureCache; import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; +import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; -@Mixin(value = ArmorFeatureRenderer.class, priority = 900) -abstract class ArmorFeatureRendererMixin implements ArmorTextureCache { +@Mixin(ArmorFeatureRenderer.class) +abstract class ArmorFeatureRendererMixin, A extends BipedEntityModel> implements ArmorTextureCache { @Shadow @Final private static Map ARMOR_TEXTURE_CACHE; + @Shadow + @Final + private A leggingsModel; + + @Shadow + @Final + private A bodyModel; + + /* + * We do this instead of just an invoker because Geckolib Injects into #getArmor and runs an instanced set/get exiting the method, + * which causes the game to crash anytime that method is accessed from anywhere else - and we want to be compatible with Geckolib. + */ + @Override + public A getArmorCustom(EquipmentSlot slot) { + return slot == EquipmentSlot.LEGS ? this.leggingsModel : this.bodyModel; + } + @Override public Identifier getOrCache(final String path) { return ARMOR_TEXTURE_CACHE.computeIfAbsent(path, Identifier::new); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index cf6fa77..04a41e3 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,8 +26,8 @@ ], "depends": { "fabricloader": ">=0.14.9", - "fabric-api": ">=0.59.0", - "minecraft": "1.19.2", + "fabric": ">=0.58.0", + "minecraft": "1.19", "java": ">=17" } } \ No newline at end of file