Jump to content

[1.7.10]Need help with custom IItemRenderer


Jedispencer21

Recommended Posts

So I'm new to the whole item rendering. I have done some changes with the code, if anyone could help with it, that would be nice:

 

 

 

package com.feudalcraft.client.render.items;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.ItemRenderer;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.client.renderer.texture.TextureManager;

import net.minecraft.client.renderer.texture.TextureMap;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.item.EntityItem;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.IItemRenderer;

 

import org.lwjgl.opengl.GL11;

 

import com.feudalcraft.blocksitems.ItemLightCrossbow;

 

import cpw.mods.fml.client.FMLClientHandler;

 

public class RenderItemLightCrossbow implements IItemRenderer

{

private Minecraft mcinstance = FMLClientHandler.instance().getClient();

 

@Override

public boolean handleRenderType(ItemStack item, IItemRenderer.ItemRenderType type)

{

return type == IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON || type == IItemRenderer.ItemRenderType.EQUIPPED;

}

 

@Override

public boolean shouldUseRenderHelper(IItemRenderer.ItemRenderType type, ItemStack item, IItemRenderer.ItemRendererHelper helper)

{

return true;

}

 

@Override

public void renderItem(IItemRenderer.ItemRenderType type, ItemStack item, Object... data)

{

if ((type == IItemRenderer.ItemRenderType.EQUIPPED) || (type == IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON))

{

if (!(item.getItem() instanceof ItemLightCrossbow))

{

return;

}

 

ItemLightCrossbow crossbow = (ItemLightCrossbow)item.getItem();

 

EntityPlayer entity = (EntityPlayer)data[1];

float i2 = 0.0F;

float translation = -1.5F;

 

if ((entity.inventory.getCurrentItem() == null) || (!(entity.inventory.getCurrentItem().getItem() instanceof ItemLightCrossbow)))

{

return;

}

 

GL11.glPushMatrix();

 

if (i2 < 0.0F)

{

i2 = 0.0F;

}

 

if (type == IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON)

{

GL11.glTranslatef(0.0F, -(Math.abs(i2) / 2.0F), 0.0F);

 

if (entity.getItemInUseCount() > 0)

{

GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);

GL11.glRotatef(-77.0F, 0.0F, 0.0F, 1.0F);

GL11.glRotatef(-44.0F, 0.0F, 1.0F, 0.0F);

GL11.glTranslatef(-0.9F, -1.2F, -0.85F);

GL11.glRotatef(15.0F, 0.0F, 0.0F, 1.0F);

GL11.glTranslatef(0.1F, -0.25F, 0.08F);

}

 

if (entity.inventory.getCurrentItem().getItem() instanceof ItemLightCrossbow)

{

GL11.glRotatef(10.0F, 0.0F, 0.0F, 0.0F);

GL11.glTranslatef(0.3F, 0.515F, 0.5F);

}

}

else

{

GL11.glTranslatef(0.7F, 0.225F, 0.6125F);

GL11.glRotatef(-40.0F, 0.0F, 1.0F, 0.0F);

GL11.glRotatef(-110.0F, 1.0F, 0.0F, 0.0F);

GL11.glTranslatef(0.1F, -0.9F, 0.15F);

GL11.glRotatef(60.0F, 0.0F, 1.0F, 0.0F);

GL11.glScalef(1.3F, 1.3F, 1.3F);

}

 

renderItemCustom(type, item, data);

GL11.glPopMatrix();

GL11.glPushMatrix();

 

float f28 = item.getMaxItemUseDuration() - (entity.getItemInUseCount() - 1.0F + 1.0F);

float f32 = f28 / 50.0F;

f32 = (f32 * f32 + f32 * 2.0F) / 3.0F;

 

if (f32 > 1.0F)

{

f32 = 1.0F;

}

 

if (type == IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON)

{

GL11.glRotatef(-330.0F, 0.0F, 0.0F, 1.0F);

GL11.glRotatef(-50.0F, 0.0F, 1.0F, 0.0F);

GL11.glRotatef(1.0F, 1.0F, 0.0F, 0.0F);

GL11.glTranslatef(0.0F, 0.5F, 0.15F);

GL11.glTranslatef(0.0F, 0.05F, -0.25F);

GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);

GL11.glRotatef(331.0F, 0.0F, 0.0F, 1.0F);

GL11.glRotatef(2.0F, 1.0F, 0.0F, 1.0F);

GL11.glScalef(0.7F, 0.7F, 0.7F);

 

if (entity.inventory.getCurrentItem().getItem() instanceof ItemLightCrossbow)

{

GL11.glRotatef(83.0F, 1.0F, 0.0F, 0.0F);

GL11.glRotatef(-62.0F, 0.0F, 0.0F, 1.0F);

GL11.glRotatef(-45.0F, 0.0F, 1.0F, 0.0F);

GL11.glTranslatef(-1.5F, -1.22F, -0.7F);

}

}

else

{

GL11.glTranslatef(0.7F, 0.225F, 0.6125F);

GL11.glRotatef(-40.0F, 0.0F, 1.0F, 0.0F);

GL11.glRotatef(-110.0F, 1.0F, 0.0F, 0.0F);

GL11.glTranslatef(0.05F, -0.7F, 0.15F);

GL11.glRotatef(60.0F, 0.0F, 1.0F, 0.0F);

GL11.glScalef(1.3F, 1.3F, 1.3F);

}

GL11.glPopMatrix();

}

}

 

private void renderItemCustom(IItemRenderer.ItemRenderType type, ItemStack item, Object[] data)

{

int i = 0;

EntityLivingBase entity = (EntityLivingBase)data[1];

GL11.glPushMatrix();

 

Tessellator tes = Tessellator.instance;

IIcon icon = entity.getItemIcon(item, i);

 

float f = ((IIcon)icon).getMinU();

float f1 = ((IIcon)icon).getMaxU();

float f2 = ((IIcon)icon).getMinV();

float f3 = ((IIcon)icon).getMaxV();

 

float j = 0.1F;

float l = 0.3F;

        GL11.glEnable(32826);

GL11.glTranslatef(-j, -l, 0.0F);

float m = 1.5F;

GL11.glScalef(m, m, m);

GL11.glRotatef(60.0F, 0.0F, 1.0F, 0.0F);

GL11.glRotatef(330.0F, 0.0F, 0.0F, 1.0F);

GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);

        ItemRenderer.renderItemIn2D(tes, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 0.0625F);

 

        GL11.glDisable(32826);

 

GL11.glPopMatrix();

}

}

 

 

Link to comment
Share on other sites

Hi

 

Your renderItem method calls itself

 

renderItem(type, item, data);

 

which then calls itself, which calls itself, which calls itself, etc until you run out of stack space.

 

that renderItem call should be to something which actually draws the icon.

 

There seems to be a bunch of unused code in there.  What is it all supposed to be doing?

 

-TGG

 

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.



×
×
  • Create New...

Important Information

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