Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.11.2] How do i add additional loot to vanilla chests
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
Triphion

[1.11.2] How do i add additional loot to vanilla chests

By Triphion, October 9, 2017 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted October 9, 2017

How would i do this correctly? I have made myself a registering loot tables class Here and also registered it into my init constructor inside my main class. I read the forge docs and sort of found out how to register and add new loot tables, but didn't understand where i would put certain events and such. Forge Docs 

Any answers is highly appreciated ^^

  • Quote

Share this post


Link to post
Share on other sites

oldcheese    16

oldcheese

oldcheese    16

  • Creeper Killer
  • oldcheese
  • Members
  • 16
  • 102 posts
Posted October 9, 2017 (edited)

You can put the Event anywhere.

 

What you want to do is take that event from the forge docs that you linked, put them in any class. I personally recommend making a package where you can put your events so you can always check on them later.

Then in your Main class you want to register the event using something similar to this: 


        MinecraftForge.EVENT_BUS.register( new ClassContainingEvent() );

 

You register events during the PreInit phase of loading, there's no need to put it in a proxy for this particular event. You can pretty much use any class you want to put in an event. If you have a class shooting a character off high in the air you can put a falldamageEvent in there and then pass it off to the event bus. You might want to read the bit on events , but honestly just registering the event and writing the event bit should be enough to do what you want. 

 

@SubscribeEvent
public void lootLoad(LootTableLoadEvent evt) {
    if (evt.getName().toString().equals("minecraft:chests/simple_dungeon")) {
        /* do stuff with evt.getTable() like
		LootTable table = evt.getTable();
		//code to retrieve a lootpool
		table.mergePool(merge.getPool("main");
		evt.setTable(table);
		*/
    }
}

 

You need to register your loot table as a JSON. I assume that "Dungeon_scrolls" is a loottable JSON.  Also make sure that your Dungeon_Scrolls is in the folder /assets/modid/loot_tables/name.json, 

 

Once you have the event set up you can do stuff like evt.setTable, or you can evt.getTable and then merge the lootpools of the loottables. All of which are described in the LootTable class. 

 

Edit: I'm writing this up from my college PC, so I don't have IntelliJ to verify the exact commands you'd use. But I think this should help a fair bit. If you have any questions, feel free to burst loose.

 

Edited October 9, 2017 by oldcheese
You can't just initiate a new lootpool, not sure why I thought you could.
  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted October 9, 2017 (edited)

I made a package that i call "handlers" in which i have put the eventhandler class, which i've given the name "ModEventHandler".  And in this class i have done the lootload event as in the forge docs. Also done the registering of the event in the preinit call 

		//Eventhandler
		MinecraftForge.EVENT_BUS.register(new ModEventHandler());

Then, how do i merge the loot tables? And by the way, is this a correct way of registering the loot table? Also, dungeon_scrolls.json is in /assets/modid/loot_tables/scrolls/

Edited October 9, 2017 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

oldcheese    16

oldcheese

oldcheese    16

  • Creeper Killer
  • oldcheese
  • Members
  • 16
  • 102 posts
Posted October 9, 2017

if it's in loot_tables/scrolls then you must reflect this in your registration. Since the default area is the loot_tables pool (According to the resources) you should put the location as "scrolls/dungeon_scrolls" 

 

The register you did seems to be alright. As long as you call ModLoot.Register() in your main class. 

 

What you want to do is get a LootPool from your JSON.

 

The code that the Docs gives is the following: 

LootEntry entry = new LootEntryTable(new ResourceLocation("mymod:inject/simple_dungeon"), <weight>, <quality>, <conditions>, <entryName>); // weight doesn't matter since it's the only entry in the pool. Other params set as you wish.

LootPool pool = new LootPool(new LootEntry[] {entry}, <conditions>, <rolls>, <bonusRolls>, <name>); // Other params set as you wish.

evt.getTable().addPool(pool);

 

You'd add something like that, obviously containing the proper code instead of <>'s and add it to the Event handler.  Obviously the resourcelocation would be adjusted for your own mod. 

 

