Jump to content

[1.3.2] Error with custom block models and ISimpleBlockRenderingHandler | NPE


Jakemichie97

Recommended Posts

Okay, I've created a custom modelled block (Anvil) and I was using an item to place it, but now I want a full 3D block, so I tried to use a block rendering class which implemented ISimpleBlockRenderingHandler and ran minecraft, crashed, said something about my texture (crash log below).

 

Code:

TileEntityAnvilRenderer

 

 

package jcm2606.te.client.tiles;

import jcm2606.te.client.models.ModelAnvil;
import jcm2606.te.common.tileentities.TileEntityAnvil;
import net.minecraft.src.TileEntity;
import net.minecraft.src.TileEntitySpecialRenderer;

import org.lwjgl.opengl.GL11;

public class TileEntityAnvilRenderer extends TileEntitySpecialRenderer
{
public static TileEntityAnvilRenderer instance = new TileEntityAnvilRenderer();

        public TileEntityAnvilRenderer()
        {
                aModel = new ModelAnvil();
        }

        public void renderAModelAt(TileEntityAnvil tile, double d, double d1, double d2, float f) {
        	int i = 0;
        	
        	if (tile.worldObj != null)
            {
                    i = tile.getBlockMetadata();
            }
        	
        	int j = 0;

        	                if (i == 0)
        	                {
        	                        j = 0;
        	                }

        	                if (i == 1)
        	                {
        	                        j = 90;
        	                }

        	                if (i == 2)
        	                {
        	                        j = 180;
        	                }

        	                if (i == 3)
        	                {
        	                        j = 270;
        	                }

        	                bindTextureByName("/jcm2606/te/modelAnvil.png"); //texture
        	                GL11.glPushMatrix(); //start
        	                GL11.glTranslatef((float)d + 0.5F, (float)d1 + 1.5F, (float)d2 + 0.5F); //size
        	                GL11.glRotatef(j, 0.0F, 1.0F, 0.0F); //rotate based on metadata
        	                GL11.glScalef(1.0F, -1F, -1F); //if you read this comment out this line and you can see what happens
        	                aModel.renderModel(0.0625F); //renders and yes 0.0625 is a random number
        	                GL11.glPopMatrix(); //end

        	}

        public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, 
                        float f)
        {
                renderAModelAt((TileEntityAnvil)tileentity, d, d1, d2, f);
        }

        public static ModelAnvil aModel;
}

 

 

 

Block renderer

 

 

package jcm2606.te.client.core;

import jcm2606.te.client.tiles.TileEntityAnvilRenderer;
import jcm2606.te.common.lib.RenderID;
import jcm2606.te.common.tileentities.TileEntityAnvil;
import net.minecraft.src.Block;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.RenderBlocks;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class InventoryRenderer implements ISimpleBlockRenderingHandler
{

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer)
{
	if(modelID == RenderID.ID_ANVIL_RENDER)
	{
		TileEntityAnvilRenderer.instance.renderTileEntityAt(new TileEntityAnvil(), 0.0D, 0.0D, 0.0D, 0.0F);
	}

}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
		Block block, int modelId, RenderBlocks renderer) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public boolean shouldRender3DInInventory() {
	return true;
}

@Override
public int getRenderId() {
	return RenderID.ID_ANVIL_RENDER;
}

}

 

 

 

Eclipse crash log

 

 

9 22:53:19 [iNFO] [sTDERR] java.lang.NullPointerException

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.src.TileEntitySpecialRenderer.bindTextureByName(TileEntitySpecialRenderer.java:21)

2012-10-19 22:53:19 [iNFO] [sTDERR] at jcm2606.te.client.tiles.TileEntityAnvilRenderer.renderAModelAt(TileEntityAnvilRenderer.java:49)

2012-10-19 22:53:19 [iNFO] [sTDERR] at jcm2606.te.client.tiles.TileEntityAnvilRenderer.renderTileEntityAt(TileEntityAnvilRenderer.java:62)

2012-10-19 22:53:19 [iNFO] [sTDERR] at jcm2606.te.client.core.InventoryRenderer.renderInventoryBlock(InventoryRenderer.java:19)

2012-10-19 22:53:19 [iNFO] [sTDERR] at cpw.mods.fml.client.registry.RenderingRegistry.renderInventoryBlock(RenderingRegistry.java:150)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.src.FMLRenderAccessLibrary.renderInventoryBlock(FMLRenderAccessLibrary.java:84)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.src.RenderBlocks.renderBlockAsItem(RenderBlocks.java:6460)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.src.RenderItem.drawItemIntoGui(RenderItem.java:217)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.src.RenderItem.renderItemIntoGUI(RenderItem.java:281)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.src.GuiIngame.renderInventorySlot(GuiIngame.java:692)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.src.GuiIngame.renderGameOverlay(GuiIngame.java:325)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.src.EntityRenderer.updateCameraAndRender(EntityRenderer.java:898)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:882)

2012-10-19 22:53:19 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:775)

2012-10-19 22:53:19 [iNFO] [sTDERR] at java.lang.Thread.run(Unknown Source)

 

 

 

And the ForgeModLoader-client-0.log file says the same.

 

Thanks to whomever be reading this and I hope you find something.

Link to comment
Share on other sites

Okay, can some one please help, I really need this as I don't want to have to use an item to place this block down.

If it helps, I've narrowed it down the the bindTextureByName method. Yes I have the texture in the .jar (it works in the world, I have been able to test as it won't crash when I don't have the item in my inventory, once I do it crashes.), yes I have typed in the path correctly.

 

Please, if someone knows, please reply...

Link to comment
Share on other sites

Sounds like a simple NPE. If this is the solution, you may want to look into basic programming tutorials. For now, I've gone through the steps one should take when they encounter a NPE.

 

