Skip to content

Zig: Items and containers

Item

Zig
1
2
3
4
pub const Item = struct {
    item_snbt: []const u8,
    // ...
};

An item stack as SNBT, a value: reading it asks the host about that SNBT.

Item.of

Zig
pub fn of(item_snbt_value: []const u8) Item
  • Parameters:
    • item_snbt_value : []const u8
  • Return type: Item

Item.count

Zig
pub fn count(self: Item) core.Error!f64

PIER_IPROP_COUNT: ItemStackBase::mCount

Item.maxStackSize

Zig
pub fn maxStackSize(self: Item) core.Error!f64

PIER_IPROP_MAX_STACK_SIZE: ItemStackBase::getMaxStackSize

Item.auxValue

Zig
pub fn auxValue(self: Item) core.Error!f64

PIER_IPROP_AUX_VALUE: ItemStackBase::getAuxValue

Item.id

Zig
pub fn id(self: Item) core.Error!f64

PIER_IPROP_ID: ItemStackBase::getId

Item.damage

Zig
pub fn damage(self: Item) core.Error!f64

PIER_IPROP_DAMAGE: ItemStackBase::getDamageValue

Item.isNull

Zig
pub fn isNull(self: Item) core.Error!bool

PIER_IPROP_IS_NULL: ItemStackBase::isNull

Item.isBlock

Zig
pub fn isBlock(self: Item) core.Error!bool

PIER_IPROP_IS_BLOCK: ItemStackBase::isBlock

Item.isEnchanted

Zig
pub fn isEnchanted(self: Item) core.Error!bool

PIER_IPROP_IS_ENCHANTED: ItemStackBase::isEnchanted

Item.isArmor

Zig
pub fn isArmor(self: Item) core.Error!bool

PIER_IPROP_IS_ARMOR: ItemStackBase::isArmorItem

Item.isDamageable

Zig
pub fn isDamageable(self: Item) core.Error!bool

PIER_IPROP_IS_DAMAGEABLE: ItemStackBase::isDamageableItem

Item.isDamaged

Zig
pub fn isDamaged(self: Item) core.Error!bool

PIER_IPROP_IS_DAMAGED: ItemStackBase::isDamaged

Item.maxDamage

Zig
pub fn maxDamage(self: Item) core.Error!f64

PIER_IPROP_MAX_DAMAGE: ItemStackBase::getMaxDamage

Item.isUnbreakable

Zig
pub fn isUnbreakable(self: Item) core.Error!bool

PIER_IPROP_IS_UNBREAKABLE: ItemStackBase::isUnbreakable

Item.hasDurability

Zig
pub fn hasDurability(self: Item) core.Error!bool

PIER_IPROP_HAS_DURABILITY: ItemStackBase::hasDurability

Item.isPotion

Zig
pub fn isPotion(self: Item) core.Error!bool

PIER_IPROP_IS_POTION: ItemStackBase::isPotionItem

Item.isThrowable

Zig
pub fn isThrowable(self: Item) core.Error!bool

PIER_IPROP_IS_THROWABLE: ItemStackBase::isThrowable

Item.isFireResistant

Zig
pub fn isFireResistant(self: Item) core.Error!bool

PIER_IPROP_IS_FIRE_RESISTANT: ItemStackBase::isFireResistant

Item.attackDamage

Zig
pub fn attackDamage(self: Item) core.Error!f64

PIER_IPROP_ATTACK_DAMAGE: ItemStackBase::getAttackDamage

Item.repairCost

Zig
pub fn repairCost(self: Item) core.Error!f64

PIER_IPROP_REPAIR_COST: ItemStackBase::getBaseRepairCost

Item.enchantValue

Zig
pub fn enchantValue(self: Item) core.Error!f64

PIER_IPROP_ENCHANT_VALUE: ItemStackBase::getEnchantValue

Item.isStackable

Zig
pub fn isStackable(self: Item) core.Error!bool

PIER_IPROP_IS_STACKABLE: ItemStackBase::isStackable

Item.isMusicDisc

Zig
pub fn isMusicDisc(self: Item) core.Error!bool

PIER_IPROP_IS_MUSIC_DISC: ItemStackBase::isMusicDiscItem

Item.isOffhand

