Jump to content

[1.14.4] Can't figure out to add entry to already existing lootpool


Recommended Posts

Posted (edited)

So I tried to make it so that my newly added seeds drop when breaking grass, just like wheat seeds. I couldn't get it working so I tried to do what @Draco18s mentioned in an earlier thread.

 

Here's what I did

Spoiler

@Mod.EventBusSubscriber(modid = BoneAppleTea.MOD_ID)
public class EventHandlers {

    @SubscribeEvent
    public static void onLootLoad(LootTableLoadEvent event) {
        if (event.getName().equals(new ResourceLocation("minecraft", "blocks/grass"))) {
			event.getTable().addPool(LootPool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(BoneAppleTea.MOD_ID, "blocks/grass"))).build());
        }
    }
}

 

 

And here's the json file I created:

Spoiler

{
  "type": "minecraft:block",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:alternatives",
          "children": [
            {
              "type": "minecraft:item",
              "conditions": [
                {
                  "condition": "minecraft:random_chance",
                  "chance": 0.125
                }
              ],
              "functions": [
                {
                  "function": "minecraft:apply_bonus",
                  "enchantment": "minecraft:fortune",
                  "formula": "minecraft:uniform_bonus_count",
                  "parameters": {
                    "bonusMultiplier": 2
                  }
                },
                {
                  "function": "minecraft:explosion_decay"
                }
              ],
              "name": "boneappletea:barley_seeds"
            }
          ]
        }
      ]
    }
  ]
}

 

 

This is all similar to what Draco18s did in his mod:

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

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

 

The problem is that this adds a new pool to the already existing loot table for minecraft:grass. This makes it so that when you shear grass, the seeds from my mod can still drop. To fix this I don't want to add a new pool to the table, but modify the already existing table (the one which tells it to drop grass when using shears, and when not using shears have a chance to drop wheat seeds). If I can add an entry to this table then grass will: A: drop itself when using shears, B: sometimes drop wheat seeds, or C : sometimes drop my seeds.

 

I tried to add an entry to the pool but because addEntry can not be directly used (it is commented out in LootPool.class, I have no idea why) I did the following:

Spoiler

@Mod.EventBusSubscriber(modid = BoneAppleTea.MOD_ID)
public class EventHandlers {

    @SubscribeEvent
    public static void onLootLoad(LootTableLoadEvent event) {
        if (event.getName().equals(new ResourceLocation("minecraft", "blocks/grass"))) {

            LootPool pool = event.getTable().getPool("main");
            LootPool newPool = pool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(BoneAppleTea.MOD_ID, "blocks/grass"))).build();

            event.getTable().addPool(newPool);
            event.getTable().removePool("main");
        }
    }
}

 

This also didn't work because now the original LootPool is not working and only the entry that I added. Grass can now only drop my seeds, even when using shears. Wheat seeds or grass itself don't drop anymore. I also tried this:

Spoiler

@Mod.EventBusSubscriber(modid = BoneAppleTea.MOD_ID)
public class EventHandlers {

    @SubscribeEvent
    public static void onLootLoad(LootTableLoadEvent event) {
        if (event.getName().equals(new ResourceLocation("minecraft", "blocks/grass"))) {

            LootPool pool = event.getTable().getPool("main");
            event.setTable(LootTable.builder().addLootPool(pool.builder().addEntry(TableLootEntry.builder(new ResourceLocation(BoneAppleTea.MOD_ID, "blocks/grass")))).build());
        }
    }
}

 

The result of this was the same as the thing I tried earlier: only my seeds drop. Wheat seeds and grass itself don't drop anymore.

 

If someone could help me with this that would be greatly appreciated.

Edited by Tieso2001
Posted

That gets tricky.

The only thing I can suggest is doing what I did back in 1.12:

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

I have not updated this class and it does some reflection magic to get access to things, but it will let you directly modify loot pools. Or at least, give you the information necessary to write such a hook.

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.

Posted

Thanks for the information. I was hoping that it would be easier than that. Hope forge will add an easy way to do this because adding seeds to grass in 1.12.2 was really easy, using just one line of code.

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.