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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • BD303 merupakan salah satu situs slot mudah scatter paling populer dan digemari oleh kalangan slot online di tahun 2024 mainkan sekarang dengan kesempatan yang mudah menang jackpot jutaan rupiah.
  • Topics

×
×
  • Create New...

Important Information

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