Jump to content

Recommended Posts

Posted

A while back I with the help of people here figured out a way to render bows properly when held by other players/monsters. Unfortunately when the 1.6 update came rolling out I ran into a few problems with it. first, when I run the mod and pick out a bow, it throws this error.

 

 
java.lang.ClassCastException: net.minecraft.client.entity.EntityClientPlayerMP cannot be cast to net.minecraft.entity.EntityLiving
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at mod_Rareores.RenderBow.renderItem(RenderBow.java:40)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraftforge.client.ForgeHooksClient.renderEquippedItem(ForgeHooksClient.java:201)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.ItemRenderer.renderItem(ItemRenderer.java:89)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.ItemRenderer.renderItemInFirstPerson(ItemRenderer.java:490)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.EntityRenderer.renderHand(EntityRenderer.java:712)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1292)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1006)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:934)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:826)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.client.main.Main.main(Main.java:93)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at java.lang.reflect.Method.invoke(Unknown Source)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.launchwrapper.Launch.launch(Launch.java:57)
2013-07-10 15:41:26 [iNFO] [sTDERR] 	at net.minecraft.launchwrapper.Launch.main(Launch.java:18)

 

Instantly I see it is a classcast exception, so I look into IItemRenderer to figure out how to fix this, this is the data I am given.

Data parameters:

        * RenderBlocks render - The RenderBlocks instance[0]

        * EntityLiving entity - The entity holding this item[1]

 

I don't get it, why when I'm given an entityLiving data is it throwing an exception when Im making an entityliving parameter? at

EntityLiving entity = (EntityLiving) data[1];

 

I am stumped here and could use some help.

 

Secondly, What have icon.getSheetWidth() & icon.getSheetHeight() been replaced with?

 

My class file

package mod_Rareores;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class RenderBow implements IItemRenderer {
    private RenderManager renderManager;
private Minecraft mc;
public static final ResourceLocation RESOURCELOCATION = new ResourceLocation("/terrain.png");
public static final ResourceLocation RESOURCELOCATION2 = new ResourceLocation("/gui/items.png");
public static final ResourceLocation RESOURCELOCATION3 = new ResourceLocation("%blur%/misc/glint.png");
public RenderBow() {
	this.renderManager = RenderManager.instance;
	this.mc = Minecraft.getMinecraft();
}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	return type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
	return false;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	EntityLiving entity = (EntityLiving) data[1];
	ItemRenderer irInstance = this.mc.entityRenderer.itemRenderer;

	GL11.glPopMatrix();
	if(type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
		this.renderItem(entity, item, 0);
	} else {
		GL11.glPushMatrix();


            float f2 = 3F - (1F/3F);
            GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F);
            GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(-60.0F, 0.0F, 0.0F, 1.0F);
            GL11.glScalef(f2, f2, f2);
            GL11.glTranslatef(-0.25F, -0.1875F, 0.1875F);
            
          
            float f3 = 0.625F;
            GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
            GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
            GL11.glScalef(f3, -f3, f3);
            GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
            
		this.renderItem(entity, item, 0);
		GL11.glPopMatrix();
	}
	GL11.glPushMatrix(); 

private void renderItem(EntityLiving par1EntityLiving, ItemStack par2ItemStack, int par3) {
	Icon icon = par1EntityLiving.getItemIcon(par2ItemStack, par3);

        if (icon == null)
        {
            return;
        }

        if (par2ItemStack.getItemSpriteNumber() == 0)
        {
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION);
        }
        else
        {
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION2);
        }

        Tessellator tessellator = Tessellator.instance;
        float f = icon.getMinU();
        float f1 = icon.getMaxU();
        float f2 = icon.getMinV();
        float f3 = icon.getMaxV();
        float f4 = 0.0F;
        float f5 = 0.3F;
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glTranslatef(-f4, -f5, 0.0F);
        float f6 = 1.5F;
        GL11.glScalef(f6, f6, f6);
        GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
        GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
        ItemRenderer.renderItemIn2D(tessellator, f1, f2, f, f3, icon.getSheetWidth(), icon.getSheetHeight(), 0.0625F);

        if (par2ItemStack != null && par2ItemStack.hasEffect() && par3 == 0)
        {
            GL11.glDepthFunc(GL11.GL_EQUAL);
            GL11.glDisable(GL11.GL_LIGHTING);
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION3);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
            float f7 = 0.76F;
            GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F);
            GL11.glMatrixMode(GL11.GL_TEXTURE);
            GL11.glPushMatrix();
            float f8 = 0.125F;
            GL11.glScalef(f8, f8, f8);
            float f9 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
            GL11.glTranslatef(f9, 0.0F, 0.0F);
            GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
            GL11.glPopMatrix();
            GL11.glPushMatrix();
            GL11.glScalef(f8, f8, f8);
            f9 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
            GL11.glTranslatef(-f9, 0.0F, 0.0F);
            GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
            GL11.glPopMatrix();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glDepthFunc(GL11.GL_LEQUAL);
        }

        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
}

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Cast it to be an EntityLiving

