Zig:物品与容器
Item
| Zig |
|---|
| pub const Item = struct {
item_snbt: []const u8,
// ...
};
|
以 SNBT 表示的物品堆,是一个值:读取它,就是拿这段 SNBT 去问宿主。
Item.of
| Zig |
|---|
| pub fn of(item_snbt_value: []const u8) Item
|
- 参数:
- item_snbt_value :
[]const u8
- 返回值类型:
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,单位为刻
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")
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.name
| Zig |
|---|
| pub fn name(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
PIER_ISTR_NAME:取自 ItemStackBase::getName(显示名)
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.customName
| Zig |
|---|
| pub fn customName(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
PIER_ISTR_CUSTOM_NAME:取自 ItemStackBase::getCustomName
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
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
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.lore
| Zig |
|---|
| pub fn lore(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
PIER_ISTR_LORE:SNBT 列表 ["l1","l2"],取自 ItemStackBase::getCustomLore
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.canDestroy
| Zig |
|---|
| pub fn canDestroy(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
PIER_ISTR_CAN_DESTROY:SNBT 列表 ["minecraft:stone",…]
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.canPlaceOn
| Zig |
|---|
| pub fn canPlaceOn(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
PIER_ISTR_CAN_PLACE_ON:SNBT 列表
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.userData
| Zig |
|---|
| pub fn userData(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
PIER_ISTR_USER_DATA:完整的 NBT 用户数据,以 SNBT 表示
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.hoverName
| Zig |
|---|
| pub fn hoverName(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
PIER_ISTR_HOVER_NAME:取自 ItemStackBase::getHoverName
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.effectName
| Zig |
|---|
| pub fn effectName(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
PIER_ISTR_EFFECT_NAME:取自 ItemStackBase::getEffectName
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
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
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_get_str
Item.create
| Zig |
|---|
| pub fn create(allocator: std.mem.Allocator, type_name: []const u8, amount: u8) std.mem.Allocator.Error![]u8
|
用类型名和数量构造一个物品,SNBT 形式,由调用方持有。
- 参数:
- allocator :
std.mem.Allocator
- type_name :
[]const u8
- amount :
u8
- 返回值类型:
std.mem.Allocator.Error![]u8
Item.matches
| Zig |
|---|
| pub fn matches(self: Item, other: Item) core.Error!bool
|
两个物品是否是同一种东西。
| Zig |
|---|
| pub fn transform(self: Item, allocator: std.mem.Allocator, op: types.ItemOp, sarg: []const u8, narg: f64) core.Error![]u8
|
执行一次变换,并返回新物品的 SNBT,由调用方持有。原物品不变。
- 参数:
- allocator :
std.mem.Allocator
- op :
types.ItemOp
- sarg :
[]const u8
- narg :
f64
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withCustomName
| Zig |
|---|
| pub fn withCustomName(self: Item, allocator: std.mem.Allocator, new_name: []const u8) core.Error![]u8
|
- 参数:
- allocator :
std.mem.Allocator
- new_name :
[]const u8
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withoutCustomName
| Zig |
|---|
| pub fn withoutCustomName(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withDamage
| Zig |
|---|
| pub fn withDamage(self: Item, allocator: std.mem.Allocator, value: i32) core.Error![]u8
|
- 参数:
- allocator :
std.mem.Allocator
- value :
i32
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withCount
| Zig |
|---|
| pub fn withCount(self: Item, allocator: std.mem.Allocator, amount: u8) core.Error![]u8
|
- 参数:
- allocator :
std.mem.Allocator
- amount :
u8
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withUnbreakable
| Zig |
|---|
| pub fn withUnbreakable(self: Item, allocator: std.mem.Allocator, on: bool) core.Error![]u8
|
- 参数:
- allocator :
std.mem.Allocator
- on :
bool
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.hurtAndBreak
| Zig |
|---|
| pub fn hurtAndBreak(self: Item, allocator: std.mem.Allocator, wear: i32) core.Error![]u8
|
让物品磨损 wear 点,磨完时物品会损坏。
- 参数:
- allocator :
std.mem.Allocator
- wear :
i32
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withRepairCost
| Zig |
|---|
| pub fn withRepairCost(self: Item, allocator: std.mem.Allocator, cost: i32) core.Error![]u8
|
- 参数:
- allocator :
std.mem.Allocator
- cost :
i32
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withLore
| Zig |
|---|
| pub fn withLore(self: Item, allocator: std.mem.Allocator, lines: []const []const u8) core.Error![]u8
|
设置物品说明文字,每行一个字符串。
- 参数:
- allocator :
std.mem.Allocator
- lines :
[]const []const u8
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withoutLore
| Zig |
|---|
| pub fn withoutLore(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withEnchant
| Zig |
|---|
| pub fn withEnchant(self: Item, allocator: std.mem.Allocator, enchant_id: []const u8, level: i32) core.Error![]u8
|
添加一个附魔。等级为 0 时,在引擎看来就是移除它。
- 参数:
- allocator :
std.mem.Allocator
- enchant_id :
[]const u8
- level :
i32
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withoutEnchants
| Zig |
|---|
| pub fn withoutEnchants(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withCanDestroy
| Zig |
|---|
| pub fn withCanDestroy(self: Item, allocator: std.mem.Allocator, blocks: []const []const u8) core.Error![]u8
|
物品在冒险模式下可以破坏的方块。
- 参数:
- allocator :
std.mem.Allocator
- blocks :
[]const []const u8
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.withCanPlaceOn
| Zig |
|---|
| pub fn withCanPlaceOn(self: Item, allocator: std.mem.Allocator, blocks: []const []const u8) core.Error![]u8
|
物品在冒险模式下可以放置到的方块上。
- 参数:
- allocator :
std.mem.Allocator
- blocks :
[]const []const u8
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_transform
Item.enchants
| Zig |
|---|
| pub fn enchants(self: Item, allocator: std.mem.Allocator) core.Error!types.Owned(types.Enchant)
|
物品上的附魔。
- 参数:
- allocator :
std.mem.Allocator
- 返回值类型:
core.Error!types.Owned(types.Enchant)
- 对应槽位:
item_get_enchants
Item.withEnchants
| Zig |
|---|
| pub fn withEnchants(self: Item, allocator: std.mem.Allocator, set: []const types.Enchant) core.Error![]u8
|
替换整套附魔,并返回新物品的 SNBT,由调用方持有。目前所有宿主都返回 NotProvided:写入附魔没有实现,要添加一个附魔请用 withEnchant。
- 参数:
- allocator :
std.mem.Allocator
- set :
[]const types.Enchant
- 返回值类型:
core.Error![]u8
- 对应槽位:
item_set_enchants
Item.userDataSnbt
| Zig |
|---|
| pub fn userDataSnbt(self: Item, allocator: std.mem.Allocator) core.Error![]u8
|
物品的自定义 NBT,也就是 tag 部分,SNBT 形式,由调用方持有。它走专用槽位,而不是字符串属性。
container.Container
| Zig |
|---|
| pub const Container = struct {
kind: Kind,
owner: props.Player,
dim: i32 = 0,
x: i32 = 0,
y: i32 = 0,
z: i32 = 0,
// ...
};
|
对一个容器的引用。
container.Container.ofPlayer
| Zig |
|---|
| pub fn ofPlayer(owner: props.Player, kind: Kind) Container
|
玩家身上的一个容器。
- 参数:
- owner :
props.Player
- kind :
Kind
- 返回值类型:
Container
container.Container.block
| Zig |
|---|
| pub fn block(dim: i32, x: i32, y: i32, z: i32) Container
|
世界里某个坐标处的方块容器。
- 参数:
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- 返回值类型:
Container
container.Container.size
| Zig |
|---|
| pub fn size(self: Container) core.Error!i32
|
槽位数。
container.Container.item
| Zig |
|---|
| pub fn item(self: Container, allocator: Allocator, slot: i32) core.Error![]u8
|
一个槽位里的内容,物品 SNBT 形式,由调用方持有。空槽位给出空气物品的 SNBT,不是错误。
container.Container.items
| Zig |
|---|
| pub fn items(self: Container, allocator: Allocator) core.Error![][]u8
|
按槽位顺序给出每个槽位,物品 SNBT 形式,由调用方持有;用 core.freeList 释放。
container.Container.setItem
| Zig |
|---|
| pub fn setItem(self: Container, slot: i32, item_snbt: []const u8) core.Error!void
|
写入一个槽位。玩家的容器写完后要调用 refresh。
container.Container.addItem
| Zig |
|---|
| pub fn addItem(self: Container, item_snbt: []const u8) core.Error!void
|
放进去一个,槽位由引擎挑选。
container.Container.removeItem
| Zig |
|---|
| pub fn removeItem(self: Container, slot: i32, count: i32) core.Error!void
|
从某一格取出 count 个物品。
container.Container.clear
| Zig |
|---|
| pub fn clear(self: Container) core.Error!void
|
container.Container.refresh
| Zig |
|---|
| pub fn refresh(self: Container) core.Error!void
|
把整个容器重新发给它的主人。方块容器没有主人可发,会得到 Refused。
container.Kind
| Zig |
|---|
| pub const Kind = enum(i32) {
inventory = 0,
ender_chest = 1,
armor = 2,
off_hand = 3,
block = 4,
};
|
容器的种类。取值和 PierContainerRef::which 对齐。
container.Kind.isPlayerOwned
| Zig |
|---|
| pub fn isPlayerOwned(self: Kind) bool
|
方块容器没有唯一的主人,所以无法重新同步。