Jump to content

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


Recommended Posts

Posted

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.

Posted

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

Posted

How about not bumping?

I would stop but considering that this thread has been here for 3+ days with no replies and I really need the fix (Cannot find a single problem and I even have 3 other modders helping me) I am at the point were I have to... sorry though.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

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

    • Please read the FAQ and post logs as described there.
    • Upon starting the server I get; [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [     Framework (framework) has failed to load correctly §7java.lang.NoClassDefFoundError: net/minecraft/client/gui/components/toasts/Toast ] I suspect there is a (possibly a few) client-only mods installed on my server. Any help would be appreciated! (Yes I know there are a lot of mods...) Here is the crash log:   https://paste.ee/p/pRz5mhMl#s=0
    • That's basically what the failure does, my apologies for failing to specify.  It just tries again on the next tick until it detects the entities for that chunk are loaded, and then tries to load the entity.  From there it gets into different failure states depending on what goes wrong, but in short, if the entity fails to load once the entity list becomes available, the request is cleared and must be resubmitted by the end user.  There should be few cases where that actually happens. Yes, that is my understanding of forceloading.  That's why on a successful summon, it removes the forceload.  Otherwise it does just leave the chunks loaded long term. Thank you for your help, any knowledge is useful!  I don't often mess with forceloading and my prior experience is 1.16 so I'm also a bit out of my depth haha.
    • I will have to do more research about 1.18 chunk loading. You were unclear about how your code manages with the entity load failure. If you simply used a loop, I suggest submitting a tick task to the next tick which does the same thing, checking if the entities are loaded and if so teleporting the right one else submitting another tick task etc. Also I think forceloading permanently force loads the chunk, and it only starts to unload when you make a subsequent call to mark the chunk as not forceloaded. I may be completely wrong, I dont know much about 1.18, most of my experience is 1.20. Good luck I hope you figure it out after all this time 😅
    • i managed to fix it by reinstalling the modpack and re-add all the extra mods I've had previously.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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