1. 22:53:19  [sTDERR] java.lang.NullPointerException
2. 2012-10-19 22:53:19  [sTDERR]    at net.minecraft.src.TileEntitySpecialRenderer.bindTextureByName(TileEntitySpecialRenderer.java:21)
3. 2012-10-19 22:53:19  [sTDERR]    at jcm2606.te.client.tiles.TileEntityAnvilRenderer.renderAModelAt(TileEntityAnvilRenderer.java:49)
4. 2012-10-19 22:53:19  [sTDERR]    at jcm2606.te.client.tiles.TileEntityAnvilRenderer.renderTileEntityAt(TileEntityAnvilRenderer.java:62)

 

Your stack trace shows that your issue ends up in your class TileEntityAnvilRenderer. We know this thanks to lines 3 and 4.

Following along the trace shows that the exception is actually thrown in the TileEntitySpecialRenderer.bindTextureByName function.

It also shows the file and line number: TileEntitySpecialRenderer.java:21.

 

Looking there, we find this section of code:

 

...
19. protected void bindTextureByName(String par1Str)
20.    {
21.        RenderEngine var2 = this.tileEntityRenderer.renderEngine;
22.
23.        if (var2 != null)
24.        {
25.            var2.bindTexture(var2.getTexture(par1Str));
26.        }
27. }
...

 

Line 21 shows that there are 3 possible null variables; this, this.tileEntityRenderer, and this.tileEntityRenderer.renderEngine.

 

Looking at the TileEntitySpecialRenderer class we can see it does not set a tileEntityRenderer when created.

 

...
12. protected TileEntityRenderer tileEntityRenderer;
...

 

There is a function to do so;

 

...
32. public void setTileEntityRenderer(TileEntityRenderer par1TileEntityRenderer)
33.    {
34.        this.tileEntityRenderer = par1TileEntityRenderer;
35.    }
...

 

We can also see that you never call this function in the code you provided.

I can only assume that if you actually set the TileEntityRenderer and its renderEngine, the error would not be thrown.

Link to comment
Share on other sites

Quick question, that requires a TileEntityRenderer, which I have a TileEntitySpecialRenderer, incompatible types and would likely throw more errors if I create another one. And also if it were to be the error your describing, wouldn't that cause it to crash on world load, it doesn't as it works in the world, I can see the block clearly with the texture and all.

Link to comment
Share on other sites

Trace out the values of this, this.tileEntityRenderer and this.tileEntityRenderer.renderEngine right before the crash line. Look for which is null and make that variable not null.

 

I'm only explaining why the error is thrown, not giving you alternatives.

 

If you don't want to set the tileEntityRenderer on your TileEntitySpecialRenderer to something not null, you could rewrite the bindTextureByName function to not use a TileEntityRenderer. I can't tell you how to do that though.

 

To answer your questions;

 

If they were incompatible types, the TileEntitySpecialRenderer wouldn't be asking to set a TileEntityRenderer and the bindTextureByName function wouldn't be looking for one. You need to use one or make one alongside your TileEntitySpecialRenderer, I suppose.

 

Secondly, if it isn't crashing when you load the world, then no, the error I'm describing wouldn't cause the world to crash on load, because I'm describing your error, which doesn't cause the world to crash on load.

Link to comment
Share on other sites

Okay, I think I know the cause, something that you had said, but not quite... since I'm using a TileEntitySpecialRenderer it should be taken as if it is a TileEntityRenderer (someone correct me if I'm wrong), what I think is causing this is the fact that I'm not creating a RenderEngine instance. I will try now and post me results.

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

    • i notice a change if i add the min and max ram in the line like this for example:    # Xmx and Xms set the maximum and minimum RAM usage, respectively. # They can take any number, followed by an M or a G. # M means Megabyte, G means Gigabyte. # For example, to set the maximum to 3GB: -Xmx3G # To set the minimum to 2.5GB: -Xms2500M # A good default for a modded server is 4GB. # Uncomment the next line to set it. -Xmx10240M -Xms8192M    i need to make more experiments but for now this apparently works.
    • Selamat datang di OLXTOTO, situs slot gacor terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, maka OLXTOTO adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermain judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI   Slot Gacor untuk Sensasi Bermain Maksimal Olahraga cepat dan seru dengan slot gacor di OLXTOTO. Rasakan sensasi bermain maksimal dengan mesin slot yang memberikan kemenangan beruntun. Temukan keberuntungan Anda di antara berbagai pilihan slot gacor yang tersedia dan rasakan kegembiraan bermain judi slot yang tak terlupakan. Situs Slot Terpercaya dengan Pilihan Terlengkap OLXTOTO adalah situs slot terpercaya yang menawarkan pilihan terlengkap dalam perjudian online. Nikmati berbagai genre dan tema slot online yang menarik, dari slot klasik hingga slot video yang inovatif. Dipercaya oleh jutaan pemain, OLXTOTO memberikan pengalaman bermain yang aman dan terjamin.   Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpot slot maxwin yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiah jackpot slot maxwin kami. Jackpot slot maxwin merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir dengan jackpot slot maxwin yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda.  
    • LOGIN DAN DAFTAR DISINI SEKARANG !!!! Blacktogel adalah situs judi slot online yang menjadi pilihan banyak penggemar judi slot gacor di Indonesia. Dengan platform yang sangat user-friendly dan berbagai macam permainan slot yang tersedia, Blacktogel menjadi tempat yang tepat untuk penggemar judi slot online. Dalam artikel ini, kami akan membahas tentang Blacktogel dan keunggulan situs slot gacor online yang disediakan.  
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
  • Topics

×
×
  • Create New...

Important Information

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