Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Incompatible LootConditions? (1.16.X) [Solved]

Featured Replies

Posted

I have a loot modifier that updates all loot tables to drop specific items when using certain tools. Or at least I thought it did. It works on blocks, but not for entities. However I've tested it with the condition "killed_by_player" and that works for entities, the problem is testing these conditions together fails:

Spoiler
{
  "type": "mod_id:my_modifier",
  "conditions": [
    {
      "condition": "minecraft:match_tool",
      "predicate": {
        "tag": "mod_id:my_tools"
      }
    },
    {
      "condition": "minecraft:killed_by_player"
    }
  ]
}

So then I tried creating a custom ILootCondition, which registered fine but still failed:

Spoiler
public class MatchToolKilledByPlayer implements ILootCondition {
    private final ItemPredicate predicate;

    public MatchToolKilledByPlayer(ItemPredicate predicate) {
        this.predicate = predicate;
    }

    public LootConditionType getType() {
        return new LootConditionType(new MatchToolKilledByPlayer.Serializer());
    }

    public Set<LootParameter<?>> getReferencedContextParams() {
        return ImmutableSet.of(LootParameters.TOOL, LootParameters.LAST_DAMAGE_PLAYER);
    }

    public boolean test(LootContext p_test_1_) {
        ItemStack itemstack = p_test_1_.getParamOrNull(LootParameters.TOOL);
        return itemstack != null && this.predicate.matches(itemstack) && p_test_1_.hasParam(LootParameters.LAST_DAMAGE_PLAYER);
    }

    public static class Serializer implements ILootSerializer<MatchToolKilledByPlayer> {
        public void serialize(JsonObject p_230424_1_, MatchToolKilledByPlayer p_230424_2_, JsonSerializationContext p_230424_3_) {
            p_230424_1_.add("predicate", p_230424_2_.predicate.serializeToJson());
        }

        public MatchToolKilledByPlayer deserialize(JsonObject p_230423_1_, JsonDeserializationContext p_230423_2_) {
            ItemPredicate predicate = ItemPredicate.fromJson(p_230423_1_.get("predicate"));
            return new MatchToolKilledByPlayer(predicate);
        }
    }
}

 

If anyone has advice I'd be very appreciative.

Edited by urbanxx001

  • urbanxx001 changed the title to Incompatible LootConditions? (1.16.X) [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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.