Posted January 14, 20178 yr I want to add my two custom items to chests that generate along with the world. I want it so that between 1-25 coins in a stack have a chance of appearing, seems simple enough right? But after looking through various GitHub entries and how-to, I just can't get my head around the Forge Loot System. I added two item entries to test out the system but I get a nullpointer exception. Any suggestions as to how I go about this? Here's my code. Also lootLoad doesn't need @SubscribeEvent because that was already done in my EventHandlerClass. package com.TonyTiger.simplecoins.world; import com.TonyTiger.simplecoins.Main; import com.TonyTiger.simplecoins.items.ModItems; import net.minecraft.util.ResourceLocation; import net.minecraft.world.storage.loot.LootContext; import net.minecraft.world.storage.loot.LootEntry; import net.minecraft.world.storage.loot.LootEntryItem; import net.minecraft.world.storage.loot.LootEntryTable; import net.minecraft.world.storage.loot.LootPool; import net.minecraft.world.storage.loot.LootTableList; import net.minecraft.world.storage.loot.conditions.LootCondition; import net.minecraft.world.storage.loot.functions.LootFunction; import net.minecraftforge.event.LootTableLoadEvent; public class genCoinsInWorld { //10% chance for gold coins to spawn, 5% chance for iron coins to spawn public static int goldChance = 10, ironChance = 5; public static int minGoldGen = 0, maxGoldGen = 25, minIronGen = 0, maxIronGen = 25; public static final ResourceLocation SIMPLECOINS_LOOT_TABLE = LootTableList.register(new ResourceLocation(Main.MODID, "simplecoins_loot_table")); public static void lootLoad(LootTableLoadEvent event){ if(!event.getName().getResourceDomain().equals("Minecraft") && !event.getName().getResourcePath().contains("/") && !event.getName().getResourcePath().contains("CHEST")) return; // LootEntry LE = new LootEntryTable(SIMPLECOINS_LOOT_TABLE, 25, 0, // new LootCondition[0], "simplecoins:loot_table"); LootEntry iron = new LootEntryItem(ModItems.IRONCOIN, goldChance, 0, new LootFunction[0], new LootCondition[0], "simplecoins:loot_ironcoin"); LootEntry gold = new LootEntryItem(ModItems.IRONCOIN, ironChance, 0, new LootFunction[0], new LootCondition[0], "simplecoins:loot_goldcoin"); LootPool main = event.getTable().getPool("main"); main.addEntry(gold); main.addEntry(iron); } } And the error message when I try to generate a world. ---- Minecraft Crash Report ---- // Hey, that tickles! Hehehe! Time: 1/14/17 5:19 PM Description: Exception in server tick loop com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201) at com.google.common.cache.LocalCache.get(LocalCache.java:3934) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821) at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4827) at net.minecraft.world.storage.loot.LootTableManager.getLootTableFromLocation(LootTableManager.java:39) at net.minecraft.world.storage.loot.LootTableManager.reloadLootTables(LootTableManager.java:48) at net.minecraft.world.storage.loot.LootTableManager.<init>(LootTableManager.java:34) at net.minecraft.world.WorldServer.init(WorldServer.java:156) at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:87) at net.minecraft.server.integrated.IntegratedServer.init(IntegratedServer.java:124) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:507) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at com.TonyTiger.simplecoins.world.genCoinsInWorld.lootLoad(genCoinsInWorld.java:36) at com.TonyTiger.simplecoins.event.EventHandlerCommon.lootLoad(EventHandlerCommon.java:63) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_EventHandlerCommon_lootLoad_LootTableLoadEvent.invoke(.dynamic) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) at net.minecraftforge.event.ForgeEventFactory.loadLootTable(ForgeEventFactory.java:628) at net.minecraftforge.common.ForgeHooks.loadLootTable(ForgeHooks.java:1103) at net.minecraft.world.storage.loot.LootTableManager$Loader.loadBuiltinLootTable(LootTableManager.java:148) at net.minecraft.world.storage.loot.LootTableManager$Loader.load(LootTableManager.java:71) at net.minecraft.world.storage.loot.LootTableManager$Loader.load(LootTableManager.java:52) at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317) at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280) at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195) ... 12 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details: Minecraft Version: 1.11.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_111, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 232640400 bytes (221 MB) / 542638080 bytes (517 MB) up to 928514048 bytes (885 MB) JVM Flags: 0 total; IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP 9.38 Powered by Forge 13.20.0.2206 6 mods loaded, 6 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored UCHIJAA minecraft{1.11.2} [Minecraft] (minecraft.jar) UCHIJAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) UCHIJAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11.2-13.20.0.2206.jar) UCHIJAA forge{13.20.0.2206} [Minecraft Forge] (forgeSrc-1.11.2-13.20.0.2206.jar) UCHIJAA simplecoins{0.6.0} [simple Coins] (bin) UCHIJAA examplemod{1.0} [Example Mod] (bin) Loaded coremods (and transformers): GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Player Count: 0 / 8; [] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' I don't know anything.
January 14, 20178 yr Caused by: java.lang.NullPointerException at com.TonyTiger.simplecoins.world.genCoinsInWorld.lootLoad(genCoinsInWorld.java:36) Looks like this line isn't working: LootPool main = event.getTable().getPool("main"); 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.
January 14, 20178 yr Was writing the same thing as Draco. Also, please name your packages in lowercase and start your class name with an uppercase. It's a java standard ^^
January 14, 20178 yr Author Well, this is embarrassing. Thanks though, works now, just gotta set the possible stack sizes. public static void lootLoad(LootTableLoadEvent event){ if(!event.getName().getResourcePath().contains("chest")) return; LootEntry iron = new LootEntryItem(ModItems.IRONCOIN, 100, 0, new LootFunction[0], new LootCondition[0], "simplecoins:loot_ironcoin"); LootEntry gold = new LootEntryItem(ModItems.GOLDCOIN, 100, 0, new LootFunction[0], new LootCondition[0], "simplecoins:loot_goldcoin"); LootPool main = event.getTable().getPool("main"); main.addEntry(gold); main.addEntry(iron); } I don't know anything.
January 14, 20178 yr By the way, feel free to take a look at my LootUtils class and a very basic usage of same. (d7: any suggestions on how I'd make the giant list of ints more legible without having to check all the paramter names? Using variables would work, but would take up a bunch of lines...) 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.
January 14, 20178 yr Author By the way, feel free to take a look at my LootUtils class and a very basic usage of same. Thanks man! This should help me in figuring out what I should do! I don't know anything.
January 14, 20178 yr (d7: any suggestions on how I'd make the giant list of ints more legible without having to check all the paramter names? Using variables would work, but would take up a bunch of lines...) The latest version of IDEA will automatically show the name of any parameter you pass a literal value to, which would help with those methods. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
January 15, 20178 yr The latest version of IDEA will automatically show the name of any parameter you pass a literal value to, which would help with those methods. Oh that's nice. Shame I use Eclipse. Then again, I've been off in Unity3D land and you know what I miss? Refactor tools that do things other than "rename." Or the ability to define a super class and interfaces when creating a new class (Microsoft actually REMOVED this feature between 2005 and 2015....) or a builder: new LootBuilder() .item(<item>) .metaRange(<min>, <max>) .weight(<weight>) // and so on .addTo(<loot table>); Damn, should have thought of that. And I don't feel like refactoring it now... 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.
January 15, 20178 yr Refactor tools that do things other than "rename."You think that is a lot? Check this out (and I don't think that's even everything) No, I'm complaining that that's all Visual Studio has, and not more. I'm grouching that the things I want aren't there. I've used Extract Interface a dozen times, extract superclass at least twice. No push up/pull down, but I can see its use. Used Encapsulate fields a few times (usually through the auto-hinter). Use Interface Where Possible I've done when using Extract Interface/Superclass... I freaking love those options and I wish Visual Studio had them. 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.