Jump to content

[SOLVED]IItemRenderer not rendering EQUIPPED and EQUIPPED_FIRST_PERSON texture!


lorizz

Recommended Posts

Hi guys I'm lorizz and I need to know why my IItemRenderer class, that is used for a class EXTENDING TO A SWORD, doesn't render my texture in case of EQUIPPED and EQUIPPED_FIRST_PERSON, if I don't use those it renders the texture normally but I need to move the model, so this is why I use IItemRenderer (I use it for another reason that you will may find in my code)!

This is the IItemRenderer class:

package it.exoworld_client.renderer;

import it.exoworld_client.ExoWorld_Client;
import it.exoworld_client.extender.ItemDaggerExtender;
import it.exoworld_client.registry.ItemRegistry;
import it.exoworld_client.watcher.PlayerInformation;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraftforge.client.IItemRenderer;

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

import cpw.mods.fml.client.FMLClientHandler;

public class ItemDaggerRenderer implements IItemRenderer {

private static RenderItem renderItem = new RenderItem();
private Minecraft mc;

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	// TODO Auto-generated method stub
	return type == ItemRenderType.INVENTORY
			|| type == ItemRenderType.EQUIPPED
			|| type == ItemRenderType.EQUIPPED_FIRST_PERSON;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,
		ItemRendererHelper helper) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	EntityLiving entity = (EntityLiving) data[1];
	ItemRenderer itemRenderer = this.mc.entityRenderer.itemRenderer;
	PlayerInformation props = PlayerInformation.get(Minecraft
			.getMinecraft().thePlayer);
	ItemDaggerExtender dagger = (ItemDaggerExtender) item.getItem();
	int selectedClass = props.getSelectedClass();
	int classConfirm = props.getClassConfirm();
	Icon daggerIcon = dagger.getIconIndex(item);
	Icon daggerWrongClass = ItemRegistry.daggerWrongClass
			.getIconIndex(item);
	if (type == ItemRenderType.INVENTORY) {
		if (classConfirm != 1 && selectedClass != 1) {
			this.renderItem.renderIcon(0, 0, daggerWrongClass, 16, 16);
		} else {
			this.renderItem.renderIcon(0, 0, daggerIcon, 16, 16);
		}
	}
	GL11.glPushMatrix();
	FMLClientHandler.instance().getClient().renderEngine
			.bindTexture("/mods/" + ExoWorld_Client.modid
					+ "/textures/items/dagger/"
					+ dagger.getUnlocalizedName().substring(5) + ".png");
	if(type == ItemRenderType.EQUIPPED) {

	} else if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) {

	}
	GL11.glPopMatrix();
}
}

 

I tried using "Minecraft.getMinecraft().renderEngine.bindTexture()" method but still not working, also I tried using tessellator...crash because of "EntityLiving entity = (EntityLiving) data[1];" and I don't know why, it tells me "ArrayIndexOutOfBounds".

Who can help me? Maybe it doesn't work because it's used for a class that extends to a custom extender that extends to an ItemSword? Does my extender need to extends to an Item? I can make my own ItemSword if I need so.

Thanks! (I'm italian sorry for my bad english...if I made some grammar mistakes)

Link to comment
Share on other sites

Hi

 

You may find this link useful

http://greyminecraftcoder.blogspot.com.au/2013/09/custom-item-rendering-using.html

and some sample code

http://greyminecraftcoder.blogspot.com.au/2013/09/sample-code-for-rendering-items.html

 

I'd say the crash is because the caller doesn't always pass an entity in data.  That's why it's got a variable argument list Object... after all.

 

Do you even need the EntityLiving?

 

-TGG

 

Link to comment
Share on other sites

I used the EntityLiving for tessellator, but if it crashes...

EDIT: I have no idea on how to do that, I tried with this.renderItem(); method but it crashes when I equip it! How can I do that? I don't understand at all the code you gave to me

Link to comment
Share on other sites

I used the EntityLiving for tessellator, but if it crashes...

EDIT: I have no idea on how to do that, I tried with this.renderItem(); method but it crashes when I equip it! How can I do that? I don't understand at all the code you gave to me

 

So...you use the EntityLiving to get the ItemRenderer, which you then don't use...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You also don't need to get the Tessellator from an entity:

 

Tessallator.instance

 

Magic.

 

The better question is:

What are you trying to do?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Are you doing something that requires the item to not render as a default item?

If so, what?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

This is what I wanted to do:

1)Creating an item normally;

2)Changing position and angles of the render in First Person and Third Person.

 

From point 2 I created an IItemRenderer for the angles and position, but when I wrote "case EQUIPPED" or "case EQUIPPED_FIRST_PERSON" the texture's gone...I don't know why, the player has nothing in hand! I can't fix/render this!

Link to comment
Share on other sites

From point 2 I created an IItemRenderer for the angles and position, but when I wrote "case EQUIPPED" or "case EQUIPPED_FIRST_PERSON" the texture's gone...I don't know why, the player has nothing in hand! I can't fix/render this!

 

You mean these lines?

 

		if(type == ItemRenderType.EQUIPPED) {

	} else if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) {

	}

 

First off, those aren't case statements.

Second, duh.  You're not doing anything.

 

