WrittenBook
extends WritableBookBase
in package
Table of Contents
- GENERATION_COPY = 1
- GENERATION_COPY_OF_COPY = 2
- GENERATION_ORIGINAL = 0
- GENERATION_TATTERED = 3
- TAG_AUTHOR = "author"
- TAG_BLOCK_ENTITY_TAG = "BlockEntityTag"
- TAG_DISPLAY = "display"
- TAG_DISPLAY_LORE = "Lore"
- TAG_DISPLAY_NAME = "Name"
- TAG_ENCH = "ench"
- TAG_GENERATION = "generation"
- TAG_PAGE_PHOTONAME = "photoname"
- TAG_PAGE_TEXT = "text"
- TAG_PAGES = "pages"
- TAG_TITLE = "title"
- $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
- $enchantments : array<string|int, EnchantmentInstance>
- $lore : array<string|int, string>
- $name : string
- $author : string
- $generation : int
- $identifier : ItemIdentifier
- $nbt : CompoundTag
- $pages : array<string|int, WritableBookPage>
- $title : string
- __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
- addPage() : $this
- Adds a new page with the given page ID.
- 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.
- deletePage() : $this
- Deletes an existing page with the given page ID.
- 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
- Returns how many points of damage this item will deal to an entity when used as a weapon.
- getAuthor() : string
- Returns the author of this book.
- getBlock() : Block
- Returns the block corresponding to this Item.
- 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.
- 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() : 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
- 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.
- getGeneration() : int
- Returns the generation of the book.
- getId() : int
- getLore() : array<string|int, string>
- 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.
- getPages() : array<string|int, WritableBookPage>
- Returns an array containing all pages of this book.
- getPageText() : string
- Returns a string containing the content of a page (which could be empty), or null if the page doesn't exist.
- getTitle() : string
- Returns the title of this book.
- 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.
- insertPage() : $this
- Inserts a new page with the given text and moves other pages upwards.
- isNull() : bool
- 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
- Called when this item is used to attack an entity. Usually used to update durability.
- onClickAir() : ItemUseResult
- Called when a player uses the item on air, for example throwing a projectile.
- onDestroyBlock() : bool
- Called when this item is used to destroy a block. Usually used to update durability.
- 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.
- pageExists() : bool
- Returns whether the given page exists in this book.
- 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
- setAuthor() : $this
- Sets the author of this book.
- setCanDestroy() : void
- setCanPlaceOn() : void
- setCount() : $this
- setCustomBlockData() : $this
- setCustomName() : $this
- setGeneration() : $this
- Sets the generation of a book.
- setLore() : $this
- setNamedTag() : $this
- Sets the Item's NBT from the supplied CompoundTag object.
- setPages() : $this
- setPageText() : $this
- Sets the text of a page in the book. Adds the page if the page does not yet exist.
- setTitle() : $this
- Sets the author of this book.
- swapPages() : bool
- Switches the text of two pages with each other.
- deserializeCompoundTag() : void
- serializeCompoundTag() : void
Constants
GENERATION_COPY
public
mixed
GENERATION_COPY
= 1
GENERATION_COPY_OF_COPY
public
mixed
GENERATION_COPY_OF_COPY
= 2
GENERATION_ORIGINAL
public
mixed
GENERATION_ORIGINAL
= 0
GENERATION_TATTERED
public
mixed
GENERATION_TATTERED
= 3
TAG_AUTHOR
public
mixed
TAG_AUTHOR
= "author"
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"
TAG_GENERATION
public
mixed
TAG_GENERATION
= "generation"
TAG_PAGE_PHOTONAME
public
mixed
TAG_PAGE_PHOTONAME
= "photoname"
TAG_PAGE_TEXT
public
mixed
TAG_PAGE_TEXT
= "text"
TAG_PAGES
public
mixed
TAG_PAGES
= "pages"
TAG_TITLE
public
mixed
TAG_TITLE
= "title"
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
= ""
$enchantments
protected
array<string|int, EnchantmentInstance>
$enchantments
= []
$lore
protected
array<string|int, string>
$lore
= []
$name
protected
string
$name
$author
private
string
$author
= ""
$generation
private
int
$generation
= self::GENERATION_ORIGINAL
$identifier
private
ItemIdentifier
$identifier
$nbt
private
CompoundTag
$nbt
$pages
private
array<string|int, WritableBookPage>
$pages
= []
Tags
$title
private
string
$title
= ""
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 —addPage()
Adds a new page with the given page ID.
public
addPage(int $pageId) : $this
Creates a new page for every page between the given ID and existing pages that doesn't yet exist.
Parameters
- $pageId : int
Return values
$this —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 —deletePage()
Deletes an existing page with the given page ID.
public
deletePage(int $pageId) : $this
Parameters
- $pageId : int
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()
Returns how many points of damage this item will deal to an entity when used as a weapon.
public
getAttackPoints() : int
Return values
int —getAuthor()
Returns the author of this book.
public
getAuthor() : string
This is not a reliable way to get the name of the player who signed this book. The author can be set to anything when signing a book.
Return values
string —getBlock()
Returns the block corresponding to this Item.
public
getBlock([int|null $clickedFace = null ]) : Block
Parameters
- $clickedFace : int|null = null
Return values
Block —getBlockToolHarvestLevel()
Returns the harvesting power that this tool has. This affects what blocks it can mine when the tool type matches the mined block.
public
getBlockToolHarvestLevel() : int
This should return 1 for non-tiered tools, and the tool tier for tiered tools.
Tags
Return values
int —getBlockToolType()
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)
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 —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 —getGeneration()
Returns the generation of the book.
public
getGeneration() : int
Generations higher than 1 can not be copied.
Return values
int —getId()
public
final getId() : int
Return values
int —getLore()
public
getLore() : array<string|int, string>
Return values
array<string|int, string> —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 —getPages()
Returns an array containing all pages of this book.
public
getPages() : array<string|int, WritableBookPage>
Return values
array<string|int, WritableBookPage> —getPageText()
Returns a string containing the content of a page (which could be empty), or null if the page doesn't exist.
public
getPageText(int $pageId) : string
Parameters
- $pageId : int
Tags
Return values
string —getTitle()
Returns the title of this book.
public
getTitle() : string
Return values
string —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 —insertPage()
Inserts a new page with the given text and moves other pages upwards.
public
insertPage(int $pageId[, string $pageText = "" ]) : $this
Parameters
- $pageId : int
- $pageText : string = ""
Return values
$this —isNull()
public
isNull() : 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()
Called when this item is used to attack an entity. Usually used to update durability.
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()
Called when this item is used to destroy a block. Usually used to update durability.
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 —pageExists()
Returns whether the given page exists in this book.
public
pageExists(int $pageId) : bool
Parameters
- $pageId : int
Return values
bool —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 —setAuthor()
Sets the author of this book.
public
setAuthor(string $authorName) : $this
Parameters
- $authorName : string
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 —setGeneration()
Sets the generation of a book.
public
setGeneration(int $generation) : $this
Parameters
- $generation : int
Return values
$this —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 —setPages()
public
setPages(array<string|int, WritableBookPage> $pages) : $this
Parameters
- $pages : array<string|int, WritableBookPage>
Return values
$this —setPageText()
Sets the text of a page in the book. Adds the page if the page does not yet exist.
public
setPageText(int $pageId, string $pageText) : $this
Parameters
- $pageId : int
- $pageText : string
Return values
$this —setTitle()
Sets the author of this book.
public
setTitle(string $title) : $this
Parameters
- $title : string
Return values
$this —swapPages()
Switches the text of two pages with each other.
public
swapPages(int $pageId1, int $pageId2) : bool
Parameters
- $pageId1 : int
- $pageId2 : int
Tags
Return values
bool —indicating success
deserializeCompoundTag()
protected
deserializeCompoundTag(CompoundTag $tag) : void
Parameters
- $tag : CompoundTag
Return values
void —serializeCompoundTag()
protected
serializeCompoundTag(CompoundTag $tag) : void
Parameters
- $tag : CompoundTag