Jump to content

Recommended Posts

Posted

So what i'm trying to do is rendering a backpack when held.

I have multiple working IItemrenderers that work fine.

I noticed how those IItemrenderers work only when they render blocks with tileentities, while they don't work on items.

 

RenderItemBackpack:

package coalpower.client.render.item;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import net.minecraftforge.client.IItemRenderer.ItemRendererHelper;

import org.lwjgl.opengl.GL11;

import coalpower.client.model.ModelBackpackHandheld;
import coalpower.lib.render.Texture;

public class RenderItemBackpack implements IItemRenderer {

private ModelBackpackHandheld backpacks;
private Texture texture = Texture.BACKPACK;

public RenderItemBackpack() {
		backpacks = new ModelBackpackHandheld();
}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	return true;
}

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

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	switch (type) {
		case ENTITY: {			
			texture.bind();
			GL11.glPushMatrix();
			GL11.glTranslatef(0F, 1F, 0F);
			GL11.glRotatef(180, 1, 0, 0);
			GL11.glRotatef(-90, 0, 1, 0);
			backpacks.render((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
			GL11.glPopMatrix();
			break;
		}

		case EQUIPPED: {
			texture.bind();
			GL11.glPushMatrix();
			GL11.glTranslatef(0.5F, 1.5F, 0.5F);
			GL11.glRotatef(180, 1, 0, 0);
			GL11.glRotatef(-90, 0, 1, 0);
			backpacks.render((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
			GL11.glPopMatrix();
			break;
		}

		case EQUIPPED_FIRST_PERSON: {
			texture.bind();
			GL11.glPushMatrix();
			GL11.glTranslatef(1F, 2F, 1F);
			GL11.glRotatef(180, 1, 0, 0);
			GL11.glRotatef(-90, 0, 1, 0);
			backpacks.render((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
			GL11.glPopMatrix();
			break;
		}

		default:
			break;
	}
}

}

 

ClientProxy

MinecraftForgeClient.registerItemRenderer(Config.itemBackpackID, new RenderItemBackpack());		

 

This is how I did it for every other block, and it works fine, so I don't know what to do..

I try my best, so apologies if I said something obviously stupid!

Posted

Hi

 

I noticed how those IItemrenderers work only when they render blocks with tileentities, while they don't work on items.

 

I really don't understand what you mean by that.  IItemRenderer is designed for use with Items, and once the renderItem is called, you can render it any way you want.

 

What do you mean that this code doesn't work?  Do you see nothing at all, or do you see something but it is wrong?

Have you tried inserting breakpoint or System.out.println into renderItem or backpacks.render to see if it's called?

 

The problem might be what you're doing with (Entity)data[1]

 

eg for equipped it's the entity holding the item, not the item itself (since there is no entity for the item itself when it's being held)

        /** 
         * Called to render an item currently held in-hand by a living entity. If
         * rendering as a 3D block, the item will be rotated to a 45-degree angle.
         * To render a 2D texture with some thickness (like default items), see
         * net.minecraft.src.ItemRenderer. In either case, rendering should be done
         * in local coordinates from (0,0,0)-(1,1,1).
         * 
         * Data parameters:
         * RenderBlocks render - The RenderBlocks instance
         * EntityLiving entity - The entity holding this item
         */
        EQUIPPED, 

 

Some more info on IItemRenderer here,

http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html

see the Item Rendering sections

 

-TGG

Posted

What I mean by that is that only blocks with TileEntities get rendered as 3d items with IItemRenderer whereas items (Such as my backpack) don't get renderer at all. All I can see is the item texture in my hand, just like every other item instead of a custom model

 

So for instance I have a Pipe which has got a TileEntity. This pipe gets rendered with IItemRenderer.

Backpack won't get rendered at all.

 

Example of what I'm trying to explain:

7ERtx.jpg

 

This is not what I want. The backpack should not be a plain texture but a custom model

 

I try my best, so apologies if I said something obviously stupid!

Posted

Even If this is not required, since other IItemRenderers are registered in this way and work properly, It doesn't hurt me to.

 

Main Class (Commented out everything so yuo can understand what's going on)

package coalpower;


import net.minecraft.util.DamageSource;
import net.minecraftforge.common.MinecraftForge;
import coalpower.addon.AddonManager;
import coalpower.core.CPKeyBindings;
import coalpower.core.Config;
import coalpower.enchantment.EnchantmentTimedDamage;
import coalpower.info.dev.CapeHandler;
import coalpower.lib.core.AchievementLoader;
import coalpower.lib.handler.CPEventHandler;
import coalpower.lib.handler.GuiHandler;
import coalpower.lib.handler.PacketHandler;
import coalpower.lib.handler.SoundHandler;
import coalpower.lib.world.BiomeLoader;
import coalpower.lib.world.CPLoot;
import coalpower.lib.world.RadiationDamageSource;
import coalpower.network.proxy.ICPProxy;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid = CoalPower.modid, name = CoalPower.modid, version = CoalPower.version)
@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels={ CoalPower.channel }, packetHandler = PacketHandler.class)


public class CoalPower 
{
@Instance("CoalPower")
public static CoalPower instance;
public static final String modid = "CoalPower";
public static final String version = "0.0.1";
public static final String channel = "coalPower";

public static AchievementLoader achievements;

public static EnchantmentTimedDamage coalTouch = new EnchantmentTimedDamage(100, 1, "Coal Touch");

public static GuiHandler guiHandler = new GuiHandler();
public static DamageSource radiation = new RadiationDamageSource("radiation").setDamageBypassesArmor();

@SidedProxy(clientSide = "coalpower.network.proxy.ClientProxy", serverSide = "coalpower.network.proxy.CommonProxy")
public static ICPProxy proxy;

@EventHandler
public void PreInit(FMLPreInitializationEvent event)
{
	//Config for ids
	Config.preInit(event);
	//Capes
	CapeHandler.registerCapesFromList(CapeHandler.devList, CapeHandler.devCape);
	//Achievements
	achievements = new AchievementLoader();
	//Events and sounds
	MinecraftForge.EVENT_BUS.register(new CPEventHandler());
	MinecraftForge.EVENT_BUS.register(new SoundHandler());
	//KeyBindings
	if (FMLCommonHandler.instance().getEffectiveSide().isClient())
		CPKeyBindings.init();
}

@EventHandler
public void load(FMLInitializationEvent event) 
{	
	//Blocks, items, entites, custom dungeon chests and proxy registrations
        CPLoader.load();
        CPLoot.init();
	proxy.init();			
}

@EventHandler
public void PostInit(FMLPostInitializationEvent event)
{
	//Addons and biomes
	AddonManager.loadAddons();
	AddonManager.init();

	BiomeLoader biomes = new BiomeLoader();
	biomes.register();
}

}

 

ClientProxy

package coalpower.network.proxy;

import java.util.Random;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.BiomeManager;
import coalpower.client.render.block.RenderAlloyFurnace;
import coalpower.client.render.block.RenderGas;
import coalpower.client.render.blockitem.RenderItemCrusher;
import coalpower.client.render.blockitem.RenderItemGasPipe;
import coalpower.client.render.blockitem.RenderItemSawmill;
import coalpower.client.render.blockitem.RenderItemSprinkler;
import coalpower.client.render.entity.RenderBee;
import coalpower.client.render.item.RenderItemBackpack;
import coalpower.client.render.machine.RenderCrusher;
import coalpower.client.render.machine.RenderSawmill;
import coalpower.client.render.machine.RenderSprinkler;
import coalpower.client.render.machine.pipe.RenderPipeGas;
import coalpower.core.Config;
import coalpower.entity.EntityBee;
import coalpower.entity.fx.EntitySparkFX;
import coalpower.entity.fx.EntityWoodDustFX;
import coalpower.lib.core.FXType;
import coalpower.tileentity.TileEntityHeatConductant;
import coalpower.tileentity.furnace.TileEntityAlloyFurnace;
import coalpower.tileentity.machine.TileEntityCrusher;
import coalpower.tileentity.machine.TileEntityPoweredFurnace;
import coalpower.tileentity.machine.TileEntityProjectTable;
import coalpower.tileentity.machine.TileEntitySawmill;
import coalpower.tileentity.machine.TileEntitySprinkler;
import coalpower.tileentity.machine.conductor.TileEntityGasPipe;
import coalpower.world.GenerationManager;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.registry.GameRegistry;

public class ClientProxy extends CommonProxy
{	
@Override
public void init(){
	super.init();
	this.registerEntities();
	this.registerGeneric();
	this.registerRenderers();
	this.registerTileEntities();
	this.registerWorldFeatures();
}


@Override
public void registerRenderers()
{
	super.registerRenderers();

	//Entities
	RenderingRegistry.registerEntityRenderingHandler(EntityBee.class, new RenderBee());

	//Blocks / Items
	RenderingRegistry.registerBlockHandler(renderGasBlock, new RenderGas());
	RenderingRegistry.registerBlockHandler(renderAlloyFurnace, RenderAlloyFurnace.INSTANCE);

	MinecraftForgeClient.registerItemRenderer(Config.machineCrusherID, new RenderItemCrusher());
	MinecraftForgeClient.registerItemRenderer(Config.machineSawmillID, new RenderItemSawmill());
	MinecraftForgeClient.registerItemRenderer(Config.pipeGasID, new RenderItemGasPipe());
	MinecraftForgeClient.registerItemRenderer(Config.machineSprinklerID, new RenderItemSprinkler());
	MinecraftForgeClient.registerItemRenderer(Config.itemBackpackID, new RenderItemBackpack());		

	//TileEntities
   	 	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCrusher.class, new RenderCrusher());
   	 	ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySawmill.class, new RenderSawmill());
   	 	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityGasPipe.class, new RenderPipeGas());
   	 	ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySprinkler.class, new RenderSprinkler());
   	 	

}

