Jump to content

[SOLVED] Help with armour rendering


PegBeard

Recommended Posts

I have followed several tutorials and I have my armour working as intended, the only issue is - when worn, the armour is not being displayed on the player.

The item icons work properly, and MC recognises each armour piece as either helmet, boots, etc. But I can't work out why the armour is not displayed on the player when worn.

 

This is the code I am using, based on the tutorials I have followed. This is for 1.7.10 and it is the first time I have tried to do armour.

 

@Override
@SideOnly(Side.CLIENT)
public String getArmorTexture(ItemStack par1ItemStack, Entity par2Entity, int slot, String type)
{
	if (par1ItemStack.getItem() == DungeonTacticsItems.goldplateHelmet || par1ItemStack.getItem() == DungeonTacticsItems.goldplateChestplate || par1ItemStack.getItem() == DungeonTacticsItems.goldplateBoots)
	{
		return Reference.MOD_ID.toLowerCase() + ":textures/armor/" + Names.Armor.GOLDPLATE_ARMOR + "_layer_1.png";
	}
	if (par1ItemStack.getItem() == DungeonTacticsItems.goldplateLeggings);
	{
		return Reference.MOD_ID.toLowerCase() + ":textures/armor/" + Names.Armor.GOLDPLATE_ARMOR + "_layer_2.png";
	}
}

 

 

In my client proxy I have 'registerRenderThings', for registering some entities, but none of the tutorials have mentioned using that for rendering the armour on the player. Not sure if that is relevant or not.

 

Also, I get this in the system log, when I open the inventory with the armour equipped.

 

[20:14:31] [Client thread/ERROR]: Couldn't render entity

java.lang.ArrayIndexOutOfBoundsException: 27

at net.minecraft.client.renderer.entity.RenderBiped.getArmorResource(RenderBiped.java:408) ~[RenderBiped.class:?]

at net.minecraft.client.renderer.entity.RenderPlayer.shouldRenderPass(RenderPlayer.java:70) ~[RenderPlayer.class:?]

at net.minecraft.client.renderer.entity.RenderPlayer.shouldRenderPass(RenderPlayer.java:517) ~[RenderPlayer.class:?]

at net.minecraft.client.renderer.entity.RendererLivingEntity.doRender(RendererLivingEntity.java:173) [RendererLivingEntity.class:?]

at net.minecraft.client.renderer.entity.RenderPlayer.doRender(RenderPlayer.java:167) [RenderPlayer.class:?]

at net.minecraft.client.renderer.entity.RenderPlayer.doRender(RenderPlayer.java:565) [RenderPlayer.class:?]

at net.minecraft.client.renderer.entity.RenderManager.func_147939_a(RenderManager.java:300) [RenderManager.class:?]

at net.minecraft.client.renderer.entity.RenderManager.renderEntityWithPosYaw(RenderManager.java:283) [RenderManager.class:?]

at net.minecraft.client.gui.inventory.GuiInventory.func_147046_a(GuiInventory.java:112) [GuiInventory.class:?]

at net.minecraft.client.gui.inventory.GuiContainerCreative.drawGuiContainerBackgroundLayer(GuiContainerCreative.java:839) [GuiContainerCreative.class:?]

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:93) [GuiContainer.class:?]

at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:44) [inventoryEffectRenderer.class:?]

at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:673) [GuiContainerCreative.class:?]

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137) [EntityRenderer.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1068) [Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]

at GradleStart.main(Unknown Source) [start/:?]

 

Link to comment
Share on other sites

Armour class

 

public class ArmorGoldplate extends ItemArmor
{
    public ArmorGoldplate(ArmorMaterial par1ArmorMaterial, int par2Int, int par3Int)
    {
        super(Material.Armor.GOLDPLATE, par2Int, par3Int);
	this.setUnlocalizedName(Names.Armor.GOLDPLATE_ARMOR);
        this.setCreativeTab(DungeonTacticsCreativeTab.DUNGEONTACTICS_TAB);
}

@Override
public String getUnlocalizedName()
{
	return String.format("item.%s%s", Reference.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
}

@Override
public String getUnlocalizedName(ItemStack ItemStack)
{
	return String.format("item.%s%s", Reference.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
}

protected String getUnwrappedUnlocalizedName(String unlocalizedName)
{
	return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
}

    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister iconRegister)
    {
        itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".") + 1));
    }

