PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
10.03k stars 2.33k forks source link

LootTable#populateLoot Missing required parameters #9684

Open KillerCreeper112 opened 1 year ago

KillerCreeper112 commented 1 year ago

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" } } ] } ] } ] }

electronicboy commented 1 year ago

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?

KillerCreeper112 commented 1 year ago

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 commented 1 year ago

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

Malfrador commented 1 year ago

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.

KillerCreeper112 commented 1 year ago

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.

Machine-Maker commented 2 months ago

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