KeeganDeathman Posted September 6, 2016 Posted September 6, 2016 Okay, so like a good boy I switched to set and getRegistryName(), but now whenever i use the getter, I get an NPE. Why? I set the registry name? Any help? Quote [shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]
Draco18s Posted September 6, 2016 Posted September 6, 2016 Post your code, we're not psychic. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
KeeganDeathman Posted September 6, 2016 Author Posted September 6, 2016 Here's a sample block declaration labstuffBlocks.add(blockAcceleratorPowerInput = new BlockAcceleratorPowerInput().setRegistryName("labstuff","blockAcceleratorPowerInput").setCreativeTab(tabLabStuff)); And my registry code for(Block block : labstuffBlocks) { GameRegistry.register(block, block.getRegistryName()); GameRegistry.register(Item.getItemFromBlock(block).setRegistryName(block.getRegistryName()), block.getRegistryName()); } Quote [shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]
Draco18s Posted September 6, 2016 Posted September 6, 2016 Betcha it's this part here: Item.getItemFromBlock(block) Just because you called GameRegistry.register on a block does not mean your block has an item. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
KeeganDeathman Posted September 6, 2016 Author Posted September 6, 2016 Interesting, that must be new. However, it also happened in this(now since reworked) functions in a block class @Override public boolean isOpaqueCube(IBlockState state) { if(getRegistryName().getResourcePath().contains("Glass") || getRegistryName().getResourcePath().contains("Rotor")) return false; return true; } Quote [shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]
Animefan8888 Posted September 6, 2016 Posted September 6, 2016 Interesting, that must be new. However, it also happened in this(now since reworked) functions in a block class @Override public boolean isOpaqueCube(IBlockState state) { if(getRegistryName().getResourcePath().contains("Glass") || getRegistryName().getResourcePath().contains("Rotor")) return false; return true; } If you are getting a NPE just run a check to see if it is != null. Though I can not see the error report to give you anymore guidance. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
Matryoshika Posted September 6, 2016 Posted September 6, 2016 If the NPE is caused by getRegistryName() , then either the item/block you are trying to get the registry name of, does not have a registry name, or you are trying to access the registry name before you actually do set it. If the NPE is caused by the, as mentioned, Item.getItemFromBlock(block) , then skip that method altogether. Instead, create an ItemBlock using the block as the passed parameter, and then register that. ItemBlock is instantiated just like an ItemStack. Quote Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
LexManos Posted September 6, 2016 Posted September 6, 2016 Also, DO NOT run fundemental aspects of your code based off string comparisons of registry names. Seriously... Set a field for the opaquenss and use that... Quote I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
jeffryfisher Posted September 6, 2016 Posted September 6, 2016 I switched to set and getRegistryName(), but now whenever i use the getter, I get an NPE. Why? You asked about an NPE without posting the crash report. Perhaps the forum needs a banner or sticky rules to warn against that again. As Draco says, we're not psychic. Rerun your code in the debugger (setting a breakpoint ahead of the crash point). Examine the fields about to be used in the crash. See what is null. Fix it. Further, since order of execution is often the cause of an NPE, we need to see whole classes, not just lines out of context. You could also put print statements in both your get and set to see which runs first (then use the debugger to examine the call stack). Finally, when referring to a class's methods and fields that are not static, get into the habit of prefixing them with "this." 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.
shadowfacts Posted September 6, 2016 Posted September 6, 2016 Finally, when referring to a class's methods and fields that are not static, get into the habit of prefixing them with "this." That's completely personal preference and doesn't have any affect on the compiled code (excepting overloaded parameters). I personally don't use this because I feel it's unnecessarily verbose and doesn't provide any valuable information. Quote Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
jeffryfisher Posted September 7, 2016 Posted September 7, 2016 Actually, using "this" is a good habit because it will sometimes remind you when you that you have a static vs instance conflict (at least it will have you thinking about it). Well, you might never do anything that careless, but if I revisit code after months away doing something else, I sometimes break it, and I like having Eclipse tell me so sooner rather than later. 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.
Draco18s Posted September 7, 2016 Posted September 7, 2016 I have an IDE that formats static in italics, so I don't have that problem. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.