Zig
pub fn isOffhand(self: Item) core.Error!bool

PIER_IPROP_IS_OFFHAND: ItemStackBase::isOffhandItem

Item.useDuration

Zig
pub fn useDuration(self: Item) core.Error!f64

PIER_IPROP_USE_DURATION: ItemStackBase::getMaxUseDuration

Item.isGlint

Zig
pub fn isGlint(self: Item) core.Error!bool

PIER_IPROP_IS_GLINT: ItemStackBase::isGlint

Item.isBundle

Zig
pub fn isBundle(self: Item) core.Error!bool

PIER_IPROP_IS_BUNDLE: ItemStackBase::isBundle

Item.hasUserData

Zig
pub fn hasUserData(self: Item) core.Error!bool

PIER_IPROP_HAS_USER_DATA: ItemStackBase::hasUserData

Item.hasCustomName

Zig
pub fn hasCustomName(self: Item) core.Error!bool

PIER_IPROP_HAS_CUSTOM_NAME: ItemStackBase::hasCustomHoverName

Item.isFood

Zig
pub fn isFood(self: Item) core.Error!bool

PIER_IPROP_IS_FOOD: Item::isFood

Item.isDyeable

Zig
pub fn isDyeable(self: Item) core.Error!bool

PIER_IPROP_IS_DYEABLE: Item::isDyeable

Item.isHandEquipped

Zig
pub fn isHandEquipped(self: Item) core.Error!bool

PIER_IPROP_IS_HAND_EQUIPPED: Item::isHandEquipped

Item.isLiquidClip

Zig
pub fn isLiquidClip(self: Item) core.Error!bool

PIER_IPROP_IS_LIQUID_CLIP: Item::isLiquidClipItem

Item.isStackedByData

Zig
pub fn isStackedByData(self: Item) core.Error!bool

PIER_IPROP_IS_STACKED_BY_DATA: Item::isStackedByData

Item.cooldownDuration

Zig
pub fn cooldownDuration(self: Item) core.Error!f64

PIER_IPROP_COOLDOWN_DURATION: Item::getCooldownDuration, in ticks

Item.isComponentBased

Zig
pub fn isComponentBased(self: Item) core.Error!bool

PIER_IPROP_IS_COMPONENT_BASED: Item::isComponentBased

Item.isHumanoidArmor

Zig
pub fn isHumanoidArmor(self: Item) core.Error!bool

PIER_IPROP_IS_HUMANOID_ARMOR: Item::isHumanoidArmor

Item.armorValue

Zig
pub fn armorValue(self: Item) core.Error!f64

PIER_IPROP_ARMOR_VALUE: Item::getArmorValue

Item.canBeDepleted

Zig
pub fn canBeDepleted(self: Item) core.Error!bool

PIER_IPROP_CAN_BE_DEPLETED: Item::canBeDepleted

Item.isUseable

Zig
pub fn isUseable(self: Item) core.Error!bool

PIER_IPROP_IS_USEABLE: Item::isUseable

Item.canDestroyInCreative

Zig
pub fn canDestroyInCreative(self: Item) core.Error!bool

PIER_IPROP_CAN_DESTROY_IN_CREATIVE: Item::canDestroyInCreative

Item.showsDurabilityInCreative

Zig
pub fn showsDurabilityInCreative(self: Item) core.Error!f64

PIER_IPROP_SHOWS_DURABILITY_IN_CREATIVE: Item::showsDurabilityInCreative

Item.typeName

