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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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