Jump to content

Recommended Posts

Posted

I am trying to make a custom rendered tool that will show its model in first and third person. However at the moment it is only showing a blank texture.

 

5qgOd.jpg

 

My ClientProxy is as follows:

package opticraft.proxies;

import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;
import opticraft.entitys.TileEntityBeam;
import opticraft.entitys.TileEntityItemLaser;
import opticraft.entitys.TileEntityLaserDetector;
import opticraft.entitys.TileEntitySolarCollector;
import opticraft.items.LaserWrench;
import opticraft.items.LaserWrenchRenderer;
import opticraft.lib.Ids;
import opticraft.render.BeamRenderer;
import opticraft.render.ItemLaserRenderer;
import opticraft.render.LaserDetectorRenderer;
import opticraft.render.SolarCollectorRenderer;
import cpw.mods.fml.client.registry.ClientRegistry;

public class ClientProxy extends CommonProxy{

@Override
public void initRenderers() {

}

@Override
public void initSounds() {

}

public void registerRenderThings() {
    	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityItemLaser.class, new ItemLaserRenderer());
    	ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySolarCollector.class, new SolarCollectorRenderer());
    	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBeam.class, new BeamRenderer());
    	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserDetector.class, new LaserDetectorRenderer());
    	
    	MinecraftForgeClient.registerItemRenderer(Ids.laserRench, (IItemRenderer)new LaserWrenchRenderer());
}

}

 

LaserWrench Item:

package opticraft.items;

import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import opticraft.lib.Ids;
import opticraft.lib.ModInfo;
import opticraft.lib.Names;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class LaserWrench extends Item{

public LaserWrench(int par1) {
	super(par1);
	setMaxStackSize(1);
	this.setCreativeTab(CreativeTabs.tabTools);
	this.setUnlocalizedName(Names.laserRench_unlocalizedName);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister icon) {
	itemIcon = icon.registerIcon(ModInfo.ID.toLowerCase() + ":" + "Error");
}

@Override
public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase target) {

	return false;
}

@Override
  public int getSpriteNumber() {
    return 0;
  }
}

 

LaserWrench Renderer:

package opticraft.items;

import opticraft.lib.ModInfo;
import opticraft.models.ItemLaserModel;
import opticraft.models.LaserWrenchModel;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

public class LaserWrenchRenderer implements IItemRenderer {

protected LaserWrenchModel model;

public LaserWrenchRenderer() {
	model = new LaserWrenchModel();
}

@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) 
{
	if (type == ItemRenderType.EQUIPPED) {
		RenderBlocks blockRenderer = (RenderBlocks)data[0];
		EntityLiving entity = (EntityLiving)data[1]; // entity holding the item

		GL11.glPushMatrix();
		Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(ModInfo.ID.toLowerCase() + ":textures/items/LaserWrench.png"));

		float scale = 1.4F;
		GL11.glScalef(scale, scale, scale);
		GL11.glRotatef(90, -1, 0, 0);
		GL11.glRotatef(85, 0, 0, 1);
		GL11.glRotatef(180, 0, 1, 0);
		GL11.glRotatef(135, 1, 0, 0);
		GL11.glTranslatef(-0.1F, -0.5F, 0.5F); // Left-Right
		// Forward-Backwards Up-Down
		model.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F,
				0.0625F);

		GL11.glPopMatrix();
	}
}

}

Posted

Hi

 

It looks to me like you're missing the texture for your item (as seen in the hotbar) and the vanilla code is rendering the item in first person.  Does it work ok in third person view?

 

These links might be useful perhaps:

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

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

 

-TGG

Posted

Having added some debug code, it appears that renderItem in the renderer is never getting called. Which is weird, as my code is pretty darn similar in every other aspect.

Posted

Hi

 

    MinecraftForgeClient.registerItemRenderer(Ids.laserRench, (IItemRenderer)new LaserWrenchRenderer());

 

Are you sure that this statement is called and that the ID (laserRench? :-) ) is correct?

 

-TGG

Posted

Okay there are a few things that you'll need to change and it should be working just great :)

Firstly, you'll need shouldUseRenderHelper() to return true, otherwise nothing will render when you ask it to,

