Jump to content

[1.12.2] Adding an item to a loot table


Eilux

Recommended Posts

I have tried the following code:

@Mod.EventBusSubscriber
public class HorseMeatDrops {
    @SubscribeEvent
    public void onLootTablesLoaded(LootTableLoadEvent event){

        if (event.getName().equals(LootTableList.ENTITIES_HORSE)){
            final LootPool main = event.getTable().getPool("main");
            if (main != null) {
                new SetCount(new LootCondition[0],new RandomValueRange(1,3));
                main.addEntry(new LootEntryItem(ModItems.RAW_HORSE, 10, 0, new LootFunction[0], new LootCondition[0], "loottable:rawhorse" ));
            }
        }
    }

}

It dose not seem to be working however any help would be appreciated.

Link to comment
Share on other sites

44 minutes ago, Eilux said:

new SetCount(new LootCondition[0],new RandomValueRange(1,3));

This is unused. You create a SetCount object and then immediately discard it.

 

Also, you should definitely do this json-ly.

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderfarming/EventHandlers.java#L49-L57

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/resources/data/harderfarming/loot_tables/entities/leather.json

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

I don't think there's a LootPool builder in 1.12, so you have to set them up just with normal constructors*.

What I've done is as follows:

   Declare a LootEntry object using new LootEntryTable(ResourceLocation tableIn, int weightIn, int qualityIn, LootCondition[]

      conditionsIn, String entryName), where the ResourceLocation points towards your json file.

   Declare a new LootPool using the LootEntry with new LootPool(LootEntry[] lootEntriesIn, LootCondition[] poolConditionsIn, 

      RandomValueRange rollsIn, RandomValueRange bonusRollsIn, String name).

   Add the pool to the event's table

 

*Unless I'm unaware of something here?

Edited by SerpentDagger
Formatting is a fickle beast

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

34 minutes ago, Eilux said:

could you show me some kind of example?

This adds my custom loot, defined in the json file simple_chest, to all entries whose name contains "chests".

	@SubscribeEvent
	public void lootLoad(LootTableLoadEvent evt)
	{
		//Check for chest loot
		if (evt.getName().toString().contains("chests"))
		{
			//Declare entry
			LootEntry simpleDungeonEntry = new LootEntryTable(new ResourceLocation("artificialartificing:simple_chest"), 1, 0,
					new LootCondition[0], "artificialartificing:simple_chest_entry");
			
			//Declare pool with entry inside
			LootPool simpleDungeonPool = new LootPool(new LootEntry[] {simpleDungeonEntry}, new LootCondition[0],
					new RandomValueRange(1), new RandomValueRange(0, 1), "artificialartificing:simple_chest_pool");
			
			//Add pool to chest loot
			evt.getTable().addPool(simpleDungeonPool);
			
			//Print table that loot is being added to
			System.out.println("AA loot added to table: " + evt.getName().toString());
		}
	}

simple_chest.json

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

It still don't seem to work here is my code:

@Mod.EventBusSubscriber
public class HorseMeatDrops {
    @SubscribeEvent
    public void onLootTablesLoaded(LootTableLoadEvent event){

        if (event.getName().equals(LootTableList.ENTITIES_HORSE)){

            LootEntry rawEntry = new LootEntryTable(new ResourceLocation("eatahorse:raw_horse"), 1, 0,
                    new LootCondition[0], "eatahorse:raw_horse_entry");

            LootPool rawPool = new LootPool(new LootEntry[] {rawEntry}, new LootCondition[0],
                    new RandomValueRange(1), new RandomValueRange(0, 1), "eatahorse:raw_horse_pool");

            event.getTable().addPool(rawPool);
        }
    }
}

and here is the json file, the filepath to it is: resources/data/eatahorse/loot_tables/entities/raw_horse.json

{
  "type": "minecraft:entity",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "functions": [
            {
              "function": "minecraft:set_count",
              "count": {
                "min": 2.0,
                "max": 3.0,
                "type": "minecraft:uniform"
              }
            },
            {
              "function": "minecraft:looting_enchant",
              "count": {
                "min": 0.0,
                "max": 1.0
              }
            }
          ],
          "name": "eatahorse:raw_horse"
        }
      ]
    }
  ]
}

 

Link to comment
Share on other sites

As an aside, you've made sure that the methods run, right? lol

Beyond that, though, I think your json should be placed in resources/assets/eatahorse/loot_tables/, unless you change the path accordingly. Your json file also has some differences in formatting from mine, which might or might not be fine (I'm not fabulous with loot jsons, so I'll leave that to someone else)*.

 

*Edit: Here's a link to the loot table wiki. Tag structure is described in depth there.

Edited by SerpentDagger

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

29 minutes ago, SerpentDagger said:

As an aside, you've made sure that the methods run, right? lol

Beyond that, though, I think your json should be placed in resources/assets/eatahorse/loot_tables/, unless you change the path accordingly. Your json file also has some differences in formatting from mine, which might or might not be fine (I'm not fabulous with loot jsons, so I'll leave that to someone else).

Yeah you need to check if the class has been registered correctly, add some printlns to check is it actually being called

Link to comment
Share on other sites

6 hours ago, SerpentDagger said:

1.12

Oh. 1.12

Use this:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/util/LootUtils.java

 

Take that whole thing, put it in your project in (use your own package) and invoke its methods during the LootTableLoadEvent. (Yes, you can use it, its a utility class, I really don't care. I did a lot of futzing around figuring out how the stuff works so you don't have to)

Example usage
https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/farming/FarmingEventHandler.java#L425

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

I can't get it to work I created a test one that is very close to the example provided but it dose not seem to be doing anything.

@Mod.EventBusSubscriber(modid = Main.MODID)
public class HorseMeatDrops {
    @SubscribeEvent
    public void lootTableLoad(LootTableLoadEvent event) {
        //FamingBase.logger.log(Level.INFO, event.getName());
        LootCondition[] chance;
        LootCondition[] lootingEnchant;
        LootFunction[] count;
        LootEntryItem[] item;
        LootPool newPool;
        LootTable loot = event.getTable();
        if (event.getName().getPath().equals("entities/cow")) {
            LootUtils.removeLootFromTable(loot, Items.DIAMOND);
            LootUtils.addItemToTable(loot, Items.DIAMOND, 1, 2, 1, 2, 5, 0, 1, "minecraft:diamond",
                    new LootUtils.IMethod() {
                        @Override
                        public void FunctionsCallback(ArrayList<LootFunction> lootfuncs) {
                            LootCondition[] condition = {new EntityHasProperty(new EntityProperty[]{new EntityOnFire(true)}, LootContext.EntityTarget.THIS)};
                            LootFunction cooked = new Smelt(condition);
                            lootfuncs.add(cooked);
                            LootFunction looting = new LootingEnchantBonus(null, new RandomValueRange(1, 3), 0);
                            lootfuncs.add(looting);
                        }
                    });
        }
    }
}

 

Link to comment
Share on other sites

15 minutes ago, Eilux said:

HorseMeatDrops

15 minutes ago, Eilux said:

equals("entities/cow")

You seem to be wanting to affect the horse, but you look for cow.

 

16 minutes ago, Eilux said:

LootUtils.removeLootFromTable(loot, Items.DIAMOND);

That item doesn't exist in that loot table, so I'm not sure why you're doing that.

 

17 minutes ago, Eilux said:

LootUtils

Hopefully you pulled in my LootUtils class, yes?

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

I'm not sure what's up, then. I pretty rigorously made sure I got things working when I updated stuff.

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

1 hour ago, Eilux said:

was not static

That'd do it.

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.



×
×
  • Create New...

Important Information

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