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'