Jump to content

Recommended Posts

Posted

Hi. I created a custom helmet model, but its texture is not displayed correctly. What could be the problem?

Here's the code.

Model

Spoiler
package com.vikings.vikingsmod.entities;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class VikingHelmet extends EntityModel<Entity> {
	public final ModelRenderer Head;
	private final ModelRenderer cube_r1;
	private final ModelRenderer cube_r2;
	private final ModelRenderer cube_r3;
	private final ModelRenderer cube_r4;
	private final ModelRenderer cube_r5;
	private final ModelRenderer cube_r6;
	public final ModelRenderer Body;
	public final ModelRenderer RightArm;
	public final ModelRenderer LeftArm;
	public final ModelRenderer RightLeg;
	public final ModelRenderer LeftLeg;

	public VikingHelmet() {
		textureWidth = 64;
		textureHeight = 64;

		Head = new ModelRenderer(this);
		Head.setRotationPoint(0.0F, 0.0F, 0.0F);
		Head.setTextureOffset(0, 9).addBox(3.5F, -9.0F, -4.0F, 1.0F, 7.0F, 8.0F, 0.0F, false);
		Head.setTextureOffset(20, 9).addBox(4.4F, -6.0F, -4.0F, 1.0F, 4.0F, 8.0F, 0.0F, false);
		Head.setTextureOffset(10, 16).addBox(-5.5F, -6.0F, -4.0F, 1.0F, 4.0F, 8.0F, 0.0F, false);
		Head.setTextureOffset(10, 1).addBox(-3.5F, -9.0F, -4.0F, -1.0F, 7.0F, 8.0F, 0.0F, false);
		Head.setTextureOffset(18, 28).addBox(-5.5F, -8.0F, -2.0F, 1.0F, 4.0F, 4.0F, 0.0F, false);
		Head.setTextureOffset(4, 9).addBox(-8.75F, -6.6F, -3.9F, 1.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(0, 30).addBox(3.7F, -8.0F, -2.0F, 1.0F, 4.0F, 4.0F, 0.0F, false);
		Head.setTextureOffset(23, 15).addBox(7.45F, -6.6F, -3.9F, 1.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(24, 0).addBox(-4.5F, -9.0F, 3.6F, 9.0F, 7.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(27, 27).addBox(-4.5F, -9.0F, -4.5F, 9.0F, 4.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(0, 13).addBox(-1.0F, -8.0F, -4.8F, 2.0F, 3.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(0, 0).addBox(-4.0F, -9.5F, -4.0F, 8.0F, 1.0F, 8.0F, 0.0F, false);
		Head.setTextureOffset(10, 34).addBox(-1.0F, -5.0F, -5.0F, 2.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(32, 23).addBox(3.0F, -5.0F, -5.0F, 2.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(6, 32).addBox(3.0F, -5.0F, 4.0F, 2.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(30, 14).addBox(-5.0F, -5.0F, 4.0F, 2.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(20, 21).addBox(-5.0F, -4.0F, 4.0F, 10.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(0, 28).addBox(-5.0F, -3.0F, 4.0F, 10.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(12, 32).addBox(-5.0F, -5.0F, -5.0F, 2.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(0, 24).addBox(-5.0F, -4.0F, -5.0F, 4.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(6, 30).addBox(-5.0F, -3.0F, -5.0F, 3.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(0, 26).addBox(1.0F, -4.0F, -5.0F, 4.0F, 1.0F, 1.0F, 0.0F, false);
		Head.setTextureOffset(14, 30).addBox(2.0F, -3.0F, -5.0F, 3.0F, 1.0F, 1.0F, 0.0F, false);

		cube_r1 = new ModelRenderer(this);
		cube_r1.setRotationPoint(-0.9F, 5.0F, 0.0F);
		Head.addChild(cube_r1);
		setRotationAngle(cube_r1, 0.0F, -0.3927F, 0.0F);
		cube_r1.setTextureOffset(28, 23).addBox(6.4F, -12.1F, -5.9F, 1.0F, 2.0F, 2.0F, 0.0F, false);

		cube_r2 = new ModelRenderer(this);
		cube_r2.setRotationPoint(-0.9F, 5.0F, 0.0F);
		Head.addChild(cube_r2);
		setRotationAngle(cube_r2, 0.0F, 0.7854F, 0.0F);
		cube_r2.setTextureOffset(0, 4).addBox(4.7F, -12.4F, 3.8F, 2.0F, 2.0F, 2.0F, 0.0F, false);

		cube_r3 = new ModelRenderer(this);
		cube_r3.setRotationPoint(-0.9F, 5.0F, 0.0F);
		Head.addChild(cube_r3);
		setRotationAngle(cube_r3, 0.0F, 0.3927F, 0.0F);
		cube_r3.setTextureOffset(28, 32).addBox(4.5F, -12.7F, 0.8F, 2.0F, 3.0F, 3.0F, 0.0F, false);

		cube_r4 = new ModelRenderer(this);
		cube_r4.setRotationPoint(0.8F, 5.0F, 0.0F);
		Head.addChild(cube_r4);
		setRotationAngle(cube_r4, 0.0F, 0.3927F, 0.0F);
		cube_r4.setTextureOffset(0, 9).addBox(-8.1F, -12.1F, -5.9F, 1.0F, 2.0F, 2.0F, 0.0F, false);

		cube_r5 = new ModelRenderer(this);
		cube_r5.setRotationPoint(0.8F, 5.0F, 0.0F);
		Head.addChild(cube_r5);
		setRotationAngle(cube_r5, 0.0F, -0.7854F, 0.0F);
		cube_r5.setTextureOffset(0, 0).addBox(-6.8F, -12.4F, 3.8F, 2.0F, 2.0F, 2.0F, 0.0F, false);

		cube_r6 = new ModelRenderer(this);
		cube_r6.setRotationPoint(0.8F, 5.0F, 0.0F);
		Head.addChild(cube_r6);
		setRotationAngle(cube_r6, 0.0F, -0.3927F, 0.0F);
		cube_r6.setTextureOffset(30, 8).addBox(-7.1F, -12.7F, 0.8F, 2.0F, 3.0F, 3.0F, 0.0F, false);

		Body = new ModelRenderer(this);
		Body.setRotationPoint(0.0F, 0.0F, 0.0F);
		

		RightArm = new ModelRenderer(this);
		RightArm.setRotationPoint(-5.0F, 2.0F, 0.0F);
		

		LeftArm = new ModelRenderer(this);
		LeftArm.setRotationPoint(5.0F, 2.0F, 0.0F);
		

		RightLeg = new ModelRenderer(this);
		RightLeg.setRotationPoint(-1.9F, 12.0F, 0.0F);
		

		LeftLeg = new ModelRenderer(this);
		LeftLeg.setRotationPoint(1.9F, 12.0F, 0.0F);
		
	}

	@Override
	public void setRotationAngles(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
		//previously the render function, render code was moved to a method below
	}

	@Override
	public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
		Head.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
		Body.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
		RightArm.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
		LeftArm.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
		RightLeg.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
		LeftLeg.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
	}

	public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
		modelRenderer.rotateAngleX = x;
		modelRenderer.rotateAngleY = y;
		modelRenderer.rotateAngleZ = z;
	}
}

 

Item

Spoiler
package com.vikings.vikingsmod.objects.items;

import com.vikings.vikingsmod.VikingsMod;
import com.vikings.vikingsmod.entities.VikingHelmet;
import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.ItemStack;


public class VikingHelmetItem extends ArmorItem {

    private BipedModel<LivingEntity> model = null;

    public VikingHelmetItem(IArmorMaterial p_i48534_1_, EquipmentSlotType p_i48534_2_, Properties p_i48534_3_) {
        super(p_i48534_1_, p_i48534_2_, p_i48534_3_);
    }

    @Override
    public <A extends BipedModel<?>> A getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlotType armorSlot, A _default) {
        if (this.model == null) {
            this.model = new BipedModel<>(1);
            VikingHelmet tempModel = new VikingHelmet();
            model.bipedHead = tempModel.Head;

            model.isSneak = entityLiving.isSneaking();
            model.isSitting = entityLiving.isPassenger();
            model.isChild = entityLiving.isChild();
        }
        return (A) this.model;
    }

    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlotType slot, String type) {
        return VikingsMod.MOD_ID + ":textures/entity/viking_helmet.png";
    }

}

 

Screenshot:

https://ibb.co/YtLT4Xm/

 

Texture:

https://ibb.co/rM2YtvP

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.