Jump to content

Null Pointer Exception


Leon
 Share

Recommended Posts

Things are going great, I've made some marbles of my own and I'm adding the bricks, the problem comes to the creative mode menu. You see I've added Green and Yellow Bricks yet when I scroll down to them in the menu the game crashes expressing Null Pointer Exception, this as I understand occurs because there is nothing were the Block is meant to be.

Here's the error message followed by the code in my mod_ file.

Mods loaded: 2

ModLoader 1.2.5

mod_BlockMarble 1.2.5

 

      Minecraft has crashed!     

      ----------------------     

 

Minecraft has stopped running because it encountered a problem.

 

 

 

 

--- BEGIN ERROR REPORT 2b95d8b8 --------

Generated 07/07/12 18:17

 

Minecraft: Minecraft 1.2.5

OS: Windows 7 (amd64) version 6.1

Java: 1.7.0_05, Oracle Corporation

VM: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

LWJGL: 2.4.2

OpenGL: GeForce GTX 560 Ti/PCIe/SSE2 version 4.2.0, NVIDIA Corporation

 

java.lang.NullPointerException

    at net.minecraft.src.ItemStack.getIconIndex(ItemStack.java:105)

    at net.minecraft.src.RenderItem.renderItemIntoGUI(RenderItem.java:270)

    at net.minecraft.src.GuiContainer.drawSlotInventory(GuiContainer.java:228)

    at net.minecraft.src.GuiContainer.drawScreen(GuiContainer.java:74)

    at net.minecraft.src.GuiContainerCreative.drawScreen(GuiContainerCreative.java:235)

    at net.minecraft.src.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1008)

    at net.minecraft.src.EntityRendererProxy.updateCameraAndRender(EntityRendererProxy.java:20)

    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:922)

    at net.minecraft.client.Minecraft.run(Minecraft.java:801)

    at java.lang.Thread.run(Unknown Source)

--- END ERROR REPORT f9fe730e ----------

 


 


package net.minecraft.src;

import net.minecraft.client.Minecraft;

import java.util.List;

import java.util.Random;

 

public class mod_BlockMarble extends BaseMod

{

    private static GuiScreen creativeInventory;

    // Blocks

    public static final Block BlockMarble = new BlockMarble(160,

    0).setBlockName("Marble").setHardness(3F).setResistance(4F).setLightValue(0F);

    public static final Block BlockMarbleG = new BlockMarbleG(162,

    0).setBlockName("Marble").setHardness(3F).setResistance(4F).setLightValue(0F);

    public static final Block BlockMarbleY = new BlockMarbleY(163,

    0).setBlockName("Marble").setHardness(3F).setResistance(4F).setLightValue(0F);

   

    public static final Block BlockMarbleBricks = new BlockMarbleBricks(161,

    0).setBlockName("Marble Bricks").setHardness(3F).setResistance(4F).setLightValue(0F);

    public static final Block BlockMarbleGBricks = new BlockMarbleGBricks(164,

    0).setBlockName("Marble").setHardness(3F).setResistance(4F).setLightValue(0F);

    public static final Block BlockMarbleYBricks = new BlockMarbleYBricks(165,

    0).setBlockName("Marble").setHardness(3F).setResistance(4F).setLightValue(0F);

 

 

    @Override

    public void load() {

        BlockMarble.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/img/BlockMarble.png");

        ModLoader.registerBlock(BlockMarble);

        ModLoader.addName(BlockMarble, "Marble");

        ModLoader.setInGameHook(this,true,false);

        ModLoader.setInGUIHook(this,true,false);

       

        BlockMarbleY.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/img/BlockMarbleY.png");

        ModLoader.registerBlock(BlockMarble);

        ModLoader.addName(BlockMarble, "Marble");

        ModLoader.setInGameHook(this,true,false);

        ModLoader.setInGUIHook(this,true,false);

       

        BlockMarbleG.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/img/BlockMarbleG.png");

        ModLoader.registerBlock(BlockMarble);

        ModLoader.addName(BlockMarble, "Marble");

        ModLoader.setInGameHook(this,true,false);

        ModLoader.setInGUIHook(this,true,false);

       

        BlockMarbleBricks.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/img/BlockMarbleBricks.png");

        ModLoader.registerBlock(BlockMarbleBricks);

        ModLoader.addName(BlockMarbleBricks, "Marble Bricks");

        ModLoader.addRecipe(new ItemStack(BlockMarbleBricks, 4), new Object [] {"##","##", Character.valueOf('#'), BlockMarble});

        ModLoader.setInGameHook(this,true,false);

        ModLoader.setInGUIHook(this,true,false);

       

        BlockMarbleGBricks.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/img/BlockMarbleGBricks.png");

        ModLoader.registerBlock(BlockMarbleGBricks);

        ModLoader.addName(BlockMarbleGBricks, "Marble Bricks");

        ModLoader.addRecipe(new ItemStack(BlockMarbleGBricks, 4), new Object [] {"##","##", Character.valueOf('#'), BlockMarbleG});

        ModLoader.setInGameHook(this,true,false);

        ModLoader.setInGUIHook(this,true,false);

       

        BlockMarbleYBricks.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/img/BlockMarbleYBricks.png");

        ModLoader.registerBlock(BlockMarbleYBricks);

        ModLoader.addName(BlockMarbleYBricks, "Marble Bricks");

        ModLoader.addRecipe(new ItemStack(BlockMarbleYBricks, 4), new Object [] {"##","##", Character.valueOf('#'), BlockMarbleY});

        ModLoader.setInGameHook(this,true,false);

        ModLoader.setInGUIHook(this,true,false);

       

    }

   