@Override
@SideOnly(Side.CLIENT)
public String getArmorTexture(ItemStack par1ItemStack, Entity par2Entity, int slot, String type)
{
	if (par1ItemStack.getItem() == DungeonTacticsItems.goldplateHelmet || par1ItemStack.getItem() == DungeonTacticsItems.goldplateChestplate || par1ItemStack.getItem() == DungeonTacticsItems.goldplateBoots)
	{
		return Reference.MOD_ID.toLowerCase() + ":textures/armor/" + Names.Armor.GOLDPLATE_ARMOR + "_layer_1.png";
	}
	if (par1ItemStack.getItem() == DungeonTacticsItems.goldplateLeggings);
	{
		return Reference.MOD_ID.toLowerCase() + ":textures/armor/" + Names.Armor.GOLDPLATE_ARMOR + "_layer_2.png";
	}
}
}

 

 

Item register

 

@GameRegistry.ObjectHolder(Reference.MOD_ID)
public class DungeonTacticsItems
{
public static Item goldplateHelmet = new ArmorGoldplate(Material.Armor.GOLDPLATE, 27, 0).setUnlocalizedName(Names.Armor.GOLDPLATE_HELMET);
public static Item goldplateChestplate = new ArmorGoldplate(Material.Armor.GOLDPLATE, 28, 1).setUnlocalizedName(Names.Armor.GOLDPLATE_CHESTPLATE);
public static Item goldplateLeggings = new ArmorGoldplate(Material.Armor.GOLDPLATE, 29, 2).setUnlocalizedName(Names.Armor.GOLDPLATE_LEGGINGS);
public static Item goldplateBoots = new ArmorGoldplate(Material.Armor.GOLDPLATE, 30, 3).setUnlocalizedName(Names.Armor.GOLDPLATE_BOOTS);

public static void Init()
{
	GameRegistry.registerItem(goldplateHelmet, Names.Armor.GOLDPLATE_HELMET);
	GameRegistry.registerItem(goldplateChestplate, Names.Armor.GOLDPLATE_CHESTPLATE);
	GameRegistry.registerItem(goldplateLeggings, Names.Armor.GOLDPLATE_LEGGINGS);
	GameRegistry.registerItem(goldplateBoots, Names.Armor.GOLDPLATE_BOOTS);
}
}

 

 

Main class

 

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)

public class DungeonTactics
{

@Mod.Instance (Reference.MOD_ID)
public static DungeonTactics instance;

@SidedProxy (clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static IProxy proxy;

@Mod.EventHandler
public void preInitialize (FMLPreInitializationEvent event)
{
	FMLCommonHandler.instance().bus().register(event);
    	MinecraftForge.EVENT_BUS.register(event);
    	DungeonTacticsItems.Init();
}

@Mod.EventHandler
public void initialize (FMLInitializationEvent event)
{
	proxy.registerRenderThings();
	proxy.registerSounds();
	DungeonTacticsEntities.Init();
	DungeonTacticsShapedRecipes.Init();
	DungeonTacticsShapelessRecipes.Init();
}

@Mod.EventHandler
public void postInitialization (FMLPostInitializationEvent event)
{

}
}

 

 

I don't have my own renderer, because none of the tutorials I followed even hinted that I needed one, and I don't call a vanilla renderer specifically for the armour for the same reason.

I am presuming that is the problem, but I am still unfamiliar with many methods, as I'm still fairly new to MC modding (and never done armour before).

Link to comment
Share on other sites

The issue is in this and the other 3 lines of code.

public static Item goldplateHelmet = new ArmorGoldplate(Material.Armor.GOLDPLATE, 27, 0).setUnlocalizedName(Names.Armor.GOLDPLATE_HELMET);

You should have looked into the ItemArmor class before you started tossing in arguments for the hell of it. That argument is not item id or armor id, it is the render id.

Here is the comment for the integer as found in ItemArmor.class.

 

Used on RenderPlayer to select the correspondent armor to be rendered on the player: 0 is cloth, 1 is chain, 2 is

iron, 3 is diamond and 4 is gold.

 

Link to comment
Share on other sites

Based on more than one tutorial, I was under the impression that in "(Material.Armor.GOLDPLATE, 27, 0)" was "amour material, unique model id, armourslot(helmet, boots, etc.)".

From what you say, I presume, if I change the '27' to '0' my armour would render as vanilla cloth armour? or would it render my specified textures?

 

I do apologise for what is probably a dumb question, but I'm still fairly new to making an MC mod and just lack some experience.

Link to comment
Share on other sites

Haha. I can't believe it was something simple. I'll admit, I probably misunderstood one of the tutorials I used, but the trouble I find is that most people tell you what to do and not why.

Never the less, it is working now. Thank you. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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