Botania has a good example of how they added loot, look at the getInjectPool and getInjectEntry at the bottom most of all. If you don't know how switches work, basically all cases jump down untill either it returns or breaks anything. So what it says there is that depending on what string they will just add a pool to the table, a pool gotten by the getInjectPool.

 

The getInjectPool then gets an InjectEntry and yada yada. The code speaks for itself. Looking at that you should be able to figure out how to retrieve a lootpool and a lootentry. 

 

 

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted October 9, 2017 (edited)

Aight, then what exactly does all the other parameters mean? Such as

Quote

<weight>, <quality>, <conditions>, <entryName>

<conditions>, <rolls>, <bonusRolls>, <name>

Like, what does that to my loot table? And what should i put in? 

 

Would this be valid? 

	@SubscribeEvent
	public void lootLoad(LootTableLoadEvent evt) {
	        /* do stuff with evt.getTable() like
			LootTable table = evt.getTable();
			LootTable merge = MyCustomTable;
			table.mergePool(merge.getPool("main");
			evt.setTable(table);
			*/
			String prefix = "minecraft:chests/";
			String name = evt.getName().toString();

			if (name.startsWith(prefix)) {
				String file = name.substring(name.indexOf(prefix) + prefix.length());
				switch (file) {
				case "abandoned_mineshaft":
				case "desert_pyramid":
				case "jungle_temple":
				case "simple_dungeon": evt.getTable().addPool(getInjectPool(file)); break;
				case "spawn_bonus_chest":
				case "stronghold_corridor":
				case "village_blacksmith": evt.getTable().addPool(getInjectPool(file)); break;
				default: break;
				}
			}
	    }
		private LootPool getInjectPool(String entryName) {
			return new LootPool(new LootEntry[] { getInjectEntry(entryName, 1) }, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(0, 1), "dungeon_scrolls_pool");
		}

		private LootEntryTable getInjectEntry(String name, int weight) {
			return new LootEntryTable(new ResourceLocation(Reference.MODID, "scrolls/" + name), weight, 0, new LootCondition[0], "dungeon_scrolls_entry");
		}

I do not quite understand the break function still tho. 

Edited October 9, 2017 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

oldcheese    16

oldcheese

oldcheese    16

  • Creeper Killer
  • oldcheese
  • Members
  • 16
  • 102 posts
Posted October 9, 2017

Weight can be empty, but usually defines the chance an item will be picked If you have 2 pools they can have different weights so one pool is more likely to show items. (I believe)

The quality relates to weight. But is modifyable by a player's luck attribute.

 

Bonus rolls is a chance for the player to roll an additional time from this pool. Bonus rolls can be more than 1, so you can have a bonus rolls value of 6 and the chest will always contain  at least 7 items.  Botania makes a 'random' amount of bonusrolls by using a new RAndomValueRange(0,1) which means that there's either 1 or 2 rolls.  Which makes sense since if you always want 7 rolls you can just set the amount of rolls to 7.

 

<Rolls> is the amount of rolls you'd have, so if it's 10 then you'll get 10 items from your table.

 

The name, obviously, is just a name.

 

The only confusing thing you might be baffled by is the LootConditions, since lootconditions is the only part where you can't just put in a number. 

 

The condition is something that is basically a check of "Does the player have this value?"  If one condition fails it aborts the picking from the lootpool. 

 

Conditions is a list. So you can simply pass it an empty list by passing a 

new LootCondition[0]

you could also add conditions.  I believe the conditions right now are random_chance, killed_by_player, entity_properties, entity_scores. Entity properties has the "on fire" modifier. 

 

If you wanted to use a condition you could pass: 
 

new LootCondition[]{new KilledByPlayer(false), new RandomChanceWithLooting(0.07f, 0.05f)}

 

for example. Tinker's construct does something similar.

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted October 9, 2017 (edited)

Okey, what would i do if i wanted the "dungeon_scrolls" loot table to spawn in all possible chests? Not just in the "simple_dungeon". Would that be to use the switch function which Botania used? Or is there another method? 

Edited October 9, 2017 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 14011 posts
Posted October 9, 2017

You can also create your own loot conditions. e.g. I have this one in my code (registered here) which prevents loot drops when an entity is killed by Wither damage (which I use to kill animals that are dying of old age; the odds of wither damage from another source is low, but remains thematically appropriate).

 

