Item
Implements JsonSerializable
Constants
TAG_BLOCK_ENTITY_TAG
public const TAG_BLOCK_ENTITY_TAG = "BlockEntityTag"TAG_DISPLAY
public const TAG_DISPLAY = "display"TAG_DISPLAY_LORE
public const TAG_DISPLAY_LORE = "Lore"TAG_DISPLAY_NAME
public const TAG_DISPLAY_NAME = "Name"TAG_ENCH
public const TAG_ENCH = "ench"TAG_KEEP_ON_DEATH
public const TAG_KEEP_ON_DEATH = "minecraft:keep_on_death"Properties
$blockEntityTag protected
protected ?\pocketmine\nbt\tag\CompoundTag $blockEntityTagTODO: this needs to die in a fire
$canDestroy protected
protected array $canDestroy$canPlaceOn protected
protected array $canPlaceOn$count protected
protected int $count$customName protected
protected string $customName$keepOnDeath protected
protected bool $keepOnDeath$lore protected
protected array $lore$name
public string $nameMethods
__clone()
public function __clone()__construct()
public function __construct(\pocketmine\item\ItemIdentifier $identifier, string $name = "Unknown", array $enchantmentTags = [])Constructs a new Item type. This constructor should ONLY be used when constructing a new item TYPE to register into the index.
NOTE: This should NOT BE USED for creating items to set into an inventory. Use VanillaItems for that purpose.
__toString()
final public function __toString() : stringcanBePlaced()
final public function canBePlaced() : boolcanStackWith()
final public function canStackWith(\pocketmine\item\Item $other) : boolReturns whether this item could stack with the given item (ignoring stack size and count).
clearCustomBlockData()
public function clearCustomBlockData()clearCustomName()
public function clearCustomName() : \pocketmine\item\ItemclearNamedTag()
public function clearNamedTag() : \pocketmine\item\ItemRemoves the Item's NBT.
continueUsing() 5.46.0
public function continueUsing(\pocketmine\player\Player $player, int $useDuration) : voidCalled every tick while the player is using a Chargeable item (holding right-click/pressing screen).
describeState() protected
protected function describeState(\pocketmine\data\runtime\RuntimeDataDescriber $w) : voidDescribes state properties of the item, such as colour, skull type, etc. This allows associating basic extra data with the item at runtime in a more efficient format than NBT.
deserializeCompoundTag() protected
protected function deserializeCompoundTag(\pocketmine\nbt\tag\CompoundTag $tag) : voidequals()
final public function equals(\pocketmine\item\Item $item, bool $checkDamage = true, bool $checkCompound = true) : boolCompares an Item to this Item and check if they match.
equalsExact()
final public function equalsExact(\pocketmine\item\Item $other) : boolReturns whether the specified item stack has the same ID, damage, NBT and count as this item stack.
getAttackPoints()
public function getAttackPoints() : intReturns how many points of damage this item will deal to an entity when used as a weapon.
getBlock()
public function getBlock(?int $clickedFace = null) : \pocketmine\block\BlockReturns the block corresponding to this Item.
getBlockToolHarvestLevel()
public function getBlockToolHarvestLevel() : intReturns the harvesting power that this tool has. This affects what blocks it can mine when the tool type matches the mined block. This should return 1 for non-tiered tools, and the tool tier for tiered tools.
getBlockToolType()
public function getBlockToolType() : intReturns what type of block-breaking tool this is. Blocks requiring the same tool type as the item will break faster (except for blocks requiring no tool, which break at the same speed regardless of the tool used)
getCanDestroy()
public function getCanDestroy() : arraygetCanPlaceOn()
public function getCanPlaceOn() : arraygetCompostabilityChance() 5.46.0
public function getCompostabilityChance() : intReturns the chance that this item will fill one layer of a composter.
getCooldownTag()
public function getCooldownTag() : ?stringReturns a tag that identifies a group of items that should have cooldown at the same time regardless of their state or type. When cooldown starts, any other items with the same cooldown tag can't be used until the cooldown expires. Such behaviour can be seen in goat horns and shields.
If tag is null, item state id will be used to store cooldown.
getCooldownTicks()
public function getCooldownTicks() : intReturns the number of ticks a player must wait before activating this item again.
getCount()
public function getCount() : intgetCustomBlockData()
public function getCustomBlockData() : ?\pocketmine\nbt\tag\CompoundTaggetCustomName()
public function getCustomName() : stringgetDefensePoints()
public function getDefensePoints() : intReturns how many armor points can be gained by wearing this item.
getEnchantability()
public function getEnchantability() : intReturns the value that defines how enchantable the item is.
The higher an item's enchantability is, the more likely it will be to gain high-level enchantments or multiple enchantments upon being enchanted in an enchanting table.
getEnchantmentTags()
public function getEnchantmentTags() : arrayReturns tags that represent the type of item being enchanted and are used to determine what enchantments can be applied to this item during in-game enchanting (enchanting table, anvil, fishing, etc.).
getFuelResidue()
public function getFuelResidue() : \pocketmine\item\ItemReturns an item after burning fuel
getFuelTime()
public function getFuelTime() : intReturns the time in ticks which the item will fuel a furnace for.
getLore()
public function getLore() : arraygetMaxStackSize()
public function getMaxStackSize() : intReturns the highest amount of this item which will fit into one inventory slot.
getMiningEfficiency()
public function getMiningEfficiency(bool $isCorrectTool) : floatgetName()
final public function getName() : stringReturns the name of the item, or the custom name if it is set.
getNamedTag()
public function getNamedTag() : \pocketmine\nbt\tag\CompoundTagReturns a tree of Tag objects representing the Item's NBT. If the item does not have any NBT, an empty CompoundTag object is returned to allow the caller to manipulate and apply back to the item.
getPlacementTransaction()
public function getPlacementTransaction(\pocketmine\block\Block $blockReplace, \pocketmine\block\Block $blockClicked, int $face, \pocketmine\math\Vector3 $clickVector, ?\pocketmine\player\Player $player = null) : ?\pocketmine\world\BlockTransactiongetStateId()
final public function getStateId() : intgetTypeId()
final public function getTypeId() : intgetVanillaName()
public function getVanillaName() : stringReturns the vanilla name of the item, disregarding custom names.
hasCustomBlockData()
public function hasCustomBlockData() : boolhasCustomName()
public function hasCustomName() : boolhasNamedTag()
public function hasNamedTag() : boolReturns whether this Item has a non-empty NBT.
isCompostable() 5.46.0
public function isCompostable() : boolReturns whether this item can be used in a composter.
isFireProof()
public function isFireProof() : boolReturns whether this item can survive being dropped into lava, or fire.
isNull()
public function isNull() : booljsonSerialize()
public function jsonSerialize() : arraykeepOnDeath()
public function keepOnDeath() : boolReturns whether players will retain this item on death. If a non-player dies it will be excluded from the drops.
legacyJsonDeserialize()
final public static function legacyJsonDeserialize(array $data) : \pocketmine\item\ItemDeserializes item JSON data produced by json_encode()ing Item instances in older versions of PocketMine-MP. This method exists solely to allow upgrading old JSON data stored by plugins.
nbtDeserialize()
public static function nbtDeserialize(\pocketmine\nbt\tag\CompoundTag $tag) : \pocketmine\item\ItemDeserializes an Item from an NBT CompoundTag
nbtSerialize()
public function nbtSerialize(int $slot = -1) : \pocketmine\nbt\tag\CompoundTagSerializes the item to an NBT CompoundTag
onAttackEntity()
public function onAttackEntity(\pocketmine\entity\Entity $victim, array &$returnedItems) : boolCalled when this item is used to attack an entity. Usually used to update durability.
onClickAir()
public function onClickAir(\pocketmine\player\Player $player, \pocketmine\math\Vector3 $directionVector, array &$returnedItems) : \pocketmine\item\ItemUseResultCalled when a player uses the item on air, for example throwing a projectile. Returns whether the item was changed, for example count decrease or durability change.
onDestroyBlock()
public function onDestroyBlock(\pocketmine\block\Block $block, array &$returnedItems) : boolCalled when this item is used to destroy a block. Usually used to update durability.
onInteractBlock()
public function onInteractBlock(\pocketmine\player\Player $player, \pocketmine\block\Block $blockReplace, \pocketmine\block\Block $blockClicked, int $face, \pocketmine\math\Vector3 $clickVector, array &$returnedItems) : \pocketmine\item\ItemUseResultCalled when a player uses this item on a block.
onInteractEntity()
public function onInteractEntity(\pocketmine\player\Player $player, \pocketmine\entity\Entity $entity, \pocketmine\math\Vector3 $clickVector) : boolCalled when a player uses the item to interact with entity, for example by using a name tag.
onReleaseUsing()
public function onReleaseUsing(\pocketmine\player\Player $player, array &$returnedItems) : \pocketmine\item\ItemUseResultCalled when a player is using this item and releases it. Used to handle bow shoot actions. Returns whether the item was changed, for example count decrease or durability change.
onTickWorn()
public function onTickWorn(\pocketmine\entity\Living $entity) : boolCalled when this item is being worn by an entity. Returns whether it did something.
pop()
public function pop(int $count = 1) : \pocketmine\item\ItemPops an item from the stack and returns it, decreasing the stack count of this item stack by one.
safeNbtDeserialize()
public static function safeNbtDeserialize(\pocketmine\nbt\tag\CompoundTag $tag, string $errorLogContext, ?\Logger $logger = null) : \pocketmine\item\ItemSame as nbtDeserialize(), but purposely suppresses data errors and returns AIR if deserialization fails. An error will be logged to the global logger if this happens.
serializeCompoundTag() protected
protected function serializeCompoundTag(\pocketmine\nbt\tag\CompoundTag $tag) : voidsetCanDestroy()
public function setCanDestroy(array $canDestroy) : voidsetCanPlaceOn()
public function setCanPlaceOn(array $canPlaceOn) : voidsetCount()
public function setCount(int $count) : \pocketmine\item\ItemsetCustomBlockData()
public function setCustomBlockData(\pocketmine\nbt\tag\CompoundTag $compound) : \pocketmine\item\ItemsetCustomName()
public function setCustomName(string $name) : \pocketmine\item\ItemsetKeepOnDeath()
public function setKeepOnDeath(bool $keepOnDeath) : voidsetLore()
public function setLore(array $lines) : \pocketmine\item\ItemsetNamedTag()
public function setNamedTag(\pocketmine\nbt\tag\CompoundTag $tag) : \pocketmine\item\ItemSets the Item's NBT from the supplied CompoundTag object.
tryPlacementTransaction() protected
final protected function tryPlacementTransaction(\pocketmine\block\Block $blockPlace, \pocketmine\block\Block $blockReplace, \pocketmine\block\Block $blockClicked, int $face, \pocketmine\math\Vector3 $clickVector, ?\pocketmine\player\Player $player) : ?\pocketmine\world\BlockTransaction