EntityLiving entity = (EntityLiving)entityLivingBase

 

*headbash*

That variable CANNOT be Entityliving! The method Renderitem takes AN EntityLiving, which cannot be taken from data[1].

YES is can be casted to EntityLivingBase but Not EntityLiving.

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Yeah but this.renderItem takes an entityliving.

 

Then change the parameter type of it to EntityLivingBase. Overall, it's your method ;)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Okay figured out how to fix it!

 

First this is your starting class.

 

package mod_Rareores;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class RenderBow implements IItemRenderer {
    private RenderManager renderManager;
private Minecraft mc;
public static final ResourceLocation RESOURCELOCATION = new ResourceLocation("/terrain.png");
public static final ResourceLocation RESOURCELOCATION2 = new ResourceLocation("/gui/items.png");
public static final ResourceLocation RESOURCELOCATION3 = new ResourceLocation("%blur%/misc/glint.png");
public RenderBow() {
	this.renderManager = RenderManager.instance;
	this.mc = Minecraft.getMinecraft();
}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	return type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
	return false;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	EntityLiving entity = (EntityLiving) data[1];
	ItemRenderer irInstance = this.mc.entityRenderer.itemRenderer;

	GL11.glPopMatrix();
	if(type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
		this.renderItem(entity, item, 0);
	} else {
		GL11.glPushMatrix();


            float f2 = 3F - (1F/3F);
            GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F);
            GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(-60.0F, 0.0F, 0.0F, 1.0F);
            GL11.glScalef(f2, f2, f2);
            GL11.glTranslatef(-0.25F, -0.1875F, 0.1875F);
            
          
            float f3 = 0.625F;
            GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
            GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
            GL11.glScalef(f3, -f3, f3);
            GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
            
		this.renderItem(entity, item, 0);
		GL11.glPopMatrix();
	}
	GL11.glPushMatrix(); 

private void renderItem(EntityLiving par1EntityLiving, ItemStack par2ItemStack, int par3) {
	Icon icon = par1EntityLiving.getItemIcon(par2ItemStack, par3);

        if (icon == null)
        {
            return;
        }

        if (par2ItemStack.getItemSpriteNumber() == 0)
        {
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION);
        }
        else
        {
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION2);
        }

        Tessellator tessellator = Tessellator.instance;
        float f = icon.getMinU();
        float f1 = icon.getMaxU();
        float f2 = icon.getMinV();
        float f3 = icon.getMaxV();
        float f4 = 0.0F;
        float f5 = 0.3F;
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glTranslatef(-f4, -f5, 0.0F);
        float f6 = 1.5F;
        GL11.glScalef(f6, f6, f6);
        GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
        GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
        ItemRenderer.renderItemIn2D(tessellator, f1, f2, f, f3, icon.getSheetWidth(), icon.getSheetHeight(), 0.0625F);

        if (par2ItemStack != null && par2ItemStack.hasEffect() && par3 == 0)
        {
            GL11.glDepthFunc(GL11.GL_EQUAL);
            GL11.glDisable(GL11.GL_LIGHTING);
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION3);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
            float f7 = 0.76F;
            GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F);
            GL11.glMatrixMode(GL11.GL_TEXTURE);
            GL11.glPushMatrix();
            float f8 = 0.125F;
            GL11.glScalef(f8, f8, f8);
            float f9 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
            GL11.glTranslatef(f9, 0.0F, 0.0F);
            GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
            GL11.glPopMatrix();
            GL11.glPushMatrix();
            GL11.glScalef(f8, f8, f8);
            f9 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
            GL11.glTranslatef(-f9, 0.0F, 0.0F);
            GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
            GL11.glPopMatrix();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glDepthFunc(GL11.GL_LEQUAL);
        }

        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
}

