Jump to content

Incompatible LootConditions? (1.16.X) [Solved]


urbanxx001

Recommended Posts

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
Link to comment
Share on other sites

The TOOL parameter is only set when mining a block. You do not use a "tool" on an entity.

You have to use the "damage_source_properties" condition. In there you can specify an entity predicate for the "source_entity" (the entity that applied the damage, either directly (via sword) or indirectly (e.g. via arrow)). This entity predicate can then have a predicate for the held item.

You can find documentation for the JSON predicates on the Minecraft Wiki: https://minecraft.fandom.com/wiki/Predicate.

  • Thanks 1
Link to comment
Share on other sites

  • 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
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.