Помощь с отрисовкой брони маинкрафт 1.12.2

Версия Minecraft
1.12.2
API
Forge
RenderHandler:
package com.example.examplemod.client.handler;

import com.example.examplemod.ExampleMod;
import com.example.examplemod.capabilities.ICustomArmorInventory;
import com.example.examplemod.capabilities.ModCapabilities;
import com.example.examplemod.client.model.ModelCustomArmor;
import com.example.examplemod.item.armor.BaseArmor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import static org.lwjgl.opengl.GL11.GL_LEQUAL;

@SideOnly(Side.CLIENT)
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = ExampleMod.MODID)
public class RenderHandler {

    private static final ModelCustomArmor ARMOR_MODEL = new ModelCustomArmor(0.0f);

    @SubscribeEvent
    public static void onRenderPlayerPost(RenderPlayerEvent.Post event) {
        EntityPlayer player = event.getEntityPlayer();
        float partialTicks = event.getPartialRenderTick();

        ICustomArmorInventory invCap = player.getCapability(ModCapabilities.CUSTOM_ARMOR_INVENTORY, null);
        if (invCap == null) return;

        ModelPlayer playerModel = event.getRenderer().getMainModel();

        GlStateManager.pushMatrix();

        float eyeHeight = player.getEyeHeight();
        GlStateManager.translate(0.0F, eyeHeight - 0.17F, 0.0F);

        float renderYawOffset = interpolateRotation(
                player.prevRenderYawOffset,
                player.renderYawOffset,
                partialTicks
        );

        GlStateManager.rotate(180.0F - renderYawOffset, 0.0F, 1.0F, 0.0F);
        GlStateManager.scale(-1.0F, -1.0F, 1.0F);

        float limbSwing = player.limbSwing - player.limbSwingAmount * (1.0F - partialTicks);
        float limbSwingAmount = player.prevLimbSwingAmount + (player.limbSwingAmount - player.prevLimbSwingAmount) * partialTicks;

        float rotationYawHead = interpolateRotation(
                player.prevRotationYawHead,
                player.rotationYawHead,
                partialTicks
        );

        float headYaw = rotationYawHead - renderYawOffset;
        headYaw = MathHelper.wrapDegrees(headYaw);

        float headPitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;

        float ageInTicks = player.ticksExisted + partialTicks;

        if (player.isPlayerSleeping()) {
            headYaw = 0.0F;
            headPitch = 0.0F;
        }

        GlStateManager.enablePolygonOffset();
        GlStateManager.doPolygonOffset(-6.5F, -7.0F);

        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);

        GlStateManager.depthMask(true);
        GlStateManager.enableDepth();
        GlStateManager.depthFunc(515);

        for (int i = 0; i < invCap.getInventory().getSizeInventory(); i++) {
            ItemStack stack = invCap.getInventory().getStackInSlot(i);
            if (!stack.isEmpty() && stack.getItem() instanceof BaseArmor) {
                BaseArmor armor = (BaseArmor) stack.getItem();
                if (armor.getArmorSlot().ordinal() != i) continue;

                Minecraft.getMinecraft().getTextureManager().bindTexture(
                        new ResourceLocation(armor.getTexturePath())
                );

                ARMOR_MODEL.setModelAttributes(playerModel);

                syncWithPlayerModel(playerModel, player, partialTicks);

                ARMOR_MODEL.render(
                        player,
                        limbSwing,
                        limbSwingAmount,
                        ageInTicks,
                        headYaw,
                        headPitch,
                        0.0625F
                );
            }
        }

        GlStateManager.depthFunc(515);
        GlStateManager.disableBlend();
        GlStateManager.disablePolygonOffset();

        GlStateManager.popMatrix();
    }

    private static void syncWithPlayerModel(ModelPlayer playerModel, EntityPlayer player, float partialTicks) {
        playerModel.swingProgress = player.getSwingProgress(partialTicks);
        playerModel.isSneak = player.isSneaking();
        playerModel.isRiding = player.isRiding();
    }

    private static float interpolateRotation(float prevYaw, float yaw, float partialTicks) {
        float difference = yaw - prevYaw;

        while (difference < -180.0F) {
            difference += 360.0F;
        }

        while (difference >= 180.0F) {
            difference -= 360.0F;
        }

        return prevYaw + difference * partialTicks;
    }
}
ModelCustomArmor:
package com.example.examplemod.client.model;

import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumHandSide;

public class ModelCustomArmor extends ModelBiped {

    private EnumHandSide swingingHand;

    public ModelCustomArmor(float modelSize) {
        super(modelSize, 0.0F, 64, 32);
    }

    public ModelCustomArmor(float modelSize, float yOffset, int textureWidth, int textureHeight) {
        super(modelSize, yOffset, textureWidth, textureHeight);
    }