There's also loot functions. Handles things like metadata, stack count, enchantments (e.g. the Looting Enchantment Bonus). Creating the "add this to the loot pool" function in my LootUtils class was a pain in the arse.

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted October 9, 2017 (edited)

Okay, that's pretty neat. Well, i'm sort of stuck here. 

LootPool pool = new LootPool(new LootEntry[] {entry}, new LootCondition[0], 3, 2, "scrolls_pool");

I do not know what to put in the 

new LootEntry[] {entry}

 

Edited October 9, 2017 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 14011 posts
Posted October 9, 2017 (edited)

entry = new LootEntryItem(item, weight, 1, <functions>, <conditions>, name);

Edited October 9, 2017 by Draco18s
  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted October 9, 2017 (edited)

Like this?

LootPool pool = new LootPool(new LootEntry[] {entry = new LootEntryItem(itemIn, weightIn, qualityIn, functionsIn, conditionsIn, entryName)}, new LootCondition[0], 3, 2, "scrolls_pool");

Well, i don't understand why 

new LootEntryItem

is the way to go though. 

Also, what is the "function" parameter?

This gives me a bunch of errors

LootPool pool = new LootPool(new LootEntry[] {entry = new LootEntryItem(ModScrolls.scroll, 0, 0, 0, new LootCondition[0], "scroll")}, new LootCondition[0], 3, 2, "scrolls_pool");

Lol, im hopeless, wow. 

Edited October 9, 2017 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 14011 posts
Posted October 9, 2017

entry = isn't needed, you asked what went inside {entry} and I said "entry = " meaning "replace that bit that isn't code with this bit that is code.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • BitNet_
      [1.12.2] Exception loading model

      By BitNet_ · Posted 8 minutes ago

      That hasn't worked for me, I still get the model registering error even when adding the code to my build.gradle
    • JMAS
      Recompile mod with newer version of Java?

      By JMAS · Posted 11 minutes ago

      Thank you for your quick and direct response.   After making the changes directed, I now receive the following error: Execution failed for task ':runClient'. > Process 'command 'C:\Program Files\Java\jdk1.8.0_231\bin\java.exe'' finished with non-zero exit value 1    No new debug.log was generated in run/logs. 😕
    • Lea9ue
      .setRepairItem not work

      By Lea9ue · Posted 25 minutes ago

      In your item class you should have something like...   @Override public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { if (toRepair.getItem().equals("YOUR ITEM") && repair.getItem().equals("WHAT REPAIRS IT")) { return true; } else { return false; } }  
    • Electrodynamite12
      .setRepairItem not work

      By Electrodynamite12 · Posted 32 minutes ago

      I made the ToolMaterial, and i add the .setRepairItem method, announced the ItemStack, where indicated the target item. Maybe i made something wrong? public static Item.ToolMaterial HLOMINITE = EnumHelper.addToolMaterial("another_test:hlominite", 5, 1000, 50.0F, 16.0F, 76).setRepairItem(new ItemStack(ItemsRegister.HLOMINGOT));
    • diesieben07
      [1.12.2] Exception loading model

      By diesieben07 · Posted 1 hour ago

  • Topics

    • BitNet_
      2
      [1.12.2] Exception loading model

      By BitNet_
      Started 8 hours ago

    • JMAS
      6
      Recompile mod with newer version of Java?

      By JMAS
      Started 10 hours ago

    • Electrodynamite12
      1
      .setRepairItem not work

      By Electrodynamite12
      Started 32 minutes ago

    • Hemeroahz
      5
      1.12.2 Crashing Upon Running Forge

      By Hemeroahz
      Started November 27, 2017

    • zhubwat
      9
      Forge not creating version .jar files?

      By zhubwat
      Started January 25, 2016

  • Who's Online (See full list)

    • JMAS
    • imacatlolol
    • saxon564
    • BitNet_
    • AJGingy
    • Lordyammer
    • ItzGenes
    • Nuparu00
    • M1ntcraft3r
    • fcelon
    • KolonilGamer
    • Choonster
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.11.2] How do i add additional loot to vanilla chests
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community