Jump to content

[1.11.2] Confused with Generating Loot


Tony_The_Tiger

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

(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.

 

tcXnkUz.png

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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) :P

 

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Your drivers are in a broken state, follow the guide in the FAQ: https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/#:~:text=How do I update my drivers%3F
    • A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffc3fe22b60, pid=15228, tid=5140 # # JRE version: OpenJDK Runtime Environment Microsoft-8035246 (17.0.8+7) (build 17.0.8+7-LTS) # Java VM: OpenJDK 64-Bit Server VM Microsoft-8035246 (17.0.8+7-LTS, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) # Problematic frame: # C [atio6axx.dll+0x192b60] # # No core dump will be written. Minidumps are not enabled by default on client versions of Windows # # If you would like to submit a bug report, please visit: # https://aka.ms/minecraftjavacrashes # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug i have no idea why please help
    • Quick-Books is great with regards to coordinating your monetary data. You can decide to live talk with a specialist at Quick-Books to get the answer for your questions. You will actually want to get to the talk going to the landing page and call us +1855-210-1428.
    • Update: I managed to make the item not disappear after crafting, but it doesn't remove any durability. import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.enchantment.UnbreakingEnchantment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class NuggetHammer extends Item { private boolean damage; public NuggetHammer(Properties p_i48487_1_) { super(p_i48487_1_); } @Override public int getMaxDamage(ItemStack stack) { return 54 - 1; } public boolean isBarVisible(ItemStack stack) { return false; } @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack copy = stack.copy(); copy.setCount(1); if (!this.damage) return copy; int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, stack); for (int i = 0; i < unbreaking; i++) { if (UnbreakingEnchantment.shouldIgnoreDurabilityDrop(stack, unbreaking, random)) return copy; } copy.setDamageValue(stack.getDamageValue() + 1); if (copy.getDamageValue() > stack.getMaxDamage()) return ItemStack.EMPTY; return copy; } }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.