Jump to content

[SOLVED]IItemRenderer not rendering EQUIPPED and EQUIPPED_FIRST_PERSON texture!


Recommended Posts

Posted

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)

Posted

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

 

Posted

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

Posted

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.

Posted

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.

Posted

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.

Posted

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!

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

Posted

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?

Posted

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.

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.