Skip to content

Item ​

class · pocketmine\item\Item · source

Implements JsonSerializable

Constants ​

TAG_BLOCK_ENTITY_TAG ​

php
public const TAG_BLOCK_ENTITY_TAG = "BlockEntityTag"

TAG_DISPLAY ​

php
public const TAG_DISPLAY = "display"

TAG_DISPLAY_LORE ​

php
public const TAG_DISPLAY_LORE = "Lore"

TAG_DISPLAY_NAME ​

php
public const TAG_DISPLAY_NAME = "Name"

TAG_ENCH ​

php
public const TAG_ENCH = "ench"

TAG_KEEP_ON_DEATH ​

php
public const TAG_KEEP_ON_DEATH = "minecraft:keep_on_death"

Properties ​

$blockEntityTag protected ​

php
protected ?\pocketmine\nbt\tag\CompoundTag $blockEntityTag

TODO: this needs to die in a fire

$canDestroy protected ​

php
protected array $canDestroy

$canPlaceOn protected ​

php
protected array $canPlaceOn

$count protected ​

php
protected int $count

$customName protected ​

php
protected string $customName

$keepOnDeath protected ​

php
protected bool $keepOnDeath

$lore protected ​

php
protected array $lore

$name ​

php
public string $name

Methods ​

__clone() ​

php
public function __clone()

__construct() ​

php
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() ​

php
final public function __toString() : string

canBePlaced() ​

php
final public function canBePlaced() : bool

canStackWith() ​

php
final public function canStackWith(\pocketmine\item\Item $other) : bool

Returns whether this item could stack with the given item (ignoring stack size and count).

clearCustomBlockData() ​

php
public function clearCustomBlockData()

clearCustomName() ​

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

clearNamedTag() ​

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

Removes the Item's NBT.

continueUsing() 5.46.0 ​

php
public function continueUsing(\pocketmine\player\Player $player, int $useDuration) : void

Called every tick while the player is using a Chargeable item (holding right-click/pressing screen).

describeState() protected ​

php
protected function describeState(\pocketmine\data\runtime\RuntimeDataDescriber $w) : void

Describes 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 ​

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

equals() ​