@Override 
public void registerWorldFeatures(){
	super.registerWorldFeatures();
        GameRegistry.registerWorldGenerator(GenerationManager.instance);

}

@Override 
public void registerTileEntities(){
	super.registerTileEntities();

	GameRegistry.registerTileEntity(TileEntityAlloyFurnace.class, "FurnaceAlloy");
	GameRegistry.registerTileEntity(TileEntityPoweredFurnace.class, "FurnacePowered");
	GameRegistry.registerTileEntity(TileEntityProjectTable.class, "BlockProjectTable");
	GameRegistry.registerTileEntity(TileEntityCrusher.class, "MachineCrusher");
	GameRegistry.registerTileEntity(TileEntitySawmill.class, "MachineSawmill");
	GameRegistry.registerTileEntity(TileEntityGasPipe.class, "PipeGas");
	GameRegistry.registerTileEntity(TileEntitySprinkler.class, "MachineSprinkler");

}




@Override
 public void spawnParticle(String s, double d, double d1, double d2, double d3, double d4, double d5, World worldObj, int opt)
     {
	super.spawnParticle(s, d, d1, d2, d3, d4, d5, worldObj, opt);
             Minecraft mc = Minecraft.getMinecraft();
             if (mc == null || mc.renderViewEntity == null || mc.effectRenderer == null) {
                     return;
             }
             int i = mc.gameSettings.particleSetting;
             if (i == 1 && worldObj.rand.nextInt(3) == 0) {
                     i = 2;
             }
             double d6 = mc.renderViewEntity.posX - d;
             double d7 = mc.renderViewEntity.posY - d1;
             double d8 = mc.renderViewEntity.posZ - d2;
             EntityFX obj = null;
             double d9 = 16D;
             if (d6 * d6 + d7 * d7 + d8 * d8 > d9 * d9) {
                     return;
             }
             if (i > 1) {
                     return;
             }
             
             if (s.equals("wooddust"))
                     obj = new EntityWoodDustFX(worldObj, d, d1, d2, (float)d3, (float)d4, (float)d5);
             else if(s.equals("spark"))
            	 obj = new EntitySparkFX(worldObj, d, d1, d2, false);
             else if(s.equals("randomspark"))
            	 obj = new EntitySparkFX(worldObj, d, d1, d2, true);
            
             if (obj != null) {
                     mc.effectRenderer.addEffect((EntityFX)obj);
                     FMLClientHandler.instance().getClient().effectRenderer.addEffect(obj);
             }
     }



