Jump to content

Recommended Posts

Posted

Hi all, i am getting this Nullpointer exception a lot right now and i have no idea why it is giving a nullpointer exception on getBlockId and sometimes on setBlockId. I had it working before (i'll show some code below), but right now i have changed some things which make my custom plants be placed only on some blocks and that they can't stack and fly in the air and such. That part now works, but now somehow the generation part works, which i was trying to make simpler but yet i haven't succeeded in getting it to work. So i am getting this nullpointer exception which is not really giving me much information of what is null... So when i try debugging that line it'll go great for about a million times, so to get to the part where it crashes i'd have to click a 1000 times. Well anyway here's my code:

 

So i was generating a custom tall grass like this: (and i know that i check all of the blocks it can't spawn on here, thats what i have been trying to get rid off, but it seems not to help when i take it away.

 

  Reveal hidden contents

 

 

So this is what i have in one of the blocks it CAN spawn on:

the custom grass block (which works fine itself, but all i did here was changing the canbePlacedOn and all that kind of methods)

 

  Reveal hidden contents

 

 

And this is one of the plant blocks: (this one also works like it should, i tried in the overworld by placing it on blocks etc, all i changed was the canBePlacedOn etc.)

 

  Reveal hidden contents

 

 

This is the code i use to generate it:

            for (int g1 = 0; g1 < 40; g1++)
            {
            	l1 = k + this.soulRNG.nextInt(16) + 8;
            	i2 = this.soulRNG.nextInt(128);
            	j2 = l + this.soulRNG.nextInt(16) + 8;
                WorldGenerator worldgenerator1 = soul_forest.getRandomWorldGenForGrass(this.soulRNG, 2);
                worldgenerator1.generate(this.worldObj, this.soulRNG, l1, i2, j2);
            }

 

The crash report:

 

  Reveal hidden contents

 

 

I appreciate your help

Posted

line 698 of Chunk.java:

  Quote
Block.blocksList[l1].onSetBlockIDWithMetaData(this.worldObj, j2, par2, k2, i2);

do you have your block generated at that point ?

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

well whatever this method is trying to get

par1World.setBlock(i1, j1, k1, this.tallGrassID, 0, 2);

im guessing its the plant but yeah, does thsi block exists at that  point ?

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

no i mean, does the object exists, (like code wise)

 

like the programe expect to find somethign at

 

Block.blocksList[tallGrassId]

 

and if theres nothing (because the block isnt created) well its gon crash

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

well heres i would start debugging that

 

Block.blocksList[l1].onSetBlockIDWithMetaData(this.worldObj, j2, par2, k2, i2);

the only thigns here that can throw an NPE is

blocksList[l1].onSetBlockIDWithMetaData

because j2, par2, k2, i2 can throw null and no one cares, this.worlObj can be null too if its a problem it would only throw an exception later

 

so what i would do is right before this line is called:

 

if(Block.blockList[l1]==null){
System.out.println("the block at "+l1+" was null :\ this is bad ");
}
Block.blocksList[l1].onSetBlockIDWithMetaData(this.worldObj, j2, par2, k2, i2);

remember you can change the vanilla code but make sure to ctrl+z all your changes after (i do it a lot for debugging)

 

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Unless you have registered a block with tallGrassID, blocksList[tallGrassID] will be null.

 

So you should check where your block is registered, and if you called the same id when doing

new WorldGenSoulGrass(id, meta)

Posted

Well i obviosly registered the block, and i used this method as in Blockslist[theTallgrassID] before and it was working fine, but now that i change a couple of canBlockBePlacedOn methods and such it is somehow not working anymore.

 

For example i registered the block BogTallGrassGrey, with an idea bogTallGrassGreyID of 3517 (in my config) Then when i use the block.blockID which i checked is not null when entering that method, i also tried checking wether Blockslist[theTallGrassID] was null, but that was also not null. I am pretty confused why it is throwing this error, because if i remove this little bit of code and start testing. It then throws errors in long not changed code from generating custom fires or custom trees. Its just odd...

Posted

Try this code instead

 

      for (int g1 = 0; g1 < 40; g1++)
            {
            	l1 = k + this.soulRNG.nextInt(16) + 8;
            	i2 = this.soulRNG.nextInt(128);
            	j2 = l + this.soulRNG.nextInt(16) + 8;
                WorldGenSoulGrass worldgenerator1 = new WorldGenSoulGrass(this.soulRNG, 2);
                worldgenerator1.generate(this.worldObj, this.soulRNG, l1, i2, j2);
            }

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.