Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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

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.

  • Author

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.

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

 

 

  • Author

It doesn't make sense for Blocks.brewing_stand to be null in postInit because you're supposed to make your recipes in the init method which happens before postInit.

I like trains.

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

::)

 

 

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.