HeldItemsTrait 5.46.0
Main hand and off hand items of a mob (swords, bows, crossbows, tridents, potions being drunk, gold being admired), shown to players with MobEquipmentPacket and saved as the Bedrock "Mainhand"/"Offhand" lists.
The using class must call HeldItemsTrait::loadHeldItems() and HeldItemsTrait::saveHeldItems().
Methods
equipmentXp() protected
php
protected function equipmentXp(int $base) : intReturns the experience of a monster with equipment: $base + (1-3) per equipped item, when killed by a player.
getEquipmentCount() protected
php
protected function getEquipmentCount() : intReturns the number of equipped items (held and worn), for the vanilla experience formula "5 + equipment count * (1-3)".
getHeldItemDrops() protected
php
protected function getHeldItemDrops(bool $alwaysDropOffHand = false) : arrayReturns the held items dropped on death: vanilla drops spawned equipment with an 8.5% chance (+1% per Looting level) when killed by a player. Items with $alwaysDropOffHand (e.g. a drowned's nautilus shell) always drop.
getMainHandItem()
php
public function getMainHandItem() : \pocketmine\item\ItemgetOffHandItem()
php
public function getOffHandItem() : \pocketmine\item\ItemloadHeldItems() protected
php
protected function loadHeldItems(\pocketmine\nbt\tag\CompoundTag $nbt) : voidsaveHeldItems() protected
php
protected function saveHeldItems(\pocketmine\nbt\tag\CompoundTag $nbt) : voidsendHeldItems() protected
php
protected function sendHeldItems(array $players) : voidsendSpawnPacket() protected
php
protected function sendSpawnPacket(\pocketmine\player\Player $player) : voidsetMainHandItem()
php
public function setMainHandItem(\pocketmine\item\Item $item) : voidsetOffHandItem()
php
public function setOffHandItem(\pocketmine\item\Item $item) : void