Sword
extends TieredTool
in package
Table of Contents
- TAG_BLOCK_ENTITY_TAG = "BlockEntityTag"
- TAG_DISPLAY = "display"
- TAG_DISPLAY_LORE = "Lore"
- TAG_DISPLAY_NAME = "Name"
- TAG_ENCH = "ench"
- $blockEntityTag : CompoundTag|null
- TODO: this needs to die in a fire
- $canDestroy : array<string|int, string>
- $canPlaceOn : array<string|int, string>
- $count : int
- $customName : string
- $damage : int
- $enchantments : array<string|int, EnchantmentInstance>
- $lore : array<string|int, string>
- $name : string
- $tier : ToolTier
- $identifier : ItemIdentifier
- $nbt : CompoundTag
- $unbreakable : bool
- __clone() : mixed
- __construct() : mixed
- Constructs a new Item type. This constructor should ONLY be used when constructing a new item TYPE to register into the index.
- __toString() : string
- addEnchantment() : $this
- applyDamage() : bool
- Applies damage to the item.
- canBePlaced() : bool
- canStackWith() : bool
- Returns whether this item could stack with the given item (ignoring stack size and count).
- clearCustomBlockData() : $this
- clearCustomName() : $this
- clearNamedTag() : $this
- Removes the Item's NBT.
- equals() : bool
- Compares an Item to this Item and check if they match.
- equalsExact() : bool
- Returns whether the specified item stack has the same ID, damage, NBT and count as this item stack.
- getAttackPoints() : int
- getBlock() : Block
- Returns the block corresponding to this Item.
- getBlockToolHarvestLevel() : int
- getBlockToolType() : int
- getCanDestroy() : array<string|int, string>
- getCanPlaceOn() : array<string|int, string>
- getCooldownTicks() : int
- Returns the number of ticks a player must wait before activating this item again.
- getCount() : int
- getCustomBlockData() : CompoundTag|null
- getCustomName() : string
- getDamage() : int
- getDefensePoints() : int
- Returns how many armor points can be gained by wearing this item.
- getEnchantment() : EnchantmentInstance|null
- getEnchantmentLevel() : int
- Returns the level of the enchantment on this item with the specified ID, or 0 if the item does not have the enchantment.
- getEnchantments() : array<string|int, EnchantmentInstance>
- getFuelResidue() : Item
- Returns an item after burning fuel
- getFuelTime() : int
- Returns the time in ticks which the item will fuel a furnace for.
- getId() : int
- getLore() : array<string|int, string>
- getMaxDurability() : int
- Returns the maximum amount of damage this item can take before it breaks.
- getMaxStackSize() : int
- Returns the highest amount of this item which will fit into one inventory slot.
- getMeta() : int
- getMiningEfficiency() : float
- getName() : string
- Returns the name of the item, or the custom name if it is set.
- getNamedTag() : 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.
- getTier() : ToolTier
- getVanillaName() : string
- Returns the vanilla name of the item, disregarding custom names.
- hasAnyDamageValue() : bool
- Returns whether this item can match any item with an equivalent ID with any meta value.
- hasCustomBlockData() : bool
- hasCustomName() : bool
- hasEnchantment() : bool
- hasEnchantments() : bool
- hasNamedTag() : bool
- Returns whether this Item has a non-empty NBT.
- isBroken() : bool
- Returns whether the item is broken.
- isNull() : bool
- isUnbreakable() : bool
- Returns whether this item will take damage when used.
- jsonDeserialize() : Item
- Returns an Item from properties created in an array by {@link Item#jsonSerialize}
- jsonSerialize() : array<string|int, mixed>
- Returns an array of item stack properties that can be serialized to json.
- nbtDeserialize() : Item
- Deserializes an Item from an NBT CompoundTag
- nbtSerialize() : CompoundTag
- Serializes the item to an NBT CompoundTag
- onAttackEntity() : bool
- onClickAir() : ItemUseResult
- Called when a player uses the item on air, for example throwing a projectile.
- onDestroyBlock() : bool
- onInteractBlock() : ItemUseResult
- Called when a player uses this item on a block.
- onReleaseUsing() : ItemUseResult
- Called when a player is using this item and releases it. Used to handle bow shoot actions.
- pop() : static
- Pops an item from the stack and returns it, decreasing the stack count of this item stack by one.
- removeEnchantment() : $this
- removeEnchantments() : $this
- setCanDestroy() : void
- setCanPlaceOn() : void
- setCount() : $this
- setCustomBlockData() : $this
- setCustomName() : $this
- setDamage() : Item
- setLore() : $this
- setNamedTag() : $this
- Sets the Item's NBT from the supplied CompoundTag object.
- setUnbreakable() : $this
- Sets whether the item will take damage when used.
- deserializeCompoundTag() : void
- getBaseMiningEfficiency() : float
- getUnbreakingDamageReduction() : int
- onBroken() : void
- Called when the item's damage exceeds its maximum durability.
- serializeCompoundTag() : void
Constants
TAG_BLOCK_ENTITY_TAG
public
mixed
TAG_BLOCK_ENTITY_TAG
= "BlockEntityTag"
TAG_DISPLAY
public
mixed
TAG_DISPLAY
= "display"
TAG_DISPLAY_LORE
public
mixed
TAG_DISPLAY_LORE
= "Lore"
TAG_DISPLAY_NAME
public
mixed
TAG_DISPLAY_NAME
= "Name"
TAG_ENCH
public
mixed
TAG_ENCH
= "ench"
Properties
$blockEntityTag
TODO: this needs to die in a fire
protected
CompoundTag|null
$blockEntityTag
= null
$canDestroy
protected
array<string|int, string>
$canDestroy
Tags
$canPlaceOn
protected
array<string|int, string>
$canPlaceOn
= []
Tags
$count
protected
int
$count
= 1
$customName
protected
string
$customName
= ""
$damage
protected
int
$damage
= 0
$enchantments
protected
array<string|int, EnchantmentInstance>
$enchantments
= []
$lore
protected
array<string|int, string>
$lore
= []
$name
protected
string
$name
$tier
protected
ToolTier
$tier
$identifier
private
ItemIdentifier
$identifier
$nbt
private
CompoundTag
$nbt
$unbreakable
private
bool
$unbreakable
= false
Methods
__clone()
public
__clone() : mixed
Return values
mixed —__construct()
Constructs a new Item type. This constructor should ONLY be used when constructing a new item TYPE to register into the index.
public
__construct(ItemIdentifier $identifier[, string $name = "Unknown" ]) : mixed
NOTE: This should NOT BE USED for creating items to set into an inventory. Use for that purpose.
Parameters
- $identifier : ItemIdentifier
- $name : string = "Unknown"
Return values
mixed —__toString()
public
final __toString() : string
Return values
string —addEnchantment()
public
addEnchantment(EnchantmentInstance $enchantment) : $this
Parameters
- $enchantment : EnchantmentInstance
Return values
$this —applyDamage()
Applies damage to the item.
public
applyDamage(int $amount) : bool
Parameters
- $amount : int
Return values
bool —if any damage was applied to the item
canBePlaced()
public
final canBePlaced() : bool
Return values
bool —canStackWith()
Returns whether this item could stack with the given item (ignoring stack size and count).
public
final canStackWith(Item $other) : bool
Parameters
- $other : Item
Return values
bool —clearCustomBlockData()
public
clearCustomBlockData() : $this
Return values
$this —clearCustomName()
public
clearCustomName() : $this
Return values
$this —clearNamedTag()
Removes the Item's NBT.
public
clearNamedTag() : $this
Tags
Return values
$this —equals()
Compares an Item to this Item and check if they match.
public
final equals(Item $item[, bool $checkDamage = true ][, bool $checkCompound = true ]) : bool
Parameters
- $item : Item
- $checkDamage : bool = true
-
Whether to verify that the damage values match.
- $checkCompound : bool = true
-
Whether to verify that the items' NBT match.
Return values
bool —equalsExact()
Returns whether the specified item stack has the same ID, damage, NBT and count as this item stack.
public
final equalsExact(Item $other) : bool
Parameters
- $other : Item
Return values
bool —getAttackPoints()
public
getAttackPoints() : int
Return values
int —getBlock()
Returns the block corresponding to this Item.
public
getBlock([int|null $clickedFace = null ]) : Block
Parameters
- $clickedFace : int|null = null
Return values
Block —getBlockToolHarvestLevel()
public
getBlockToolHarvestLevel() : int
Return values
int —getBlockToolType()
public
getBlockToolType() : int
Return values
int —getCanDestroy()
public
getCanDestroy() : array<string|int, string>
Tags
Return values
array<string|int, string> —getCanPlaceOn()
public
getCanPlaceOn() : array<string|int, string>
Tags
Return values
array<string|int, string> —getCooldownTicks()
Returns the number of ticks a player must wait before activating this item again.
public
getCooldownTicks() : int
Return values
int —getCount()
public
getCount() : int
Return values
int —getCustomBlockData()
public
getCustomBlockData() : CompoundTag|null
Return values
CompoundTag|null —getCustomName()
public
getCustomName() : string
Return values
string —getDamage()
public
getDamage() : int
Return values
int —getDefensePoints()
Returns how many armor points can be gained by wearing this item.
public
getDefensePoints() : int
Return values
int —getEnchantment()
public
getEnchantment(Enchantment $enchantment) : EnchantmentInstance|null
Parameters
- $enchantment : Enchantment
Return values
EnchantmentInstance|null —getEnchantmentLevel()
Returns the level of the enchantment on this item with the specified ID, or 0 if the item does not have the enchantment.
public
getEnchantmentLevel(Enchantment $enchantment) : int
Parameters
- $enchantment : Enchantment
Return values
int —getEnchantments()
public
getEnchantments() : array<string|int, EnchantmentInstance>
Return values
array<string|int, EnchantmentInstance> —getFuelResidue()
Returns an item after burning fuel
public
getFuelResidue() : Item
Return values
Item —getFuelTime()
Returns the time in ticks which the item will fuel a furnace for.
public
getFuelTime() : int
Return values
int —getId()
public
final getId() : int
Return values
int —getLore()
public
getLore() : array<string|int, string>
Return values
array<string|int, string> —getMaxDurability()
Returns the maximum amount of damage this item can take before it breaks.
public
abstract getMaxDurability() : int
Return values
int —getMaxStackSize()
Returns the highest amount of this item which will fit into one inventory slot.
public
getMaxStackSize() : int
Return values
int —getMeta()
public
getMeta() : int
Return values
int —getMiningEfficiency()
public
getMiningEfficiency(bool $isCorrectTool) : float
Parameters
- $isCorrectTool : bool
Return values
float —getName()
Returns the name of the item, or the custom name if it is set.
public
final getName() : string
Return values
string —getNamedTag()
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.
public
getNamedTag() : CompoundTag
Return values
CompoundTag —getTier()
public
getTier() : ToolTier
Return values
ToolTier —getVanillaName()
Returns the vanilla name of the item, disregarding custom names.
public
getVanillaName() : string
Return values
string —hasAnyDamageValue()
Returns whether this item can match any item with an equivalent ID with any meta value.
public
hasAnyDamageValue() : bool
Used in crafting recipes which accept multiple variants of the same item, for example crafting tables recipes.
Return values
bool —hasCustomBlockData()
public
hasCustomBlockData() : bool
Return values
bool —hasCustomName()
public
hasCustomName() : bool
Return values
bool —hasEnchantment()
public
hasEnchantment(Enchantment $enchantment[, int $level = -1 ]) : bool
Parameters
- $enchantment : Enchantment
- $level : int = -1
Return values
bool —hasEnchantments()
public
hasEnchantments() : bool
Return values
bool —hasNamedTag()
Returns whether this Item has a non-empty NBT.
public
hasNamedTag() : bool
Return values
bool —isBroken()
Returns whether the item is broken.
public
isBroken() : bool
Return values
bool —isNull()
public
isNull() : bool
Return values
bool —isUnbreakable()
Returns whether this item will take damage when used.
public
isUnbreakable() : bool
Return values
bool —jsonDeserialize()
Returns an Item from properties created in an array by {@link Item#jsonSerialize}
public
final static jsonDeserialize(array<string|int, mixed> $data) : Item
Parameters
- $data : array<string|int, mixed>
Tags
Return values
Item —jsonSerialize()
Returns an array of item stack properties that can be serialized to json.
public
final jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —nbtDeserialize()
Deserializes an Item from an NBT CompoundTag
public
static nbtDeserialize(CompoundTag $tag) : Item
Parameters
- $tag : CompoundTag
Tags
Return values
Item —nbtSerialize()
Serializes the item to an NBT CompoundTag
public
nbtSerialize([int $slot = -1 ]) : CompoundTag
Parameters
- $slot : int = -1
-
optional, the inventory slot of the item
Return values
CompoundTag —onAttackEntity()
public
onAttackEntity(Entity $victim) : bool
Parameters
- $victim : Entity
Return values
bool —onClickAir()
Called when a player uses the item on air, for example throwing a projectile.
public
onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult
Returns whether the item was changed, for example count decrease or durability change.
Parameters
Return values
ItemUseResult —onDestroyBlock()
public
onDestroyBlock(Block $block) : bool
Parameters
- $block : Block
Return values
bool —onInteractBlock()
Called when a player uses this item on a block.
public
onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult
Parameters
Return values
ItemUseResult —onReleaseUsing()
Called when a player is using this item and releases it. Used to handle bow shoot actions.
public
onReleaseUsing(Player $player) : ItemUseResult
Returns whether the item was changed, for example count decrease or durability change.
Parameters
- $player : Player
Return values
ItemUseResult —pop()
Pops an item from the stack and returns it, decreasing the stack count of this item stack by one.
public
pop([int $count = 1 ]) : static
Parameters
- $count : int = 1
Tags
Return values
static —A clone of this itemstack containing the amount of items that were removed from this stack.
removeEnchantment()
public
removeEnchantment(Enchantment $enchantment[, int $level = -1 ]) : $this
Parameters
- $enchantment : Enchantment
- $level : int = -1
Return values
$this —removeEnchantments()
public
removeEnchantments() : $this
Return values
$this —setCanDestroy()
public
setCanDestroy(array<string|int, string> $canDestroy) : void
Parameters
- $canDestroy : array<string|int, string>
Return values
void —setCanPlaceOn()
public
setCanPlaceOn(array<string|int, string> $canPlaceOn) : void
Parameters
- $canPlaceOn : array<string|int, string>
Return values
void —setCount()
public
setCount(int $count) : $this
Parameters
- $count : int
Return values
$this —setCustomBlockData()
public
setCustomBlockData(CompoundTag $compound) : $this
Parameters
- $compound : CompoundTag
Return values
$this —setCustomName()
public
setCustomName(string $name) : $this
Parameters
- $name : string
Return values
$this —setDamage()
public
setDamage(int $damage) : Item
Parameters
- $damage : int
Return values
Item —setLore()
public
setLore(array<string|int, string> $lines) : $this
Parameters
- $lines : array<string|int, string>
Return values
$this —setNamedTag()
Sets the Item's NBT from the supplied CompoundTag object.
public
setNamedTag(CompoundTag $tag) : $this
Parameters
- $tag : CompoundTag
Tags
Return values
$this —setUnbreakable()
Sets whether the item will take damage when used.
public
setUnbreakable([bool $value = true ]) : $this
Parameters
- $value : bool = true
Return values
$this —deserializeCompoundTag()
protected
deserializeCompoundTag(CompoundTag $tag) : void
Parameters
- $tag : CompoundTag
Tags
Return values
void —getBaseMiningEfficiency()
protected
getBaseMiningEfficiency() : float
Return values
float —getUnbreakingDamageReduction()
protected
getUnbreakingDamageReduction(int $amount) : int
Parameters
- $amount : int
Return values
int —onBroken()
Called when the item's damage exceeds its maximum durability.
protected
onBroken() : void
Return values
void —serializeCompoundTag()
protected
serializeCompoundTag(CompoundTag $tag) : void
Parameters
- $tag : CompoundTag