API reference / @jsprismarine/prismarine / item/Item / Item
Class: Item
Defined in: packages/prismarine/src/item/Item.ts:194
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: packages/prismarine/src/item/Item.ts:277
Parameters
__namedParameters
Returns
Item
Properties
count
count:
number=1
Defined in: packages/prismarine/src/item/Item.ts:204
durability
durability:
number
Defined in: packages/prismarine/src/item/Item.ts:200
meta
meta:
number=0
Defined in: packages/prismarine/src/item/Item.ts:199
nbt
nbt:
null=null
Defined in: packages/prismarine/src/item/Item.ts:203
selectedBundleItem
selectedBundleItem:
number=-1
Defined in: packages/prismarine/src/item/Item.ts:228
The place in the stack's minecraft:bundle_contents of the stack the player picked in the bundle's tooltip, or -1 for none; see bundleContents.ts.
Changed in place, as vanilla changes its stack, because the client that picked it already shows it: like vanilla's it is neither saved nor sent, and a slot is not shown again for it. Every copy keeps it but one with new bundle contents.
Java See
BundleContents.selectedItem
stackNetworkId
stackNetworkId:
number=0
Defined in: packages/prismarine/src/item/Item.ts:217
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: packages/prismarine/src/item/Item.ts:777
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: packages/prismarine/src/item/Item.ts:690
Returns
number
getArmorDefensePoints()
getArmorDefensePoints():
number
Defined in: packages/prismarine/src/item/Item.ts:471
The armor points the item is worth while worn.
Returns
number
getArmorToughness()
getArmorToughness():
number
Defined in: packages/prismarine/src/item/Item.ts:476
The armor toughness the item is worth while worn.
Returns
number
getAttackDamage()
getAttackDamage():
number
Defined in: packages/prismarine/src/item/Item.ts:466
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: packages/prismarine/src/item/Item.ts:907
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: packages/prismarine/src/item/Item.ts:454
How long the item burns in a furnace, in ticks.
Returns
number
getCanDestroyBlocks()
getCanDestroyBlocks(): readonly
string[]
Defined in: packages/prismarine/src/item/Item.ts:525
The Bedrock block identifiers this stack may destroy.
Returns
readonly string[]
getCanPlaceOnBlocks()
getCanPlaceOnBlocks(): readonly
string[]
Defined in: packages/prismarine/src/item/Item.ts:520
The Bedrock block identifiers this stack may be placed on.
Returns
readonly string[]
getComponents()
getComponents():
StackComponents
Defined in: packages/prismarine/src/item/Item.ts:539
The Java components the stack sets beyond its enchantments, name, lore, durability, contents and map, by namespaced id: what a smithing trim, a dye, a firework recipe or a trade wrote onto it. Empty for most stacks.
Returns
StackComponents
getContent()
getContent():
ServerContent|undefined
Defined in: packages/prismarine/src/item/Item.ts:317
The content the stack reads its item type from, or undefined for Java's committed table.
Returns
ServerContent | undefined
getContents()
getContents(): readonly (
Item|null)[]
Defined in: packages/prismarine/src/item/Item.ts:515
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: packages/prismarine/src/item/Item.ts:501
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: packages/prismarine/src/item/Item.ts:682
Returns
number
getEnchantmentLevel()
getEnchantmentLevel(
enchantment):number
Defined in: packages/prismarine/src/item/Item.ts:496
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: packages/prismarine/src/item/Item.ts:487
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: packages/prismarine/src/item/Item.ts:449
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: packages/prismarine/src/item/Item.ts:332
The Java datapack tags attached to this Bedrock item type.
Returns
readonly string[]
getLore()
getLore(): readonly
string[]
Defined in: packages/prismarine/src/item/Item.ts:506
The lore lines on this stack, which is an empty array for most of them.
Returns
readonly string[]
getMapId()
getMapId():
number|undefined
Defined in: packages/prismarine/src/item/Item.ts:530
Which saved map this stack shows, or undefined for anything but a filled map that has one.
Returns
number | undefined
getMaxAmount()
getMaxAmount():
number
Defined in: packages/prismarine/src/item/Item.ts:686
Returns
number
getMaxDurability()
getMaxDurability():
number
Defined in: packages/prismarine/src/item/Item.ts:678
Returns
number
getMeta()
getMeta():
number
Defined in: packages/prismarine/src/item/Item.ts:387
The stack's damage or variant value, which the wire carries beside the id.
Returns
number
getMiningSpeed()
getMiningSpeed(
block):number
Defined in: packages/prismarine/src/item/Item.ts:746
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.
Java Source
Player.getDestroySpeed
Java Source
Item.getDestroySpeed
getName()
getName():
string
Defined in: packages/prismarine/src/item/Item.ts:312
Returns
string
getRuntimeId()
getRuntimeId():
number
Defined in: packages/prismarine/src/item/Item.ts:371
The Bedrock runtime id for this item under the canonical numbering, the newest release'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: packages/prismarine/src/item/Item.ts:322
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: packages/prismarine/src/item/Item.ts:711
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: packages/prismarine/src/item/Item.ts:360
Whether the resolved item type declares the named data component.
Parameters
name
string
Returns
boolean
hasEnchantment()
hasEnchantment(
enchantment):boolean
Defined in: packages/prismarine/src/item/Item.ts:674
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: packages/prismarine/src/item/Item.ts:341
Whether a Java datapack tag includes this item type.
Parameters
tag
string
Returns
boolean
hasTag()
hasTag(
tag):boolean
Defined in: packages/prismarine/src/item/Item.ts:327
Whether this item type carries one of its Bedrock tags.
Parameters
tag
string
Returns
boolean
isArmorPiece()
isArmorPiece():
boolean
Defined in: packages/prismarine/src/item/Item.ts:436
Whether the item's components give it an armor value.
Returns
boolean
isPartOfCreativeInventory()
isPartOfCreativeInventory():
boolean
Defined in: packages/prismarine/src/item/Item.ts:694
Returns
boolean
isTool()
isTool():
boolean
Defined in: packages/prismarine/src/item/Item.ts:431
Whether the item's components make it a tool.
Returns
boolean
networkSerialize()
networkSerialize(
stream,stackNetId?):void
Defined in: packages/prismarine/src/item/Item.ts:847
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: packages/prismarine/src/item/Item.ts:885
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
rawComponent()
rawComponent(
name):unknown
Defined in: packages/prismarine/src/item/Item.ts:352
A data component as this stack carries it, or else as its item type's definition writes it, unparsed, for a rule that reads a field the parsed component leaves out, such as a totem's death_effects.
Parameters
name
string
Returns
unknown
toStackDescriptor()
toStackDescriptor(
source,stackNetId?):ItemStackDescriptorData
Defined in: packages/prismarine/src/item/Item.ts:861
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: packages/prismarine/src/item/Item.ts:930
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
withComponents()
withComponents(
changes):Item
Defined in: packages/prismarine/src/item/Item.ts:549
A copy of this stack with some of its other components set.
Parameters
changes
Readonly<Record<string, unknown>>
Component ids and values. An undefined value removes the component, and a component the stack holds in a field of its own is left out.
Returns
Item
withContents()
withContents(
contents):Item
Defined in: packages/prismarine/src/item/Item.ts:565
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: packages/prismarine/src/item/Item.ts:621
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: an unpinned Bedrock Dedicated Server 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: packages/prismarine/src/item/Item.ts:603
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
withDurability()
withDurability(
durability):Item
Defined in: packages/prismarine/src/item/Item.ts:636
A copy of this stack with durability left, which is how a tool wears.
A copy and not a change in place, so the slot that holds the stack is written and the change log hears it. The stack network id comes along, as Item.withCount keeps it.
Parameters
durability
number
The durability the copy has left.
Returns
Item
withEnchantments()
withEnchantments(
levels):Item
Defined in: packages/prismarine/src/item/Item.ts:594
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
Readonly<Record<string, number>> | ReadonlyMap<string, number>
Returns
Item
withMapId()
withMapId(
mapId):Item
Defined in: packages/prismarine/src/item/Item.ts:574
A copy of this stack showing a different saved map.
Parameters
mapId
number
The map's id in its level, Java's minecraft:map_id.
Returns
Item
withMeta()
withMeta(
meta):Item
Defined in: packages/prismarine/src/item/Item.ts:583
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: packages/prismarine/src/item/Item.ts:817
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: packages/prismarine/src/item/Item.ts:1014
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: packages/prismarine/src/item/Item.ts:1002
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: packages/prismarine/src/item/Item.ts:1052
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