Posted October 1, 20187 yr I need to loop through a list in an event handler (specifically for the HarvestDropsEvent), but when I use a for loop it throws a ticking world exception. Is there an accepted way of looping in event handlers?
October 1, 20187 yr Show what you tried. 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.
October 1, 20187 yr Author @SubscribeEvent public void blockBreak(HarvestDropsEvent event) { World world = event.getWorld(); if(!world.isRemote) { ForageTable table = ForageCraftMod.ForageDict.get(event.getState().getBlock()); java.util.List<ForagePool> pools = table.getPools(); for(int i = 0; i != pools.size(); i++) { ForagePool pool = table.getPool(i); if(CHANCE.nextFloat()<pool.getChance()) { event.getDrops().add(new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(pool.getItem())), pool.getAmount())); } } } } ForageDict is a hashtable using blocks as keys and returning a foragetable object. foragetables are containers for lists of foragepools, which hold a set of primitive values for use in this code, which adds new drops to blocks via json files.
October 1, 20187 yr Quote Caused by: java.lang.NullPointerException Its on line 31, whichever line that is. 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.
October 1, 20187 yr 4 minutes ago, Draco18s said: Its on line 31, whichever line that is. Don't you mean 33? Quote Caused by: java.lang.NullPointerException at com.theishiopian.foragecraft.handler.BlockForageHandler.blockBreak(BlockForageHandler.java:33) 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.
October 1, 20187 yr Then table.getPools(); returned null and you didn't check for that. 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.
October 1, 20187 yr Author It seems you are right, just calling table.getPools(); crashes the game. Whats perplexing is its just a simple return function. public List<ForagePool> getPools() { return this.table; } this.table is a list of foragetables.
October 1, 20187 yr Author SO, for clarification, are there no problems with using for loops in event handlers?
October 1, 20187 yr 5 minutes ago, theishiopian said: this.table Which must never be instantiated into an instance. 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.
October 1, 20187 yr 1 minute ago, theishiopian said: SO, for clarification, are there no problems with using for loops in event handlers? No there isn't. 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.
October 1, 20187 yr Author Ok, good to know. For some reason, my list is becoming null. The weird thing is that I can call from it elsewhere and get the correct result. Anyways, thanks for the clarification, that really helps narrow it down.
October 1, 20187 yr Author Also, what did you mean by "instantiated into an instance"? Do you mean initilized as an object? If so, I'm already doing that. ForageTable table = ForageCraftMod.ForageDict.get(event.getState().getBlock());
October 1, 20187 yr Author Ok, this is very bizzare. Whenever I try to reference my hashtable, I get a null pointer exception. But whenever I do a null check on it, it returns false.
October 1, 20187 yr A tip for combatting NPEs is to make everything that possibly can be final final. Then the compiler will let you know if you forgot to initialise your field. Step through your code with the debugger and find out why it’s null About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
October 1, 20187 yr Author Thanks for the tip. Im going to massively refactor this tomorrow. Ill also step through it with the debugger. I think it has to do with the way im creating the forage pools from json. Which is odd because it worked before. If i have any more issues tommorow, ill create a new thread. Night all.
October 1, 20187 yr 27 minutes ago, theishiopian said: Also, what did you mean by "instantiated into an instance"? Do you mean initilized as an object? If so, I'm already doing that. ForageTable table = ForageCraftMod.ForageDict.get(event.getState().getBlock()); What if that block doesnt have a ForageTable? Also why are you using a Block and not a IBlockState for your key. 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.
October 1, 20187 yr Author I know it has a foragetable. I think the foragetables are getting set to null somewhere. I hadnt considered using blockstates. Do they have a string representation like blocks do? (eg minecraft:dirt)
October 1, 20187 yr 18 minutes ago, theishiopian said: I hadnt considered using blockstates. Do they have a string representation like blocks do? (eg minecraft:dirt) Not an explicit one. It would first specify the Block I'd "minecraft:dirt" and then it would specify the property name and then the value, both can be represented by strings. 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.
October 1, 20187 yr 9 hours ago, theishiopian said: Do they have a string representation like blocks do? (eg minecraft:dirt) Its almost as if you've not actually played the game. 1) The F3 screen 2) The /give command 3) Blockstate JSON files (and the associated error messages when they aren't correct) All three of these use string representations of blockstates. Or there's just the sheer point that: anything can be turned into a string if you try hard enough. 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.
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.