    @Override
    public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) {
        super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);
    }

    public void setModelAttributes(ModelBiped sourceModel) {
        super.setModelAttributes(sourceModel);

        this.leftArmPose = sourceModel.leftArmPose;
        this.rightArmPose = sourceModel.rightArmPose;

        if (sourceModel instanceof ModelPlayer) {
            try {
                java.lang.reflect.Field swingingHandField = ModelPlayer.class.getDeclaredField("swingingHand");
                swingingHandField.setAccessible(true);
                EnumHandSide handSide = (EnumHandSide) swingingHandField.get(sourceModel);
                this.swingingHand = handSide;
            } catch (Exception e) {
                this.swingingHand = EnumHandSide.RIGHT;
            }
        }

        copyModelPositions(sourceModel.bipedHead, this.bipedHead);
        copyModelPositions(sourceModel.bipedBody, this.bipedBody);
        copyModelPositions(sourceModel.bipedRightArm, this.bipedRightArm);
        copyModelPositions(sourceModel.bipedLeftArm, this.bipedLeftArm);
        copyModelPositions(sourceModel.bipedRightLeg, this.bipedRightLeg);
        copyModelPositions(sourceModel.bipedLeftLeg, this.bipedLeftLeg);
        copyModelPositions(sourceModel.bipedHeadwear, this.bipedHeadwear);
    }

    private void copyModelPositions(ModelRenderer source, ModelRenderer dest) {
        dest.rotateAngleX = source.rotateAngleX;
        dest.rotateAngleY = source.rotateAngleY;
        dest.rotateAngleZ = source.rotateAngleZ;

        dest.rotationPointX = source.rotationPointX;
        dest.rotationPointY = source.rotationPointY;
        dest.rotationPointZ = source.rotationPointZ;

        dest.offsetX = source.offsetX;
        dest.offsetY = source.offsetY;
        dest.offsetZ = source.offsetZ;
    }
}
Здравствуйте! Решил я сделать кастомный инвентарь на 1.12.2 и добавить к нему броню , но у брони , точнее у рендера(просто накладываю текстуру на игрока как в ванилке) есть проблемки с отрисовкой на шифте да и в обычном положении , когда я смотрю в опередленном угле то у меня просвечивается армор , а у модели брони у головы смещается моделька когда я смотрю в разных положениях: посередке , вверх , вниз , скриншоты отправлю и если есть возможность фиксануть пробелы модели игрока в ногах и руках при ходьбе без PolygonOffset (потомучто из за большого значения появляются какито артефакты , а если поставить меньше то эффект пробелов останется) , то тоже буду рад , помогите пожалуйста.
 

Вложения

  • 2025-10-04_21.35.45.png
    2025-10-04_21.35.45.png
    85.7 KB · Просмотры: 12
  • 2025-10-04_21.34.48.png
    2025-10-04_21.34.48.png
    46.2 KB · Просмотры: 12
  • 2025-10-04_21.34.43.png
    2025-10-04_21.34.43.png
    263.8 KB · Просмотры: 13
  • 2025-10-04_21.34.40.png
    2025-10-04_21.34.40.png
    771.8 KB · Просмотры: 12
Тебе надо в syncWithPlayerModel запихивать модель брони, зачем тебе синхронизировать модель игрока если ты рисуешь модель брони.
Java:
                BaseArmor armor = (BaseArmor) stack.getItem();
                if (armor.getArmorSlot().ordinal() != i) continue;

                Minecraft.getMinecraft().getTextureManager().bindTexture(
                        new ResourceLocation(armor.getTexturePath())
                );

                syncWithPlayerModel(playerModel, player, partialTicks); // хотя тут в целом достаточно эти 2 строки поменять местами
                ARMOR_MODEL.setModelAttributes(playerModel);

                ARMOR_MODEL.render(
                        player,
                        limbSwing,
                        limbSwingAmount,
                        ageInTicks,
                        headYaw,
                        headPitch,
                        0.0625F
                );
 
Последнее редактирование:
ModelCustomArmor:
package com.example.examplemod.client.model;

import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumHandSide;

public class ModelCustomArmor extends ModelBiped {

    private EnumHandSide swingingHand;

    public ModelCustomArmor(float modelSize) {
        super(modelSize, 0.0F, 64, 32);
    }

    public ModelCustomArmor(float modelSize, float yOffset, int textureWidth, int textureHeight) {
        super(modelSize, yOffset, textureWidth, textureHeight);
    }