First change this line of code so that An EntityLivingBase Parameter is taken from data, like this.

EntityLiving entity = (EntityLiving) data[1]; to

EntityLivingBase entity = (EntityLivingBase) data[1];

 

Then change the renderItem method below so it uses EntityLivingBase

private void renderItem(EntityLiving par1EntityLiving, ItemStack par2ItemStack, int par3)

to

private void renderItem(EntityLivingBase par1EntityLiving, ItemStack par2ItemStack, int par3)

Now the castclassException is gone,but there are still a few problems.

 

First, change icon.getSheetWidth() & icon.getSheetHeight() in the renderIN2D line to

icon.getOriginX(),  icon.getOriginY()

 

Then make a new resource like the one below

 

public static final ResourceLocation RESOURCELOCATION = new ResourceLocation("textures/misc/enchanted_item_glint.png");

and replace the following line

bindTexture("%blur%/misc/glint.png")

with

this.mc.renderEngine.func_110577_a(RESOURCELOCATION);

 

Finally, delete the entire chunk of code that looks like this

if (par2ItemStack.getItemSpriteNumber() == 0)
        {
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION);
        }
        else
        {
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION2);
        }

Your done! I double checked and it works with enchantments and other monsters/players!

 

Your final class should look like this


package mod_Rareores;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class RenderBow implements IItemRenderer {
    private RenderManager renderManager;
private Minecraft mc;

public static final ResourceLocation RESOURCELOCATION = new ResourceLocation("textures/misc/enchanted_item_glint.png");
public RenderBow() {
	this.renderManager = RenderManager.instance;
	this.mc = Minecraft.getMinecraft();
}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	return type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
	return false;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	EntityLivingBase entity = (EntityLivingBase) data[1];

	ItemRenderer irInstance = this.mc.entityRenderer.itemRenderer;

	GL11.glPopMatrix(); 
	if(type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
		this.renderItem(entity, item, 0);
	} else {
		GL11.glPushMatrix();


            float f2 = 3F - (1F/3F);
            GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F);
            GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(-60.0F, 0.0F, 0.0F, 1.0F);
            GL11.glScalef(f2, f2, f2);
            GL11.glTranslatef(-0.25F, -0.1875F, 0.1875F);
            
            // render the item as 'real' bow
            float f3 = 0.625F;
            GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
            GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
            GL11.glScalef(f3, -f3, f3);
            GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
            
		this.renderItem(entity, item, 0);
		GL11.glPopMatrix();
	}
	GL11.glPushMatrix();
}

private void renderItem(EntityLivingBase par1EntityLiving, ItemStack par2ItemStack, int par3) {
	Icon icon = par1EntityLiving.getItemIcon(par2ItemStack, par3);

        if (icon == null)
        {
            return;
        }

        

        Tessellator tessellator = Tessellator.instance;
        float f = icon.getMinU();
        float f1 = icon.getMaxU();
        float f2 = icon.getMinV();
        float f3 = icon.getMaxV();
        float f4 = 0.0F;
        float f5 = 0.3F;
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glTranslatef(-f4, -f5, 0.0F);
        float f6 = 1.5F;
        GL11.glScalef(f6, f6, f6);
        GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
        GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
        ItemRenderer.renderItemIn2D(tessellator, f1, f2, f, f3, icon.getOriginX(), icon.getOriginY(), 0.0625F);

        if (par2ItemStack != null && par2ItemStack.hasEffect() && par3 == 0)
        {
            GL11.glDepthFunc(GL11.GL_EQUAL);
            GL11.glDisable(GL11.GL_LIGHTING);
            this.mc.renderEngine.func_110577_a(RESOURCELOCATION);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
            float f7 = 0.76F;
            GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F);
            GL11.glMatrixMode(GL11.GL_TEXTURE);
            GL11.glPushMatrix();
            float f8 = 0.125F;
            GL11.glScalef(f8, f8, f8);
            float f9 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
            GL11.glTranslatef(f9, 0.0F, 0.0F);
            GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
            GL11.glPopMatrix();
            GL11.glPushMatrix();
            GL11.glScalef(f8, f8, f8);
            f9 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
            GL11.glTranslatef(-f9, 0.0F, 0.0F);
            GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
            GL11.glPopMatrix();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glDepthFunc(GL11.GL_LEQUAL);
        }

        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
}

This is the creator of the Rareores mod! Be sure to check it out at

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.