Jump to content

RENDERING CUSTOM 3D MODEL IN HANDS


DanteZg

Recommended Posts

I'm trying to render custom block which uses metadata for binding textures but my Minecraft crashes. Im trying to fix this for 4 hours straight now. Simple problem which you will probably notice in 1 min and I'm working on it for 4 hours without results.

 

Crash Report:

 

---- Minecraft Crash Report ----
// This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~]
Time: 02.12.13. 12:03
Description: Unexpected error
java.lang.NullPointerException
at net.minecraft.tileentity.TileEntity.getBlockType(TileEntity.java:224)
at net.minecraft.tileentity.TileEntity.func_85027_a(TileEntity.java:283)
at net.minecraft.client.renderer.tileentity.TileEntityRenderer.renderTileEntityAt(TileEntityRenderer.java:178)
at woodworks.renderer.ItemRendererTable.renderItem(ItemRendererTable.java:20)
at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:163)
at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:465)
at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:976)
at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:206)
at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:141)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1014)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:946)
at net.minecraft.client.Minecraft.run(Minecraft.java:838)
at net.minecraft.client.main.Main.main(Main.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
at net.minecraft.launchwrapper.Launch.main(Launch.java:27)

 

 

ItemRenderer

 

public class ItemRendererTable implements IItemRenderer{
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
  return true;
}
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
  return true;
}
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
  TileEntityRenderer.instance.renderTileEntityAt(new TileEntityTable(), 0.D, -0.2D, 0.0D, 0.0F);
}
}

 

 

Renderer:

 

public class RendererTable extends TileEntitySpecialRenderer{
    ResourceLocation texture1 = (new ResourceLocation("textures/woodworks/textures/models/tablemodel_oak.png"));
    ResourceLocation texture2 = (new ResourceLocation("textures/woodworks/textures/models/tablemodel_spruce.png"));
    ResourceLocation texture3 = (new ResourceLocation("textures/woodworks/textures/models/tablemodel_birch.png"));
    ResourceLocation texture4 = (new ResourceLocation("textures/woodworks/textures/models/tablemodel_jungle.png"));
Object blockTable = WoodworksCommonProxy.blockTable;
   
private ModelTable model;

public RendererTable(){
  this.model = new ModelTable();
}

public void renderTileEntityAt(TileEntity tileentity, double x, double y,double z, float f) {
  GL11.glPushMatrix();
  GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z +0.5F);
  GL11.glRotatef(180, 0F, 0F, 1F);
  if(tileentity.getBlockMetadata() == 0){
      this.bindTexture(texture1);}
     
      if(tileentity.getBlockMetadata() == 1){
       this.bindTexture(texture2);}
      
       if(tileentity.getBlockMetadata() == 2){
        this.bindTexture(texture3);}
       
        if(tileentity.getBlockMetadata() == 3){
         this.bindTexture(texture4);}
  GL11.glPushMatrix();
  model.renderModel(0.0625F);
  GL11.glPopMatrix();
  GL11.glPopMatrix();
}

}

 

 

From what I was able to read from the crashreport I noticed that if I change this code:

  if(tileentity.getBlockMetadata() == 0){
      this.bindTexture(texture1);}
    
      if(tileentity.getBlockMetadata() == 1){
       this.bindTexture(texture2);}
     
       if(tileentity.getBlockMetadata() == 2){
        this.bindTexture(texture3);}
      
        if(tileentity.getBlockMetadata() == 3){
         this.bindTexture(texture4);}

to this code:

this.bindTexture(texture1);

everything works fine and every block metadata in Inventory has texture1. But I need all of them to work. Anyone can help me with this problem?

Link to comment
Share on other sites

Well, if you're creating a new TileEntityTable() to render in your hand (ItemRenderer line 9) then it's not going to have a blook to request metadata from.

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

Well, if you're creating a new TileEntityTable() to render in your hand (ItemRenderer line 9) then it's not going to have a blook to request metadata from.

 

Ohhh I see. How can I make it request metadata from my block?

 

You would need to poll the itemstack.

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

Well, if you're creating a new TileEntityTable() to render in your hand (ItemRenderer line 9) then it's not going to have a blook to request metadata from.

 

Ohhh I see. How can I make it request metadata from my block?

 

You would need to poll the itemstack.

 

Can you please provide me some open source codes or give me an example, never heard of this thing, I started modding forge 4 days ago.

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



×
×
  • Create New...

Important Information

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