mojira.dev
MC-169473

`apply_bonus` loot table function doesn't work on entity kills

The bug

The function apply_bonus takes an enchantment and some parameters to increase the item count of a loot table entry. This function is used in various vanilla block loot tables.

However it appears this does not work for entity loot tables although the enchantment context is still available, proven by the usage of the looting_enchant function, used in almost every mob loot table. This is inconsistent and no warning is given in the log it looks like there is now a warning.

How to reproduce

  1. Download and /reload the attached data pack

  2. Summon a mob with this loot table

    /summon pig ~ ~ ~ {DeathLootTable:"mc-169473:a"}
  3. Kill the mob with a normal sword
    ✔  Exactly one diamond is dropped

  4. Resummon the mob with the command in step 3.

  5. Kill the mob with a looting 3 sword
    ❌  Only one diamond is dropped, while you would expect 6.5 on average 

Example loot table

{
  "type": "entity",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "diamond",
          "functions": [
            {
              "function": "apply_bonus",
              "enchantment": "looting",
              "formula": "binomial_with_bonus_count",
              "parameters": {
                "extra": 10,
                "probability": 0.5
              }
            }
          ]
        }
      ]
    }
  ]
}

Attachments

Comments 2

Not sure whether this is intended. apply_bonus requires the TOOL context to work properly, which only exists for fishing, block, and generic loot tables.

Affects 1.21.11, updated datapack:

[media]

Misode

(Unassigned)

Confirmed

Platform

Normal

Loot tables

1.15.1, 1.15.2, 20w18a, 20w20b, 20w22a, 1.21.11

Retrieved