    public boolean onTickInGame(float f, Minecraft minecraft)

    {

        if(minecraft.currentScreen == null)

        {

        creativeInventory = null;

        }

        return true;

    }

   

    public boolean onTickInGUI(float f, Minecraft minecraft, GuiScreen guiscreen)

    {

        if((guiscreen instanceof GuiContainerCreative) && !(creativeInventory instanceof GuiContainerCreative) && !minecraft.theWorld.isRemote)

        {

            Container container = ((GuiContainer)guiscreen).inventorySlots;

            List list = ((ContainerCreative)container).itemList;

            int i = 0;

            list.add(new ItemStack(BlockMarble, 1, i));

            list.add(new ItemStack(BlockMarbleBricks, 1, i));

            list.add(new ItemStack(BlockMarbleG, 1, i));

            list.add(new ItemStack(BlockMarbleY, 1, i));

 

        }

        creativeInventory = guiscreen;

        return true;

    }

   

    public void generateSurface(World world, Random random, int chunkX, int chunkZ)

    {

        BiomeGenBase biomegenbase = world.getWorldChunkManager().getBiomeGenAt(chunkX, chunkZ);

       

        if(biomegenbase instanceof BiomeGenPlains || biomegenbase instanceof BiomeGenForest ||

                biomegenbase instanceof BiomeGenRiver)

        {

            for(int i =0; i < 30; i++)

            {

                int randPosX = chunkX + random.nextInt(16);

                int randPosY = random.nextInt(128);

                int randPosZ = chunkZ + random.nextInt(16);

                (new WorldGenMinable(BlockMarble.blockID, 35)).generate(world, random, randPosX, randPosY, randPosZ);

               

            }

        }

       

        if(biomegenbase instanceof BiomeGenSwamp)

        {

            for(int i =0; i < 20; i++)

            {

                int randPosX = chunkX + random.nextInt(16);

                int randPosY = random.nextInt(128);

                int randPosZ = chunkZ + random.nextInt(16);

                (new WorldGenMinable(BlockMarbleG.blockID, 35)).generate(world, random, randPosX, randPosY, randPosZ);

               

            }

        }

       

        if(biomegenbase instanceof BiomeGenDesert)

        {

            for(int i =0; i < 20; i++)

            {

                int randPosX = chunkX + random.nextInt(16);

                int randPosY = random.nextInt(128);

                int randPosZ = chunkZ + random.nextInt(16);

                (new WorldGenMinable(BlockMarbleY.blockID, 35)).generate(world, random, randPosX, randPosY, randPosZ);

               

            }

        }

    }

   

    @Override

    public String getVersion() {

       

        return "1.2.5";

    }

}

Link to comment
Share on other sites

So, first, you appear to adding the same two hooks over and over again, so that's probably not helping you.

Second, there's a much cleaner way to add items to the creative inventory. Simply override the addCreativeItems method in your Block classes. Like so:

public void addCreativeItems( ArrayList itemList ) {

    itemList.add( new ItemStack(this, 1, 0));

}

At a guess, since you were modifying the creative list every tick in the gui, it wasn't so happy.

Edit: Or it could be that you registered BlockMarble 3 times, and never registered BlockMarbleG or BlockMarbleY.

Link to comment
Share on other sites

So, first, you appear to adding the same two hooks over and over again, so that's probably not helping you.

Second, there's a much cleaner way to add items to the creative inventory. Simply override the addCreativeItems method in your Block classes. Like so:

public void addCreativeItems( ArrayList itemList ) {

    itemList.add( new ItemStack(this, 1, 0));

}

At a guess, since you were modifying the creative list every tick in the gui, it wasn't so happy.

Edit: Or it could be that you registered BlockMarble 3 times, and never registered BlockMarbleG or BlockMarbleY.

Yeah I didn't spot the BlockMarble thing. You really helped, thanks!

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...