Posted October 11, 201410 yr 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.
October 11, 201410 yr "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.
October 11, 201410 yr Author In the actual mod this snippet is from, it is called client-side. I like trains.
October 11, 201410 yr 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. If you don't know basic Java yet, go and follow these tutorials.
October 11, 201410 yr 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.
October 11, 201410 yr Check if your itemstack#getItem is returning null first. BEFORE ASKING FOR HELP READ THE EAQ! I'll help if I can. Apologies if I do something obviously stupid. If you don't know basic Java yet, go and follow these tutorials.
October 11, 201410 yr 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
October 11, 201410 yr 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.
October 11, 201410 yr 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
October 12, 201410 yr Author this is probibly because Blocks.brewing_stand is being used not Items.brewing_stand What. The. Hell. Well that works. I like trains.
October 12, 201410 yr 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.