Closed HimmelKreis4865 closed 4 years ago
You can do that but not directly through the API.
$x = Item::get(Item::DIAMOND_SWORD);
$y = Item::get(Item::IRON_SWORD);
$z = Item::get(Item::GOLD_SWORD);
foreach([$x, $y] as $readonly_item){ // making $x and $y read-only
$nbt = $readonly_item->getNamedTag();
$nbt->setByte("ReadOnly", 1); // set "ReadOnly" tag on item
$readonly_item->setNamedTag($nbt);
}
$menu->getInventory()->addItem($x, $y, $z);
$menu->setListener(function(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{
if($itemClicked->getNamedTag()->hasTag("ReadOnly")){ // cancel transaction for items with "ReadOnly" tag
return false;
}
return true;
});
You could wrap InvMenu over with your own API that extends it. InvMenu provides just the required data to work with.
Hello,
would it be possible to set for e.g only one item as read-only? Or maybe 2, 3, 4 up to 5? Like you can drop items there but there are some items you can't get out of the inventory?