UntouchedWagons Posted October 11, 2014 Share Posted October 11, 2014 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) Quote I like trains. Link to comment Share on other sites More sharing options...
jeffryfisher Posted October 11, 2014 Share Posted October 11, 2014 "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. Quote 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. Link to comment Share on other sites More sharing options...
UntouchedWagons Posted October 11, 2014 Author Share Posted October 11, 2014 In the actual mod this snippet is from, it is called client-side. Quote I like trains. Link to comment Share on other sites More sharing options...
shieldbug1 Posted October 11, 2014 Share Posted October 11, 2014 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. Quote 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. Link to comment Share on other sites More sharing options...
UntouchedWagons Posted October 11, 2014 Author Share Posted October 11, 2014 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? Quote I like trains. Link to comment Share on other sites More sharing options...
shieldbug1 Posted October 11, 2014 Share Posted October 11, 2014 Check if your itemstack#getItem is returning null first. Quote 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. Link to comment Share on other sites More sharing options...
Ewe Loon Posted October 11, 2014 Share Posted October 11, 2014 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 Quote Link to comment Share on other sites More sharing options...
UntouchedWagons Posted October 11, 2014 Author Share Posted October 11, 2014 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. Quote I like trains. Link to comment Share on other sites More sharing options...
Ewe Loon Posted October 11, 2014 Share Posted October 11, 2014 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 Quote Link to comment Share on other sites More sharing options...
UntouchedWagons Posted October 12, 2014 Author Share Posted October 12, 2014 this is probibly because Blocks.brewing_stand is being used not Items.brewing_stand What. The. Hell. Well that works. Quote I like trains. Link to comment Share on other sites More sharing options...
UntouchedWagons Posted October 12, 2014 Author Share Posted October 12, 2014 I'm not sure I understand. Quote I like trains. Link to comment Share on other sites More sharing options...
Eternaldoom Posted October 12, 2014 Share Posted October 12, 2014 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. Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button! Link to comment Share on other sites More sharing options...
Recommended Posts
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.