    @Override
    public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) {
        super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);
    }

    public void setModelAttributes(ModelBiped sourceModel) {
        super.setModelAttributes(sourceModel);

        this.leftArmPose = sourceModel.leftArmPose;
        this.rightArmPose = sourceModel.rightArmPose;

        if (sourceModel instanceof ModelPlayer) {
            try {
                java.lang.reflect.Field swingingHandField = ModelPlayer.class.getDeclaredField("swingingHand");
                swingingHandField.setAccessible(true);
                EnumHandSide handSide = (EnumHandSide) swingingHandField.get(sourceModel);
                this.swingingHand = handSide;
            } catch (Exception e) {
                this.swingingHand = EnumHandSide.RIGHT;
            }
        }

        copyModelPositions(sourceModel.bipedHead, this.bipedHead);
        copyModelPositions(sourceModel.bipedBody, this.bipedBody);
        copyModelPositions(sourceModel.bipedRightArm, this.bipedRightArm);
        copyModelPositions(sourceModel.bipedLeftArm, this.bipedLeftArm);
        copyModelPositions(sourceModel.bipedRightLeg, this.bipedRightLeg);
        copyModelPositions(sourceModel.bipedLeftLeg, this.bipedLeftLeg);
        copyModelPositions(sourceModel.bipedHeadwear, this.bipedHeadwear);
    }

    private void copyModelPositions(ModelRenderer source, ModelRenderer dest) {
        dest.rotateAngleX = source.rotateAngleX;
        dest.rotateAngleY = source.rotateAngleY;
        dest.rotateAngleZ = source.rotateAngleZ;

        dest.rotationPointX = source.rotationPointX;
        dest.rotationPointY = source.rotationPointY;
        dest.rotationPointZ = source.rotationPointZ;

        dest.offsetX = source.offsetX;
        dest.offsetY = source.offsetY;
        dest.offsetZ = source.offsetZ;
    }
}
RenderHandler:
package com.example.examplemod.client.handler;

import com.example.examplemod.ExampleMod;
import com.example.examplemod.capabilities.ICustomArmorInventory;
import com.example.examplemod.capabilities.ModCapabilities;
import com.example.examplemod.client.model.ModelCustomArmor;
import com.example.examplemod.item.armor.BaseArmor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;

@SideOnly(Side.CLIENT)
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = ExampleMod.MODID)
public class RenderHandler {

    private static final ModelCustomArmor ARMOR_MODEL = new ModelCustomArmor(0.0f);

    @SubscribeEvent
    public static void onRenderPlayerPost(RenderPlayerEvent.Post event) {
        EntityPlayer player = event.getEntityPlayer();
        float partialTicks = event.getPartialRenderTick();

        ICustomArmorInventory invCap = player.getCapability(ModCapabilities.CUSTOM_ARMOR_INVENTORY, null);
        if (invCap == null) return;

        ModelPlayer playerModel = event.getRenderer().getMainModel();

        GlStateManager.pushMatrix();

        float eyeHeight = player.getEyeHeight();
        GlStateManager.translate(0.0F, eyeHeight - 0.17F, 0.0F);

        float renderYawOffset = interpolateRotation(
                player.prevRenderYawOffset,
                player.renderYawOffset,
                partialTicks
        );

        GlStateManager.rotate(180.0F - renderYawOffset, 0.0F, 1.0F, 0.0F);
        GlStateManager.scale(-1.0F, -1.0F, 1.0F);

        float limbSwing = player.limbSwing - player.limbSwingAmount * (1.0F - partialTicks);
        float limbSwingAmount = player.prevLimbSwingAmount + (player.limbSwingAmount - player.prevLimbSwingAmount) * partialTicks;

        float rotationYawHead = interpolateRotation(
                player.prevRotationYawHead,
                player.rotationYawHead,
                partialTicks
        );

        float headYaw = rotationYawHead - renderYawOffset;
        headYaw = MathHelper.wrapDegrees(headYaw);

        float headPitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;

        float ageInTicks = player.ticksExisted + partialTicks;

        if (player.isPlayerSleeping()) {
            headYaw = 0.0F;
            headPitch = 0.0F;
        }

        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        GlStateManager.enableDepth();
        GlStateManager.depthMask(true);
        GlStateManager.depthFunc(GL11.GL_LEQUAL);

        for (int i = 0; i < invCap.getInventory().getSizeInventory(); i++) {
            ItemStack stack = invCap.getInventory().getStackInSlot(i);
            if (!stack.isEmpty() && stack.getItem() instanceof BaseArmor) {
                BaseArmor armor = (BaseArmor) stack.getItem();
                if (armor.getArmorSlot().ordinal() != i) continue;

                Minecraft.getMinecraft().getTextureManager().bindTexture(
                        new ResourceLocation(armor.getTexturePath())
                );

                syncWithPlayerModel(playerModel, player, partialTicks);
                ARMOR_MODEL.setModelAttributes(playerModel);

                ARMOR_MODEL.render(
                        player,
                        limbSwing,
                        limbSwingAmount,
                        ageInTicks,
                        headYaw,
                        headPitch,
                        0.0625F
                );
            }
        }

        GlStateManager.depthFunc(GL11.GL_LEQUAL);
        GlStateManager.disableBlend();
        GlStateManager.popMatrix();
    }

    private static void syncWithPlayerModel(ModelPlayer playerModel, EntityPlayer player, float partialTicks) {
        playerModel.swingProgress = player.getSwingProgress(partialTicks);
        playerModel.isSneak = player.isSneaking();
        playerModel.isRiding = player.isRiding();
    }

    private static float interpolateRotation(float prevYaw, float yaw, float partialTicks) {
        float difference = yaw - prevYaw;

        while (difference < -180.0F) {
            difference += 360.0F;
        }

        while (difference >= 180.0F) {
            difference -= 360.0F;
        }

        return prevYaw + difference * partialTicks;
    }
}
вот , это весь код который отвечает за отрисовку брони
 
Назад
Сверху