From 6ef310a5c2ea60accb1370a72164e96f152717df Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:13:43 +0200 Subject: [PATCH] Mixin't - Fixed crash on startup when Optifine is installed --- .../create/foundation/item/LayeredArmorItem.java | 15 +++++++++++++-- .../accessor/HumanoidArmorLayerAccessor.java | 9 +-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/item/LayeredArmorItem.java b/src/main/java/com/simibubi/create/foundation/item/LayeredArmorItem.java index 7207845bf..c65290dc3 100644 --- a/src/main/java/com/simibubi/create/foundation/item/LayeredArmorItem.java +++ b/src/main/java/com/simibubi/create/foundation/item/LayeredArmorItem.java @@ -3,11 +3,15 @@ package com.simibubi.create.foundation.item; import java.util.Map; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.foundation.mixin.accessor.HumanoidArmorLayerAccessor; import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.model.Model; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; @@ -39,14 +43,21 @@ public interface LayeredArmorItem extends CustomRenderedArmorItem { accessor.create$callSetPartVisibility(innerModel, slot); String locationStr2 = getArmorTextureLocation(entity, slot, stack, 2); ResourceLocation location2 = locationCache.computeIfAbsent(locationStr2, ResourceLocation::new); - accessor.create$callRenderModel(poseStack, bufferSource, light, item, innerModel, glint, 1.0F, 1.0F, 1.0F, location2); + renderModel(poseStack, bufferSource, light, item, innerModel, glint, 1.0F, 1.0F, 1.0F, location2); HumanoidModel outerModel = accessor.create$getOuterModel(); layer.getParentModel().copyPropertiesTo((HumanoidModel) outerModel); accessor.create$callSetPartVisibility(outerModel, slot); String locationStr1 = getArmorTextureLocation(entity, slot, stack, 1); ResourceLocation location1 = locationCache.computeIfAbsent(locationStr1, ResourceLocation::new); - accessor.create$callRenderModel(poseStack, bufferSource, light, item, outerModel, glint, 1.0F, 1.0F, 1.0F, location1); + renderModel(poseStack, bufferSource, light, item, outerModel, glint, 1.0F, 1.0F, 1.0F, location1); + } + + // from HumanoidArmorLayer.renderModel + private void renderModel(PoseStack poseStack, MultiBufferSource bufferSource, int light, ArmorItem item, + Model model, boolean glint, float red, float green, float blue, ResourceLocation armorResource) { + VertexConsumer vertexconsumer = bufferSource.getBuffer(RenderType.armorCutoutNoCull(armorResource)); + model.renderToBuffer(poseStack, vertexconsumer, light, OverlayTexture.NO_OVERLAY, red, green, blue, 1.0F); } String getArmorTextureLocation(LivingEntity entity, EquipmentSlot slot, ItemStack stack, int layer); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/accessor/HumanoidArmorLayerAccessor.java b/src/main/java/com/simibubi/create/foundation/mixin/accessor/HumanoidArmorLayerAccessor.java index 8b37b1435..34d7e63ab 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/accessor/HumanoidArmorLayerAccessor.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/accessor/HumanoidArmorLayerAccessor.java @@ -6,15 +6,10 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; -import com.mojang.blaze3d.vertex.PoseStack; - import net.minecraft.client.model.HumanoidModel; -import net.minecraft.client.model.Model; -import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ArmorItem; @Mixin(HumanoidArmorLayer.class) public interface HumanoidArmorLayerAccessor { @@ -31,7 +26,5 @@ public interface HumanoidArmorLayerAccessor { @Invoker("setPartVisibility") void create$callSetPartVisibility(HumanoidModel model, EquipmentSlot slot); - - @Invoker("renderModel") - void create$callRenderModel(PoseStack poseStack, MultiBufferSource bufferSource, int light, ArmorItem item, Model model, boolean glint, float red, float green, float blue, ResourceLocation armorResource); + }