Zig
pub fn typeName(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_TYPE_NAME: ItemStackBase::getTypeName ("minecraft:apple")

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.name

Zig
pub fn name(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_NAME: ItemStackBase::getName (display)

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.customName

Zig
pub fn customName(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_CUSTOM_NAME: ItemStackBase::getCustomName

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.rawNameId

Zig
pub fn rawNameId(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_RAW_NAME_ID: ItemStackBase::getRawNameId

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.lore

Zig
pub fn lore(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_LORE: SNBT list ["l1","l2"] ItemStackBase::getCustomLore

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.canDestroy

Zig
pub fn canDestroy(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_CAN_DESTROY: SNBT list ["minecraft:stone",…]

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.canPlaceOn

Zig
pub fn canPlaceOn(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_CAN_PLACE_ON: SNBT list

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.userData

Zig
pub fn userData(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_USER_DATA: full NBT user data as SNBT

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.hoverName

Zig
pub fn hoverName(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_HOVER_NAME: ItemStackBase::getHoverName

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.effectName

Zig
pub fn effectName(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_EFFECT_NAME: ItemStackBase::getEffectName

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.color

Zig
pub fn color(self: Item, allocator: std.mem.Allocator) core.Error![]u8

PIER_ISTR_COLOR: SNBT {r,g,b} ItemStackBase::getColor

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_str

Item.create

Zig
pub fn create(allocator: std.mem.Allocator, type_name: []const u8, amount: u8) std.mem.Allocator.Error![]u8

Builds an item from a type name and a count, as SNBT owned by the caller.

  • Parameters:
    • allocator : std.mem.Allocator
    • type_name : []const u8
    • amount : u8
  • Return type: std.mem.Allocator.Error![]u8

Item.matches

Zig
pub fn matches(self: Item, other: Item) core.Error!bool

Whether two items are the same kind of thing.

  • Parameters:
    • other : Item
  • Return type: core.Error!bool
  • Slots: item_matches

Item.transform

Zig
pub fn transform(self: Item, allocator: std.mem.Allocator, op: types.ItemOp, sarg: []const u8, narg: f64) core.Error![]u8

Runs one transform and returns the new item as SNBT, owned by the caller. This item is unchanged.

  • Parameters:
    • allocator : std.mem.Allocator
    • op : types.ItemOp
    • sarg : []const u8
    • narg : f64
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withCustomName

Zig
pub fn withCustomName(self: Item, allocator: std.mem.Allocator, new_name: []const u8) core.Error![]u8
  • Parameters:
    • allocator : std.mem.Allocator
    • new_name : []const u8
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withoutCustomName

Zig
pub fn withoutCustomName(self: Item, allocator: std.mem.Allocator) core.Error![]u8
  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withDamage

Zig
pub fn withDamage(self: Item, allocator: std.mem.Allocator, value: i32) core.Error![]u8
  • Parameters:
    • allocator : std.mem.Allocator
    • value : i32
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withCount

Zig
pub fn withCount(self: Item, allocator: std.mem.Allocator, amount: u8) core.Error![]u8
  • Parameters:
    • allocator : std.mem.Allocator
    • amount : u8
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withUnbreakable

Zig
pub fn withUnbreakable(self: Item, allocator: std.mem.Allocator, on: bool) core.Error![]u8
  • Parameters:
    • allocator : std.mem.Allocator
    • on : bool
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.hurtAndBreak

Zig
pub fn hurtAndBreak(self: Item, allocator: std.mem.Allocator, wear: i32) core.Error![]u8

Wears the item down by wear, breaking it when it runs out.

  • Parameters:
    • allocator : std.mem.Allocator
    • wear : i32
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withRepairCost

Zig
pub fn withRepairCost(self: Item, allocator: std.mem.Allocator, cost: i32) core.Error![]u8
  • Parameters:
    • allocator : std.mem.Allocator
    • cost : i32
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withLore

Zig
pub fn withLore(self: Item, allocator: std.mem.Allocator, lines: []const []const u8) core.Error![]u8

Sets the lore, one string per line.

  • Parameters:
    • allocator : std.mem.Allocator
    • lines : []const []const u8
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withoutLore

Zig
pub fn withoutLore(self: Item, allocator: std.mem.Allocator) core.Error![]u8
  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withEnchant

Zig
pub fn withEnchant(self: Item, allocator: std.mem.Allocator, enchant_id: []const u8, level: i32) core.Error![]u8

Adds an enchantment. A level of 0 removes it, as far as the engine is concerned.

  • Parameters:
    • allocator : std.mem.Allocator
    • enchant_id : []const u8
    • level : i32
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withoutEnchants

Zig
pub fn withoutEnchants(self: Item, allocator: std.mem.Allocator) core.Error![]u8
  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withCanDestroy

Zig
pub fn withCanDestroy(self: Item, allocator: std.mem.Allocator, blocks: []const []const u8) core.Error![]u8

The blocks the item may break in adventure mode.

  • Parameters:
    • allocator : std.mem.Allocator
    • blocks : []const []const u8
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.withCanPlaceOn

Zig
pub fn withCanPlaceOn(self: Item, allocator: std.mem.Allocator, blocks: []const []const u8) core.Error![]u8

The blocks the item may be placed on in adventure mode.

  • Parameters:
    • allocator : std.mem.Allocator
    • blocks : []const []const u8
  • Return type: core.Error![]u8
  • Slots: item_transform

Item.enchants

Zig
pub fn enchants(self: Item, allocator: std.mem.Allocator) core.Error!types.Owned(types.Enchant)

The enchantments on the item.

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error!types.Owned(types.Enchant)
  • Slots: item_get_enchants

Item.withEnchants

Zig
pub fn withEnchants(self: Item, allocator: std.mem.Allocator, set: []const types.Enchant) core.Error![]u8

Replaces the whole enchantment set and returns the new item as SNBT, owned by the caller. Every current host answers NotProvided: writing enchantments is not implemented, and withEnchant is the way to add one.

  • Parameters:
    • allocator : std.mem.Allocator
    • set : []const types.Enchant
  • Return type: core.Error![]u8
  • Slots: item_set_enchants

Item.userDataSnbt

Zig
pub fn userDataSnbt(self: Item, allocator: std.mem.Allocator) core.Error![]u8

The custom NBT of the item, the tag section, as SNBT owned by the caller. It goes through a dedicated slot and not a string property.

  • Parameters:
    • allocator : std.mem.Allocator
  • Return type: core.Error![]u8
  • Slots: item_get_user_data

container.Container

Zig
1
2
3
4
5
6
7
8
9
pub const Container = struct {
    kind: Kind,
    owner: props.Player,
    dim: i32 = 0,
    x: i32 = 0,
    y: i32 = 0,
    z: i32 = 0,
    // ...
};

A reference to one container.

container.Container.ofPlayer

Zig
pub fn ofPlayer(owner: props.Player, kind: Kind) Container

One container on a player.

  • Parameters:
    • owner : props.Player
    • kind : Kind
  • Return type: Container

container.Container.block

Zig
pub fn block(dim: i32, x: i32, y: i32, z: i32) Container

A block container at a coordinate in the world.

  • Parameters:
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
  • Return type: Container

container.Container.size

Zig
pub fn size(self: Container) core.Error!i32

The slot count.

container.Container.item

Zig
pub fn item(self: Container, allocator: Allocator, slot: i32) core.Error![]u8

What is in one slot, as item SNBT owned by the caller. An empty slot gives the SNBT of the air item and is not an error.

  • Parameters:
    • allocator : Allocator
    • slot : i32
  • Return type: core.Error![]u8
  • Slots: container_get_item

container.Container.items

Zig
pub fn items(self: Container, allocator: Allocator) core.Error![][]u8

Every slot as item SNBT in slot order, owned by the caller; core.freeList releases them.

container.Container.setItem

Zig
pub fn setItem(self: Container, slot: i32, item_snbt: []const u8) core.Error!void

Writes one slot. Call refresh afterwards for a player's container.

  • Parameters:
    • slot : i32
    • item_snbt : []const u8
  • Return type: core.Error!void
  • Slots: container_set_item

container.Container.addItem

Zig
pub fn addItem(self: Container, item_snbt: []const u8) core.Error!void

Puts one in and lets the engine pick the slot.

  • Parameters:
    • item_snbt : []const u8
  • Return type: core.Error!void
  • Slots: container_add_item

container.Container.removeItem

Zig
pub fn removeItem(self: Container, slot: i32, count: i32) core.Error!void

Takes count items out of one slot.

container.Container.clear

Zig
pub fn clear(self: Container) core.Error!void

container.Container.refresh

Zig
pub fn refresh(self: Container) core.Error!void

Resends the whole container to its owner. A block container has no owner to resend to and is Refused.

container.Kind

Zig
1
2
3
4
5
6
7
pub const Kind = enum(i32) {
    inventory = 0,
    ender_chest = 1,
    armor = 2,
    off_hand = 3,
    block = 4,
};

The kind of a container. The values align with PierContainerRef::which.

container.Kind.isPlayerOwned

Zig
pub fn isPlayerOwned(self: Kind) bool

A block container has no single owner and therefore cannot be resynchronized.

  • Return type: bool