Jump to content

Recommended Posts

Posted

package untouchedwagons.minecraft.sandbox;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;

@Mod(modid = "sandbox",  name = "Sandbox", version = "1.0.0", dependencies = "required-after:FML")
public class Sandbox {
    @Mod.EventHandler
    public void load(FMLInitializationEvent event)
    {
        ItemStack brewing_stand = new ItemStack(Blocks.brewing_stand);
        brewing_stand.getDisplayName();
    }
}

 

Throws a NullPointerException:

 

java.lang.NullPointerException: Initializing game
at net.minecraft.item.ItemStack.func_82833_r(ItemStack.java:426)
at untouchedwagons.minecraft.sandbox.Sandbox.load(Sandbox.java:25)

 

 

I like trains.

Posted

"Display" is a red-flag word suggesting client side-only (because the server never displays anything beyond its log). Take a look at the method and anything it calls to see if that's so.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

I think this has something to do with Items being available and being loaded, etc.

 

I'm assuming the NPE is caused through the getItem method in ItemStack which is used to get the items damage value.

 

Try placing the code in a later loading stage and see if that helps.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Posted

When I started this thread, it didn't occur to me that the getDisplayName method would be client-side only. It makes sense. However even if I try to get the display name of a brewing stand in a ClientProxy, I still get a NullPointerException:

 

package untouchedwagons.minecraft.sandbox;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;

@Mod(modid = "sandbox",  name = "Sandbox", version = "1.0.0", dependencies = "required-after:FML")
public class Sandbox {
    @SidedProxy(clientSide = "untouchedwagons.minecraft.sandbox.ClientProxy", serverSide = "untouchedwagons.minecraft.sandbox.CommonProxy")
    public static CommonProxy proxy;

    @Mod.EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
        proxy.doTheNeedful();
    }
}

 

package untouchedwagons.minecraft.sandbox;

import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;

public class ClientProxy extends CommonProxy {
    @Override
    public void doTheNeedful() {
        ItemStack brewing_stand = new ItemStack(Blocks.brewing_stand);
        brewing_stand.getDisplayName();
    }
}

 

java.lang.NullPointerException: Initializing game

at net.minecraft.item.ItemStack.func_82833_r(ItemStack.java:426)

at untouchedwagons.minecraft.sandbox.ClientProxy.doTheNeedful(ClientProxy.java:10)

at untouchedwagons.minecraft.sandbox.Sandbox.postInit(Sandbox.java:15)

 

Maybe because I passed a block into the ItemStack's constructor? Do I need to do something different to get the localized name of a block?

I like trains.

Posted

actually the error is not that brewing_stand is null or the error would be at line 10 of proxyclient not on this line of code in ItemStack

        String s = this.getItem().getItemStackDisplayName(this);

 

it appears that Blocks.brewing_stand is still null during post init , though i would have assumed it would be set, will investigate further and report

 

 

Posted

ok results

 

brewing_stand.getItem() == null

Blocks.brewing_stand == net.minecraft.block.BlockBrewingStand@81d5d1

 

this is probibly because Blocks.brewing_stand is being used not Items.brewing_stand

::)

 

 

Posted

When you register a block, FML automatically creates something called an ItemBlock. This is what exists in your inventory and as an item entity. You can't put a block in your inventory; they only exist in the world. In 1.8, water, lava, brewing stands, piston extensions, and a few other blocks do not have ItemBlocks and therefore cannot be placed in your inventory.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

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.