Paper icon indicating copy to clipboard operation
Paper copied to clipboard

LootTable#populateLoot Missing required parameters

Open KillerCreeper112 opened this issue 2 years ago • 6 comments

Expected behavior

When using the steps to reproduce code, the loot should populate without error.

Observed/Actual behavior

When using the steps to reproduce code, an error occurs at LootTable#populateLoot(): java.lang.IllegalArgumentException: Missing required parameters: [<parameter minecraft:direct_killer_entity>, <parameter minecraft:this_entity>, <parameter minecraft:block_state>, <parameter minecraft:block_entity>, <parameter minecraft:explosion_radius>]

Steps/models to reproduce

LootContext.Builder context = new LootContext.Builder(block.getLocation()); LootTable table = Bukkit.getLootTable(key); table.populateLoot(null, context.build());

Plugin and Datapack List

CustomPlugin, CustomDataPack(for loot table)

Paper version

This server is running Paper version git-Paper-169 (MC: 1.20.1) (Implementing API version 1.20.1-R0.1-SNAPSHOT) (Git: b4e3b3d) You are running the latest version Previous version: git-Paper-167 (MC: 1.20.1)

Other

This is the loot table I am using from the data pack:

{ "pools": [ { "rolls": 1, "entries": [ { "type": "minecraft:item", "name": "minecraft:paper", "conditions": [ { "condition": "minecraft:match_tool", "predicate": { "tag": "minecraft:pickaxes" } } ] } ] } ] }

KillerCreeper112 avatar Sep 03 '23 15:09 KillerCreeper112

I'm not 100% in loop with this system, but, mojang is what sets the required params for a loot table to function, this just seems like you're gonna have to supply them?

electronicboy avatar Sep 03 '23 16:09 electronicboy

The API does not give access to some of those values. I believe it only gives access to direct_killer_entity and this_entity.

KillerCreeper112 avatar Sep 03 '23 19:09 KillerCreeper112

Look at https://jd.papermc.io/paper/1.20/org/bukkit/loot/LootContext.Builder.html

KillerCreeper112 avatar Sep 03 '23 19:09 KillerCreeper112

You provided no type for your LootTable. By default, the ALL_PARAMS type is used, which requires all LootContextParams to be set. Craftbukkit does not handle that correctly, so you get an error. Providing a type should fix the issue, though this should be handled better by the API. You can use the EMPTY type for one that does not have any parameters:

{
  "type": "minecraft:empty",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:paper",
          "conditions": [
            {
              "condition": "minecraft:match_tool",
              "predicate": {
                "tag": "minecraft:pickaxes"
              }
            }
          ]
        }
      ]
    }
  ]
}

Alternatively there are various different types like BLOCK that might work as well in this case.

Malfrador avatar Sep 06 '23 20:09 Malfrador

You provided no type for your LootTable. By default, the ALL_PARAMS type is used, which requires all LootContextParams to be set. Craftbukkit does not handle that correctly, so you get an error.

Providing a type should fix the issue, though this should be handled better by the API.

You can use the EMPTY type for one that does not have any parameters:


{

  "type": "minecraft:empty",

  "pools": [

    {

      "rolls": 1,

      "entries": [

        {

          "type": "minecraft:item",

          "name": "minecraft:paper",

          "conditions": [

            {

              "condition": "minecraft:match_tool",

              "predicate": {

                "tag": "minecraft:pickaxes"

              }

            }

          ]

        }

      ]

    }

  ]

}

Alternatively there are various different types like BLOCK that might work as well in this case.

I've tried block and it prints an error saying it needs the block state and tool. There is seem no way to set these values using the API and using "empty" makes any conditional value that requires certain context to fail (like my example on checking for a pickaxe). It looks like the API just needs some updating.

KillerCreeper112 avatar Sep 08 '23 01:09 KillerCreeper112

https://github.com/PaperMC/Paper/pull/7655 should fix this by letting you set all the params.

Machine-Maker avatar Sep 09 '24 06:09 Machine-Maker