Skip to content

HeldItemsTrait 5.46.0 ​

trait · pocketmine\entity\monster\HeldItemsTrait · source

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) : int

Returns the experience of a monster with equipment: $base + (1-3) per equipped item, when killed by a player.

getEquipmentCount() protected ​

php
protected function getEquipmentCount() : int

Returns 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) : array

Returns 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\Item

getOffHandItem() ​

php
public function getOffHandItem() : \pocketmine\item\Item

loadHeldItems() protected ​

php
protected function loadHeldItems(\pocketmine\nbt\tag\CompoundTag $nbt) : void

saveHeldItems() protected ​

php
protected function saveHeldItems(\pocketmine\nbt\tag\CompoundTag $nbt) : void

sendHeldItems() protected ​

php
protected function sendHeldItems(array $players) : void

sendSpawnPacket() protected ​

php
protected function sendSpawnPacket(\pocketmine\player\Player $player) : void

setMainHandItem() ​

php
public function setMainHandItem(\pocketmine\item\Item $item) : void

setOffHandItem() ​

php
public function setOffHandItem(\pocketmine\item\Item $item) : void

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.