API reference / @jsprismarine/prismarine / Item
Class: Item
Defined in: prismarine/src/item/Item.ts:139
One item stack, as the rest of the server holds one.
Everything it answers about itself - how hard it hits, how much armor it is worth, how much durability it has, what it harvests - is read off Java's data components rather than declared by a subclass. The 65 item classes this replaced each restated one or two of those numbers; the table has all of them, for all 1613 items.
Constructors
Constructor
new Item(
__namedParameters):Item
Defined in: prismarine/src/item/Item.ts:197
Parameters
__namedParameters
Returns
Item
Properties
count
count:
number=1
Defined in: prismarine/src/item/Item.ts:149
durability
durability:
number
Defined in: prismarine/src/item/Item.ts:145
meta
meta:
number=0
Defined in: prismarine/src/item/Item.ts:144
nbt
nbt:
null=null
Defined in: prismarine/src/item/Item.ts:148
stackNetworkId
stackNetworkId:
number=0
Defined in: prismarine/src/item/Item.ts:162
The stack network id the client knows this stack by, or 0 before it has one.
The inventory packets write it, so that a client and the server name a stack by the same number in an ItemStackRequest and in its answer. A stack read off the wire keeps the id it came with.
Ids are counted per player by HumanInventory.assignStackNetworkId. A stack keeps its id when it moves whole or changes size through Item.withCount; every other copy starts without one, and so does a part split off a stack.
Methods
asPredicateStack()
asPredicateStack():
ItemStack
Defined in: prismarine/src/item/Item.ts:614
This stack as the loot, predicate and enchantment grammars read one.
The components carry what those grammars actually look at today: minecraft:enchantments for Fortune, Looting, Silk Touch and every effect component, and the three the item type declares that the enchanting table and the anvil read off a stack - minecraft:enchantable, minecraft:max_damage and minecraft:damage. An empty map used to go out here, which made every apply_bonus see an unenchanted tool and every enchanting table refuse every item.
Returns
getAmount()
getAmount():
number
Defined in: prismarine/src/item/Item.ts:530
Returns
number
getArmorDefensePoints()
getArmorDefensePoints():
number
Defined in: prismarine/src/item/Item.ts:368
The armor points the item is worth while worn.
Returns
number
getArmorToughness()
getArmorToughness():
number
Defined in: prismarine/src/item/Item.ts:373
The armor toughness the item is worth while worn.
Returns
number
getAttackDamage()
getAttackDamage():
number
Defined in: prismarine/src/item/Item.ts:363
Half-hearts a swing with this in hand is worth.
The player's own base of one, plus the item's minecraft:base_attack_damage modifier. A bare fist and a torch are both worth one, which is vanilla's rule rather than a placeholder.
Returns
number
getBlockRuntimeId()
getBlockRuntimeId():
number
Defined in: prismarine/src/item/Item.ts:726
The runtime id of the block this item places, or zero for anything that places none.
An id given at construction wins. Otherwise the name resolves to the block's default state, which is right for a stack a player holds and wrong for two kinds of creative entry: a block the menu shows in another state (a piston faces up there), and the item form of a block vanilla treats as a plain item (a door, a bed, a hanging sign travel with a zero) while this server has a block schema under the same name.
Returns
number
the hashed block runtime id, or 0.
getBurnTime()
getBurnTime():
number
Defined in: prismarine/src/item/Item.ts:351
How long the item burns in a furnace, in ticks.
Returns
number
getCanDestroyBlocks()
getCanDestroyBlocks(): readonly
string[]
Defined in: prismarine/src/item/Item.ts:422
The Bedrock block identifiers this stack may destroy.
Returns
readonly string[]
getCanPlaceOnBlocks()
getCanPlaceOnBlocks(): readonly
string[]
Defined in: prismarine/src/item/Item.ts:417
The Bedrock block identifiers this stack may be placed on.
Returns
readonly string[]
getContents()
getContents(): readonly (
Item|null)[]
Defined in: prismarine/src/item/Item.ts:412
What this stack holds inside it, one entry per slot and null for an empty one.
Empty for everything but a container item, which today is the shulker box.
Returns
readonly (Item | null)[]
getCustomName()
getCustomName():
string|undefined
Defined in: prismarine/src/item/Item.ts:398
The name an anvil gave this stack, or undefined when it still has the item's own.
Returns
string | undefined
getDurability()
getDurability():
number
Defined in: prismarine/src/item/Item.ts:522
Returns
number
getEnchantmentLevel()
getEnchantmentLevel(
enchantment):number
Defined in: prismarine/src/item/Item.ts:393
The level of one enchantment, or zero when the stack does not carry it.
Parameters
enchantment
string
A namespaced or bare Java enchantment id.
Returns
number
getEnchantments()
getEnchantments():
ReadonlyMap<string,number>
Defined in: prismarine/src/item/Item.ts:384
The stack's enchantments, by namespaced Java id.
Java ids and not Bedrock ones, because the enchantment definitions, the loot tables and the effect components are all Java's and converting at every read would mean converting back to run any of them.
Returns
ReadonlyMap<string, number>
getEquipmentSlot()
getEquipmentSlot():
string|undefined
Defined in: prismarine/src/item/Item.ts:346
Where minecraft:equippable says this item is worn.
The game's own answer to which slot an item occupies, which is what dressing a mob from a loot table needs: the table names minecraft:iron_helmet and nothing else says it is a helmet. One of @jsprismarine/items' EQUIPMENT_SLOTS.
Returns
string | undefined
The slot name, or undefined for an item that is not worn, which a sword and a bow are.
getJavaTags()
getJavaTags(): readonly
string[]
Defined in: prismarine/src/item/Item.ts:243
The Java datapack tags attached to this Bedrock item type.
Returns
readonly string[]
getLore()
getLore(): readonly
string[]
Defined in: prismarine/src/item/Item.ts:403
The lore lines on this stack, which is an empty array for most of them.
Returns
readonly string[]
getMaxAmount()
getMaxAmount():
number
Defined in: prismarine/src/item/Item.ts:526
Returns
number
getMaxDurability()
getMaxDurability():
number
Defined in: prismarine/src/item/Item.ts:518
Returns
number
getMeta()
getMeta():
number
Defined in: prismarine/src/item/Item.ts:284
The stack's damage or variant value, which the wire carries beside the id.
Returns
number
getMiningSpeed()
getMiningSpeed(
block):number
Defined in: prismarine/src/item/Item.ts:583
How fast this mines one block, which is Java's Player.getDestroySpeed as far as a stack alone can answer it.
The minecraft:tool rules give the base - the first rule whose block set matches and that states a speed - and minecraft:mining_efficiency raises it, which is the attribute Efficiency's modifier writes. Java only adds the attribute to a speed already above one, so Efficiency does nothing for a tool that is the wrong tool for the block.
Dig Speed, Mining Fatigue, being underwater without Aqua Affinity and being off the ground are the four other terms of Java's formula, and none of them is modeled: there is no effect system and no swimming state on an entity.
Parameters
block
string
The block identifier being mined.
Returns
number
A multiplier on the base rate; 1 for a bare hand or an item with no rule for the block, which is Java's Item.getDestroySpeed.
getName()
getName():
string
Defined in: prismarine/src/item/Item.ts:228
Returns
string
getRuntimeId()
getRuntimeId():
number
Defined in: prismarine/src/item/Item.ts:270
The Bedrock runtime id for this item under the canonical numbering, protocol 2193's.
What everything off the wire means by an item's number. A stack going to a client is numbered by Item.wireId against that session's own table instead, because the two disagree for 82 items from 1.26.60 on.
Returns
number
getTags()
getTags(): readonly
string[]
Defined in: prismarine/src/item/Item.ts:233
The Bedrock tags attached to this item type, or an empty list when it has no type.
Returns
readonly string[]
harvests()
harvests(
block,content?):boolean
Defined in: prismarine/src/item/Item.ts:551
Whether swinging this harvests a block rather than destroying it for nothing.
Java's minecraft:tool rules in one pass: the first rule whose block set matches and whose correct_for_drops is stated decides, which is how #minecraft:incorrect_for_stone_tool stops a stone pickaxe mining diamond while #minecraft:mineable/pickaxe lets it mine stone.
Parameters
block
string
The block identifier being mined.
content?
ServerContent | undefined = ...
The content whose merged tags resolve this rule, defaulting to this stack's content.
Returns
boolean
False for a bare name no rule covers, which is Java's answer too.
hasComponent()
hasComponent(
name):boolean
Defined in: prismarine/src/item/Item.ts:259
Whether the resolved item type declares the named data component.
Parameters
name
string
Returns
boolean
hasEnchantment()
hasEnchantment(
enchantment):boolean
Defined in: prismarine/src/item/Item.ts:514
Whether the stack carries an enchantment at any level.
Parameters
enchantment
string
A namespaced or bare Java enchantment id. This took ItemEnchantmentType and always answered false; the enum numbers Bedrock's 37 enchantments, gives two of them the same number, and has nothing to say about the other six or about a datapack's.
Returns
boolean
hasJavaTag()
hasJavaTag(
tag):boolean
Defined in: prismarine/src/item/Item.ts:252
Whether a Java datapack tag includes this item type.
Parameters
tag
string
Returns
boolean
hasTag()
hasTag(
tag):boolean
Defined in: prismarine/src/item/Item.ts:238
Whether this item type carries one of its Bedrock tags.
Parameters
tag
string
Returns
boolean
isArmorPiece()
isArmorPiece():
boolean
Defined in: prismarine/src/item/Item.ts:333
Whether the item's components give it an armor value.
Returns
boolean
isPartOfCreativeInventory()
isPartOfCreativeInventory():
boolean
Defined in: prismarine/src/item/Item.ts:534
Returns
boolean
isTool()
isTool():
boolean
Defined in: prismarine/src/item/Item.ts:328
Whether the item's components make it a tool.
Returns
boolean
networkSerialize()
networkSerialize(
stream,stackNetId?):void
Defined in: prismarine/src/item/Item.ts:668
Writes an item stack in the form that carries a stack net id - an ItemInstance.
There are two forms on the wire, and at 2168 they no longer differ by one byte. This one, which an inventory, an equipped hand or a transaction carries, opens with a fixed two byte id and closes with an unsigned block runtime id; the other, networkSerializeWithoutStackId, uses a varint for both. Neither still stops early for air: up to 748 a zero id was the whole stack, and now every field is written whatever the id is. An inventory is mostly empty slots, so a stack that stops after the id truncates the packet almost immediately - which is exactly what the client reports as a bad packet on join, before any of the interesting packets are even reached.
Parameters
stream
the stream to write to.
stackNetId?
number | null = null
the stack's net id, when the receiver tracks one.
Returns
void
See
https://mojang.github.io/bedrock-protocol-docs/1.26.51/types/network-item-stack-descriptor/
networkSerializeWithoutStackId()
networkSerializeWithoutStackId(
stream):void
Defined in: prismarine/src/item/Item.ts:705
Writes an item stack in the form that carries no stack net id - an ItemStack.
What the creative menu and every recipe carries, because nothing is tracking these stacks. See networkSerialize for how the two forms differ beyond the flag.
Parameters
stream
Returns
void
toStackDescriptor()
toStackDescriptor(
source,stackNetId?):ItemStackDescriptorData
Defined in: prismarine/src/item/Item.ts:682
This stack as the six wire fields of a NetworkItemStackDescriptor.
The server converts its game item into this protocol DTO at the package boundary; the protocol package writes the bytes. An empty stack zeroes every field after the id, as networkSerialize always has.
Parameters
source
BinaryStream | ProtocolContext
The packet stream or negotiated protocol context that selects item numbering.
stackNetId?
number | null = null
The stack's net id, when the receiver tracks one.
Returns
The descriptor the stack goes out as.
userDataTag()
userDataTag():
NBTTagCompound|null
Defined in: prismarine/src/item/Item.ts:737
What the client is told about this stack beyond its id, count and aux value.
The enchantments, the name, the lore and the durability spent, in the shape itemUserDataTag lays out. Null for a stack with none of them and no durability, which is most of them and every slot of an untouched inventory.
Returns
NBTTagCompound | null
withContents()
withContents(
contents):Item
Defined in: prismarine/src/item/Item.ts:431
A copy of this stack holding different contents.
Parameters
contents
readonly (Item | null)[]
One entry per slot, null for an empty one.
Returns
Item
withCount()
withCount(
count):Item
Defined in: prismarine/src/item/Item.ts:478
A copy of this stack holding a different number of items.
Everything else comes along: the enchantments, the durability spent, the name, the lore, the contents and the content the stack reads its components from. A slot that changes size goes through here, because the wire writes the item's count and not the slot's.
The stack network id comes along too, because a stack that grows or shrinks is still the stack the client knows: a Bedrock Dedicated Server 1.26.52 keeps the id on what is left of a stack and on a stack merged onto. A part split off is a new stack, and the caller clears the id on it.
Parameters
count
number
How many the copy holds. Set after construction, so zero stays zero.
Returns
Item
withDisplay()
withDisplay(
customName,lore?):Item
Defined in: prismarine/src/item/Item.ts:460
A copy of this stack with a different name and lore.
Parameters
customName
string | undefined
The new name, or undefined to go back to the item's own.
lore?
readonly string[] = ...
Returns
Item
withEnchantments()
withEnchantments(
levels):Item
Defined in: prismarine/src/item/Item.ts:451
A copy of this stack carrying a different enchantment set.
A copy rather than a mutation: the anvil and the enchanting table both compute a result before the player has paid for it, and a stack enchanted in place would have been enchanted whether they paid or not.
Parameters
levels
ReadonlyMap<string, number> | Readonly<Record<string, number>>
Returns
Item
withMeta()
withMeta(
meta):Item
Defined in: prismarine/src/item/Item.ts:440
A copy of this stack with a different legacy auxiliary value.
Parameters
meta
number
The replacement auxiliary value, such as a transformed entity-interaction item.
Returns
Item
air()
staticair():Item
Defined in: prismarine/src/item/Item.ts:638
The empty stack.
A count of zero as well as the air name, because at 2168 an empty stack still writes its count - so an "empty" stack holding one of something says the slot has one air in it.
Returns
Item
fromStackDescriptor()
staticfromStackDescriptor(source,descriptor):Item
Defined in: prismarine/src/item/Item.ts:819
The stack a NetworkItemStackDescriptor describes.
Resolves the wire descriptor returned by a protocol packet into the server's game item.
Parameters
source
BinaryStream | ProtocolContext
The packet stream or negotiated protocol context that selects item numbering.
descriptor
The six wire fields.
Returns
Item
The stack, with an unknown id kept so it goes back out as the client sent it.
networkDeserialize()
staticnetworkDeserialize(stream):Item
Defined in: prismarine/src/item/Item.ts:807
Reads an item stack off the wire.
The layout is NetworkItemStackDescriptor, which @jsprismarine/protocol already describes: the id, the count, the aux value, an always present flag saying whether a stack net id follows, the block runtime id, and one length prefixed blob holding the nbt and the can-place-on / can-break lists. All of it, even for air.
The block lists are retained so a stack the client sends can be sent back with the same adventure-mode restrictions. The NBT compound and optional shield blocking tick remain unused here; the user-data structure isolates them from the following packet fields.
Reading the flag is what keeps every field after it aligned. It used to be read only when a caller asked for extra, which no caller ever did, so from that byte onwards the reader was one out: the lists it then walked had garbage lengths, ran off the end of the buffer and threw. Every InventoryTransaction died there - which is what left a survival block break with no sound, the packet never reaching its handler.
Parameters
stream
Returns
Item
See
https://mojang.github.io/bedrock-protocol-docs/1.26.51/types/network-item-stack-descriptor/
networkDeserializeWithoutStackId()
staticnetworkDeserializeWithoutStackId(stream):Item
Defined in: prismarine/src/item/Item.ts:857
Reads the form that carries no stack net id - the creative menu's.
The counterpart to networkSerializeWithoutStackId; see it for why the two forms exist and what confusing them costs.
Parameters
stream
Returns
Item