Second, change, "(Entity) data[1]", to null, because it doesn't need the entity holding it to render,

Third, your code here should be changed from (I put in the code after the changes I already mentioned)

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) 
{
	if (type == ItemRenderType.EQUIPPED) {			

		GL11.glPushMatrix();
		Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(ModInfo.ID.toLowerCase() + ":textures/items/LaserWrench.png"));

		float scale = 1.4F;
		GL11.glScalef(scale, scale, scale);
		GL11.glRotatef(90, -1, 0, 0);
		GL11.glRotatef(85, 0, 0, 1);
		GL11.glRotatef(180, 0, 1, 0);
		GL11.glRotatef(135, 1, 0, 0);
		GL11.glTranslatef(-0.1F, -0.5F, 0.5F); // Left-Right
		// Forward-Backwards Up-Down
		model.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F,
				0.0625F);

		GL11.glPopMatrix();
	}
}

to

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	GL11.glPushMatrix();
	Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(
			"ModInfo.ID.toLowerCase() + :textures/items/LaserWrench.png"));
	switch (type) {
	case EQUIPPED:
		//scale, rotate, and translate to your liking	
		break;

	case EQUIPPED_FIRST_PERSON:
		//scale, rotate, and translate to your liking
		break;

	default:
		break;

	}

	model.render(null, 0, 0, 0, 0, 0, 0.625F);

	GL11.glPopMatrix();

}

You could use nested if statements if you wanted to I guess, this is just the way that I do mine. The type "EQUIPPED" is only the third person render view which doesn't allow for any other way to be rendered. And having default break makes it not even attempt to render if it's given any other render type. Hope I helped :)

 

Posted

Hi

 

If redphen0nix1' code doesn't work then I would suggest you put a breakpoint here

 

ItemRenderer.
    /**
     * Renders the item stack for being in an entity's hand Args: itemStack
     */
    public void renderItem(EntityLivingBase par1EntityLivingBase, ItemStack par2ItemStack, int par3, ItemRenderType type)
    {
        GL11.glPushMatrix();
        TextureManager texturemanager = this.mc.getTextureManager();

        Block block = null;
        if (par2ItemStack.getItem() instanceof ItemBlock && par2ItemStack.itemID < Block.blocksList.length)
        {
            block = Block.blocksList[par2ItemStack.itemID];
        }

// breakpoint here and trace into it to see why your Item is not getting the appropriate renderer
        IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(par2ItemStack, type);  

 

if your renderer is corrected registered, you should see it in MinecraftForgeClient.customItemRenderers[]

if not, it should hopefully give you a clue why not.

 

-TGG

 

 

Posted

Thanks for all the help guys, I realised that the way I was doing the ID's was ignoring Minecraft adding 255 to the ID, I just added 255 into the register item render code and it solved it. My rendering was all messed up, so thanks for help fixing that red!

Posted

Wahey! It displays everywhere but the inventory!, where I just get an invisible item. My code for that part is below, see any issues?

 

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

RenderBlocks blockRenderer = (RenderBlocks)data[0];

//Entity entity = (Entity)data[1]; // entity holding the item

 

GL11.glPushMatrix();

Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(ModInfo.ID.toLowerCase() + ":textures/items/LaserWrench.png"));

 

float scale = 0.7F;

GL11.glScalef(scale, scale, scale);

GL11.glRotatef(180, 1, 0, 0);

// Forward-Backwards Up-Down

model.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F,

0.0625F);

 

GL11.glPopMatrix();

}

Posted

Hi

 

Keen, glad it works

 

Re 255: do you mean 256?

 

The sooner they get rid of BlockIDs and ItemIDs the happier I'll be...

 

Re Inventory invisible - suggest to check

 

shouldUseRenderHelper(INVENTORY_BLOCK) returns true

handleRenderType(INVENTORY) returns true

 

If those are right, either your model is not right, it's rendering in the wrong spot (out of view), or you've done something funny to the renderer.  I don't see anything obvious wrong.

 

-TGG

 

 

 

 

 

Posted

Thanks TTG! it was shouldUseRenderHelper(INVENTORY_BLOCK) returns true that i needed. Here is a screenshot of everything working nicely! thanks both of you for you help :)

 

5qLxk.jpg

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.