Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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();

}

}

 

 

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

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.