Anyway, you can bind textures through the TextureManager passed as data[1] (the player is data[0] by the way) and ItemRenderer.renderItemIn2D will render an item.  If that doesn't work you can create a fake ItemEntity and render that instead using RenderManager.instance.renderEntityWithPosYaw

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ok, I think I made for myself, but I got an ArrayIndexOutsOfExceptions crash on "EntityLiving entity = (EntityLiving) data[1];"

 

package it.exoworld_client.renderer;

import it.exoworld_client.ExoWorld_Client;
import it.exoworld_client.extender.ItemDaggerExtender;
import it.exoworld_client.registry.ItemRegistry;
import it.exoworld_client.watcher.PlayerInformation;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraftforge.client.IItemRenderer;

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

import cpw.mods.fml.client.FMLClientHandler;

public class ItemDaggerRenderer implements IItemRenderer {

private RenderManager renderManager;
private Minecraft mc;

public ItemDaggerRenderer() {
	this.renderManager = RenderManager.instance;
	this.mc = Minecraft.getMinecraft();
}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	return (type == ItemRenderType.INVENTORY
			|| 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]; //Here, WHY I CRASH!
	ItemRenderer irInstance = this.mc.entityRenderer.itemRenderer;
	PlayerInformation props = PlayerInformation.get(Minecraft
			.getMinecraft().thePlayer);
	ItemDaggerExtender dagger = (ItemDaggerExtender) item.getItem();
	int selectedClass = props.getSelectedClass();
	int classConfirm = props.getClassConfirm();
	Icon daggerIcon = dagger.getIconIndex(item);
	Icon daggerWrongClass = ItemRegistry.daggerWrongClass
			.getIconIndex(item);
	if (type == ItemRenderType.INVENTORY) {
		if (classConfirm != 1 && selectedClass != 1) {
			RenderItem renderItem = new RenderItem();
			renderItem.renderIcon(0, 0, daggerWrongClass, 16, 16);
		} else {
			RenderItem renderItem = new RenderItem();
			renderItem.renderIcon(0, 0, daggerIcon, 16, 16);
		}
	}
	GL11.glPushMatrix();
	if (type == ItemRenderType.EQUIPPED) {
		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);
	} else if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
		this.renderItem(entity, item, 0);
	}
	GL11.glPopMatrix();
}

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.bindTexture("/terrain.png");
	} else {
		this.mc.renderEngine.bindTexture("/gui/items.png");
	}

	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.bindTexture("%blur%/misc/glint.png");
		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);
}
}

 

How can I fix that problem?

Link to comment
Share on other sites

do this:

 

if(data.length < 2) { return; }

 

See if that helps.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • where opportunities abound and promises of financial prosperity beckon from every corner of the internet, the line between opportunity and deception becomes increasingly blurred. As a 38-year-old single mom, I embarked on a journey into the world of cryptocurrency investing, hoping to secure a brighter future for myself and my family. Little did I know, this journey would lead me down a treacherous path fraught with deception and heartbreak. My foray into cryptocurrency investing began with the promise of lucrative returns from a platform claiming to operate within Europe and South Asia. Blinded by optimism and the allure of financial gain, I entrusted my hard-earned savings to this fraudulent company, believing wholeheartedly in its legitimacy. However, my hopes were dashed when I began encountering difficulties with withdrawals and found myself entangled in a web of exorbitant fees and dubious practices. In a desperate bid to salvage what remained of my investment, I turned to a recovery company recommended to me by the very platform that had deceived me. Yet, even in my darkest hour, the deceit persisted, as I soon discovered that the company tasked with recovering my funds was complicit in the deception. Faced with the crushing realization that I had been betrayed once again, I felt a sense of hopelessness engulf me. It was in this moment of despair that I stumbled upon Lee Ultimate Hacker – a shining beacon of hope amidst the darkness of deception. Through a stroke of luck, I came across a blog post singing the praises of this remarkable team, and I knew I had found my savior. With nothing left to lose and everything to gain, I reached out to them, hoping against hope for a chance at redemption. From the outset, Lee Ultimate Hacker proved to be a guiding light in my journey toward financial recovery. Their professionalism, expertise, and unwavering commitment to client satisfaction set them apart from the myriad of recovery services in the digital sphere. With empathy and understanding, they listened to my story and embarked on a mission to reclaim what was rightfully mine. Through their diligent efforts and meticulous attention to detail, Lee Ultimate Hacker succeeded where others had failed, restoring a sense of hope and security in the wake of betrayal. Their dedication to justice and unwavering determination to deliver results ensured that I emerged from the ordeal stronger and more resilient than ever before. Throughout the recovery process, their team remained accessible, transparent, and supportive, offering guidance and reassurance every step of the way. To anyone grappling with devastating financial fraud, I offer a lifeline of hope – trust in Lee Ultimate Hacker to guide you through the storm with expertise and compassion. In a world rife with deception and uncertainty, they stand as a beacon of reliability and trustworthiness, ready to lead you toward financial restitution and a brighter future. If you find yourself in a similar predicament, do not hesitate to reach out to Lee Ultimate Hacker.AT LEEULTIMATEHACKER@ AOL. COM   Support @ leeultimatehacker . com.  telegram:LEEULTIMATE   wh@tsapp +1  (715) 314  -  9248  https://leeultimatehacker.com
    • Sorry, this is the report https://paste.ee/p/OeDj1
    • Please share a link to your crash report on https://paste.ee, as explained in the FAQ
    • This is the crash report [User dumped their crash report directly in their thread, triggering the anti-spam]  
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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