Lootcontext.builder missing parameters

  • After careful consideration and due to limited usage, we’ve made the decision to discontinue the PaperMC forums. Moving forward, we recommend using Hangar for plugin uploads, and for all other community discussions and support, please join us on Discord.

Orbitaalex

New member
Mar 20, 2024
3
0
1
Hello everyone,

I am struggling in populating an inventory view with lootables using lootcontext.
I really want to use the lootable system, i have some projects with them.
This error is so horrible to manage. I ve tried to give some parameters but nothing.
It demotivate me so much on my creation process.
I really need help on that ...


Code:
@EventHandler
public void onPlayerClick(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (event.getAction() == Action.RIGHT_CLICK_AIR) {
        player.sendMessage(Component.text("Detected right-click in the air."));

        NamespacedKey key = new NamespacedKey("lootableentity", "chest/test");
        player.sendMessage(Component.text("Loot key used: " + key));

        LootTable lootTable = Bukkit.getLootTable(key);
        if (lootTable != null) {
            player.sendMessage(Component.text("Loot table found."));
            LootContext lootContext = new LootContext.Builder(player.getLocation())
                // .setLootingTool(player.getInventory().getItemInMainHand()) // Omit if not supported
                .build();

            Inventory lootInventory = Bukkit.createInventory(player, 27, Component.text("Loot Chest"));
            lootTable.fillInventory(lootInventory, new Random(), lootContext);
            player.openInventory(lootInventory);
            player.sendMessage(Component.text("Loot inventory opened."));
        } else {
            player.sendMessage(Component.text("Error: Loot table is null."));
        }
    } else {
        player.sendMessage(Component.text("The action is not a right-click in the air."));
    }
}


here is my error :


Code:
java.lang.IllegalArgumentException: Missing required parameters: [<parameter minecraft:direct_killer_entity>, <parameter minecraft:damage_source>, <parameter minecraft:last_damage_player>, <parameter minecraft:block_state>, <parameter minecraft:killer_entity>, <parameter minecraft:block_entity>, <parameter minecraft:this_entity>, <parameter minecraft:tool>, <parameter minecraft:explosion_radius>]