php
final public function equals(\pocketmine\item\Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool

Compares an Item to this Item and check if they match.

equalsExact() ​

php
final public function equalsExact(\pocketmine\item\Item $other) : bool

Returns whether the specified item stack has the same ID, damage, NBT and count as this item stack.

getAttackPoints() ​

php
public function getAttackPoints() : int

Returns how many points of damage this item will deal to an entity when used as a weapon.

getBlock() ​

php
public function getBlock(?int $clickedFace = null) : \pocketmine\block\Block

Returns the block corresponding to this Item.

getBlockToolHarvestLevel() ​

php
public function getBlockToolHarvestLevel() : int

Returns 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() ​

php
public function getBlockToolType() : int

Returns 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() ​

php
public function getCanDestroy() : array

getCanPlaceOn() ​

php
public function getCanPlaceOn() : array

getCompostabilityChance() 5.46.0 ​

php
public function getCompostabilityChance() : int

Returns the chance that this item will fill one layer of a composter.

getCooldownTag() ​

php
public function getCooldownTag() : ?string

Returns 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() ​

php
public function getCooldownTicks() : int

Returns the number of ticks a player must wait before activating this item again.

getCount() ​

php
public function getCount() : int

getCustomBlockData() ​

php
public function getCustomBlockData() : ?\pocketmine\nbt\tag\CompoundTag

getCustomName() ​

php
public function getCustomName() : string

getDefensePoints() ​

php
public function getDefensePoints() : int

Returns how many armor points can be gained by wearing this item.

getEnchantability() ​

php
public function getEnchantability() : int

Returns 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() ​

php
public function getEnchantmentTags() : array

Returns 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() ​

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

Returns an item after burning fuel

getFuelTime() ​

php
public function getFuelTime() : int

Returns the time in ticks which the item will fuel a furnace for.

getLore() ​

php
public function getLore() : array

getMaxStackSize() ​

php
public function getMaxStackSize() : int

Returns the highest amount of this item which will fit into one inventory slot.

getMiningEfficiency() ​

php
public function getMiningEfficiency(bool $isCorrectTool) : float

getName() ​

php
final public function getName() : string

Returns the name of the item, or the custom name if it is set.

getNamedTag() ​

php
public function getNamedTag() : \pocketmine\nbt\tag\CompoundTag

Returns 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() ​

php
public function getPlacementTransaction(\pocketmine\block\Block $blockReplace, \pocketmine\block\Block $blockClicked, int $face, \pocketmine\math\Vector3 $clickVector, ?\pocketmine\player\Player $player = null) : ?\pocketmine\world\BlockTransaction

getStateId() ​

php
final public function getStateId() : int

getTypeId() ​

php
final public function getTypeId() : int

getVanillaName() ​

php
public function getVanillaName() : string

Returns the vanilla name of the item, disregarding custom names.

hasCustomBlockData() ​

php
public function hasCustomBlockData() : bool

hasCustomName() ​

php
public function hasCustomName() : bool

hasNamedTag() ​

php
public function hasNamedTag() : bool

Returns whether this Item has a non-empty NBT.

isCompostable() 5.46.0 ​

php
public function isCompostable() : bool

Returns whether this item can be used in a composter.

isFireProof() ​

php
public function isFireProof() : bool

Returns whether this item can survive being dropped into lava, or fire.

isNull() ​

php
public function isNull() : bool

jsonSerialize() ​

php
public function jsonSerialize() : array

keepOnDeath() ​

php
public function keepOnDeath() : bool

Returns whether players will retain this item on death. If a non-player dies it will be excluded from the drops.

legacyJsonDeserialize() ​

php
final public static function legacyJsonDeserialize(array $data) : \pocketmine\item\Item

Deserializes 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() ​

php
public static function nbtDeserialize(\pocketmine\nbt\tag\CompoundTag $tag) : \pocketmine\item\Item

Deserializes an Item from an NBT CompoundTag

nbtSerialize() ​

php
public function nbtSerialize(int $slot = -1) : \pocketmine\nbt\tag\CompoundTag

Serializes the item to an NBT CompoundTag

onAttackEntity() ​

php
public function onAttackEntity(\pocketmine\entity\Entity $victim, array &$returnedItems) : bool

Called when this item is used to attack an entity. Usually used to update durability.

onClickAir() ​

php
public function onClickAir(\pocketmine\player\Player $player, \pocketmine\math\Vector3 $directionVector, array &$returnedItems) : \pocketmine\item\ItemUseResult

Called 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() ​

php
public function onDestroyBlock(\pocketmine\block\Block $block, array &$returnedItems) : bool

Called when this item is used to destroy a block. Usually used to update durability.

onInteractBlock() ​

php
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\ItemUseResult

Called when a player uses this item on a block.

onInteractEntity() ​

php
public function onInteractEntity(\pocketmine\player\Player $player, \pocketmine\entity\Entity $entity, \pocketmine\math\Vector3 $clickVector) : bool

Called when a player uses the item to interact with entity, for example by using a name tag.

onReleaseUsing() ​

php
public function onReleaseUsing(\pocketmine\player\Player $player, array &$returnedItems) : \pocketmine\item\ItemUseResult

Called 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() ​

php
public function onTickWorn(\pocketmine\entity\Living $entity) : bool

Called when this item is being worn by an entity. Returns whether it did something.

pop() ​

php
public function pop(int $count = 1) : \pocketmine\item\Item

Pops an item from the stack and returns it, decreasing the stack count of this item stack by one.

safeNbtDeserialize() ​

php
public static function safeNbtDeserialize(\pocketmine\nbt\tag\CompoundTag $tag, string $errorLogContext, ?\Logger $logger = null) : \pocketmine\item\Item

Same 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 ​

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

setCanDestroy() ​

php
public function setCanDestroy(array $canDestroy) : void

setCanPlaceOn() ​

php
public function setCanPlaceOn(array $canPlaceOn) : void

setCount() ​

php
public function setCount(int $count) : \pocketmine\item\Item

setCustomBlockData() ​

php
public function setCustomBlockData(\pocketmine\nbt\tag\CompoundTag $compound) : \pocketmine\item\Item

setCustomName() ​

php
public function setCustomName(string $name) : \pocketmine\item\Item

setKeepOnDeath() ​

php
public function setKeepOnDeath(bool $keepOnDeath) : void

setLore() ​

php
public function setLore(array $lines) : \pocketmine\item\Item

setNamedTag() ​

php
public function setNamedTag(\pocketmine\nbt\tag\CompoundTag $tag) : \pocketmine\item\Item

Sets the Item's NBT from the supplied CompoundTag object.

tryPlacementTransaction() protected ​

php
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

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