Jump to content

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


Triphion

Recommended Posts

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 ^^

Link to comment
Share on other sites

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 by oldcheese
You can't just initiate a new lootpool, not sure why I thought you could.
Link to comment
Share on other sites

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 by Triphion
Link to comment
Share on other sites

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. 

 

 

Link to comment
Share on other sites

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 by Triphion
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Triphion
Link to comment
Share on other sites

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.

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

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 by Triphion
Link to comment
Share on other sites

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

Edited by Draco18s

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

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 by Triphion
Link to comment
Share on other sites

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.

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.

Announcements



×
×
  • Create New...

Important Information

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