Jump to content

[1.15] Modifying Loot Tables [SOLVED]


Tikaji

Recommended Posts

I'm having issues modifying the loot table specifically for the coral blocks. I have a global loot modifier set up that works for other blocks (cobblestone, gravel, etc), however it does not work on the coral blocks. I assume that it has something to do with the conditions already set in the loot table. I notice that when I mine coral blocks with a silk touch pickaxe my loot modifier is run, but when attempting to mine it with a custom item (my hammer) it does not work. I attempted to modify the table as follows:

{
  "type": "minecraft:block",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:alternatives",
          "children": [
            {
              "type": "minecraft:item",
              "conditions": [
                {
                  "condition": "minecraft:alternative",
                  "terms": [
                    {
                      "condition": "minecraft:match_tool",
                      "predicate": {
                        "tag": "exnihilosequentia:hammer"
                      }
                    },
                    {
                      "condition": "minecraft:match_tool",
                      "predicate": {
                        "enchantments": [
                          {
                            "enchantment": "minecraft:silk_touch",
                            "levels": {
                              "min": 1
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              ],
              "name": "minecraft:tube_coral_block"
            },
            {
              "type": "minecraft:item",
              "conditions": [
                {
                  "condition": "minecraft:survives_explosion"
                }
              ],
              "name": "minecraft:dead_tube_coral_block"
            }
          ]
        }
      ]
    }
  ]
}

 

For the predicate that I added, I did add the tag I specified and my items are registered to that tag.

 

What am I missing to get this to work?

 

(Also, sorry about the big code block, I've forgotten how to do spoilers....)

Link to comment
Share on other sites

You aren't supposed to modify the original loot table json when using Loot Modifiers.

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

Then your modifier is broken, as even an empty loot drop list will still invoke all modifiers.

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

Ok, so my modifier looks like the following:

public class UseHammerModifier extends LootModifier {

    public UseHammerModifier(ILootCondition[] conditionsIn) {
        super(conditionsIn);
    }

    @Nonnull
    @Override
    public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
        LogUtil.info("Fired Modifier");
        ItemStack  tool       = context.get(LootParameters.TOOL);
        BlockState blockState = context.get(LootParameters.BLOCK_STATE);
        if (tool != null && blockState != null) {
            if (tool.getItem() instanceof HammerBaseItem) {
                List<ItemStack> newLoot     = new ArrayList<>();
                Block           returnBlock = ModRegistries.HAMMER
                    .getResult(blockState.getBlock().getRegistryName());
                newLoot.add(new ItemStack(returnBlock));
                return newLoot;
            }
        }
        return generatedLoot;
    }

    public static class Serializer extends GlobalLootModifierSerializer<UseHammerModifier> {


        @Override
        public UseHammerModifier read(ResourceLocation location, JsonObject object,
            ILootCondition[] ailootcondition) {
            LogUtil.info("UseHammerModifier.Serializer.read");
            return new UseHammerModifier(ailootcondition);
        }
    }
}

 

I have a file under data/<mymodid>/loot_modifiers that looks like:

{
  "type": "exnihilosequentia:use_hammer",
  "conditions": [
    {
      "condition": "minecraft:alternative",
      "terms": [
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:cobblestone"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:gravel"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:sand"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:andesite"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:diorite"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:granite"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:netherrack"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:end_stone"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:tube_coral_block"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:brain_coral_block"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:bubble_coral_block"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:fire_coral_block"
        },
        {
          "condition": "minecraft:block_state_property",
          "block": "minecraft:horn_coral_block"
        }
      ]
    }
  ]
}

 

The modifier is fired for all the blocks in the list, except for the coral blocks. What is wrong with my modifier to cause it to only fire with those blocks? You said that it should fire even when an empty drop happens, but that's not the case here.

Link to comment
Share on other sites

I've updated the file in data/<mymodid>/loot_modifiers to the following and still get the same result: 

{
  "type": "exnihilosequentia:use_hammer",
  "conditions": [
    {
      "condition": "minecraft:match_tool",
      "predicate": {
        "tag": "exnihilosequentia:hammer"
      }
    }
  ]
}

A tag file does exist and the modifier still fires for the same blocks in the previous post, except for coral blocks.

Link to comment
Share on other sites

Go into the ForgeHooks class (net.minecraftforge.common) and drop a breakpoint all the way down towards the bottom inside the modifyLoot method and use the debugger to see what's going on.

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

Nothing I can see in the Coral block class indicates that it should bypass that method. Its called directly from the LootTable class

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

That's very strange.

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

Figured it out. I did some digging and figured out that it was calling the base Item class' canHarvestBlock which has to be true in order for the block drops to be generated. So, my loot modifier works just fine, but the tool has to return that it can harvest the block you're mining.

Link to comment
Share on other sites

  • Tikaji changed the title to [1.15] Modifying Loot Tables [SOLVED]

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.