@Override
public void addBiome(final BiomeGenBase biome){

	final WorldType[] worldTypes = { WorldType.DEFAULT, WorldType.LARGE_BIOMES };

	for(final WorldType worldType : worldTypes){
		worldType.addNewBiome(biome);
	}		
}

@Override
public void addSpawnBiome(final BiomeGenBase biome){
	BiomeManager.addSpawnBiome(biome);
}

}

I try my best, so apologies if I said something obviously stupid!

Posted

Did you even write your backpacks.render function to expect a an EntityLiving as it's argument. Since you are casting it down to Entity, I suspect that isn't true. The player in the EntityLiving, not the backpack. I'd suggest you use the object you get to get the held item, then render that with the view transformations of the player (1st argument). Maybe it should work as written, but I'd set a breakpoint there and see what is happening.

Posted

Hi

 

It looks to me like your backpack is rendering fine, it's just that it's using the vanilla renderer instead of your custom renderer.  This probably means you haven't registered the renderer properly.

 

MinecraftForgeClient.registerItemRenderer(Config.itemBackpackID, new RenderItemBackpack());

 

Is Config.itemBackpackID correct?

 

Did you try our suggestion of putting a breakpoint or System.out.println in your RenderItemBackpack methods?

 

-TGG

 

Posted

Yes, the config id is correct, since I tried rendering other items, but none of them work.

I'm setting breakpoints right now, I'll let you know

 

 

So, if I set the breakpoint in the renderItem function, It's not even getting called. The class's constructor obviously is, so I don't know what's happening..

I try my best, so apologies if I said something obviously stupid!

Posted

Hi

 

In that case, I suggest you try to trace through the vanilla code when it goes to render your item.

This diagram for 1.6.4 might help you.

http://greyminecraftcoder.blogspot.com.au/2013/08/rendering-first-person-view-items.html

 

ItemRenderer::
    // JAVADOC METHOD $$ renderItem
    public void renderItem(EntityLivingBase par1EntityLivingBase, ItemStack par2ItemStack, int par3, ItemRenderType type)
    {
        GL11.glPushMatrix();
        TextureManager texturemanager = this.mc.getTextureManager();
        Item item = par2ItemStack.getItem();
        Block block = Block.getBlockFromItem(item);

        IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(par2ItemStack, type);  // breakpoint here
        if (customRenderer != null)

 

If customRenderer comes back null, you've got a registration problem.  By inspecting customItemRenderers in MinecraftForgeClient you should be able to figure out what you've done wrong.

 

-TGG

 

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

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