Inventory and items
ItemStack values are immutable descriptions. Inventory methods submit bounded
authoritative changes instead of exposing mutable slots.
Work with a player inventory
use Bedriox\Api\Inventory\ItemStack;
use Bedriox\Api\Player\Player;
private function reward(Player $player): void
{
$inventory = $player->getInventory();
$held = $inventory->getHeldItem();
if ($inventory->firstEmpty() !== null) {
$inventory->addItem(new ItemStack('minecraft:diamond', 1));
}
}
The caller supplies a connected $player from a command, event, or fresh
server lookup. $inventory is that player's current authoritative inventory;
$held is the immutable stack snapshot in the selected hotbar slot.
Use contains() and getAddableQuantity() before a multi-step reward. Use
setItem(), addItem(), removeItem(), clear(), and setContents() for
bounded mutations. Armor and offhand inventories have their own typed handles.
Bedriox exposes real and plugin-owned virtual containers through the same authoritative window lifecycle. Open and close them through the player so events, viewer tracking, and inventory reconciliation remain intact.
Never cache an inventory snapshot across async work. Resolve the connected player and obtain a fresh inventory before committing the result.
