跳转至

Go:物品与容器

函数

ContainerItems

Go
func ContainerItems(ref ContainerRef) ([]SlotItem, error)

列出一个容器里有东西的格子。只能在服务器线程调用。

  • 参数:
    • ref : ContainerRef
  • 返回值类型:([]SlotItem, error)
  • 对应槽位:container_get_items

ItemOf

Go
func ItemOf(snbt string) Item

这段 SNBT 描述的物品堆。

  • 参数:
    • snbt : string
  • 返回值类型:Item

Item

Go
1
2
3
type Item struct {
    SNBT string
}

以 SNBT 表示的物品堆,是一个值:读取它,就是拿这段 SNBT 去问宿主;修改它会得到一个新的 Item。

Item.Payload

Go
func (i Item) Payload() (*Nbt, error)

解析后的物品 SNBT。

  • 返回值类型:(*Nbt, error)

Item.Enchants

Go
func (i Item) Enchants() (string, error)

以 SNBT 列出这个物品的附魔。

Item.Matches

Go
func (i Item) Matches(other Item) (bool, error)

判断两个物品能否堆叠:同一种物品,数据值和用户数据都相同。

  • 参数:
    • other : Item
  • 返回值类型:(bool, error)
  • 对应槽位:item_matches

Item.Transform

Go
func (i Item) Transform(op int32, sarg string, narg float64) (Item, error)

执行 abi.h 里的某一个 PIER_IOP_* 操作,返回新的物品。

  • 参数:
    • op : int32
    • sarg : string
    • narg : float64
  • 返回值类型:(Item, error)
  • 对应槽位:item_transform

Item.Count

Go
func (i Item) Count() (float64, error)

读取 PIER_IPROP_COUNT:取自 ItemStackBase::mCount

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.MaxStackSize

Go
func (i Item) MaxStackSize() (float64, error)

读取 PIER_IPROP_MAX_STACK_SIZE:取自 ItemStackBase::getMaxStackSize

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.AuxValue

Go
func (i Item) AuxValue() (float64, error)

读取 PIER_IPROP_AUX_VALUE:取自 ItemStackBase::getAuxValue

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.Id

Go
func (i Item) Id() (float64, error)

读取 PIER_IPROP_ID:取自 ItemStackBase::getId

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.Damage

Go
func (i Item) Damage() (float64, error)

读取 PIER_IPROP_DAMAGE:取自 ItemStackBase::getDamageValue

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.IsNull

Go
func (i Item) IsNull() (bool, error)

读取 PIER_IPROP_IS_NULL:取自 ItemStackBase::isNull

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsBlock

Go
func (i Item) IsBlock() (bool, error)

读取 PIER_IPROP_IS_BLOCK:取自 ItemStackBase::isBlock

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsEnchanted

Go
func (i Item) IsEnchanted() (bool, error)

读取 PIER_IPROP_IS_ENCHANTED:取自 ItemStackBase::isEnchanted

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsArmor

Go
func (i Item) IsArmor() (bool, error)

读取 PIER_IPROP_IS_ARMOR:取自 ItemStackBase::isArmorItem

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsDamageable

Go
func (i Item) IsDamageable() (bool, error)

读取 PIER_IPROP_IS_DAMAGEABLE:取自 ItemStackBase::isDamageableItem

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsDamaged

Go
func (i Item) IsDamaged() (bool, error)

读取 PIER_IPROP_IS_DAMAGED:取自 ItemStackBase::isDamaged

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.MaxDamage

Go
func (i Item) MaxDamage() (float64, error)

读取 PIER_IPROP_MAX_DAMAGE:取自 ItemStackBase::getMaxDamage

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.IsUnbreakable

Go
func (i Item) IsUnbreakable() (bool, error)

读取 PIER_IPROP_IS_UNBREAKABLE:取自 ItemStackBase::isUnbreakable

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.HasDurability

Go
func (i Item) HasDurability() (bool, error)

读取 PIER_IPROP_HAS_DURABILITY:取自 ItemStackBase::hasDurability

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsPotion

Go
func (i Item) IsPotion() (bool, error)

读取 PIER_IPROP_IS_POTION:取自 ItemStackBase::isPotionItem

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsThrowable

Go
func (i Item) IsThrowable() (bool, error)

读取 PIER_IPROP_IS_THROWABLE:取自 ItemStackBase::isThrowable

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsFireResistant

Go
func (i Item) IsFireResistant() (bool, error)

读取 PIER_IPROP_IS_FIRE_RESISTANT:取自 ItemStackBase::isFireResistant

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.AttackDamage

Go
func (i Item) AttackDamage() (float64, error)

读取 PIER_IPROP_ATTACK_DAMAGE:取自 ItemStackBase::getAttackDamage

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.RepairCost

Go
func (i Item) RepairCost() (float64, error)

读取 PIER_IPROP_REPAIR_COST:取自 ItemStackBase::getBaseRepairCost

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.EnchantValue

Go
func (i Item) EnchantValue() (float64, error)

读取 PIER_IPROP_ENCHANT_VALUE:取自 ItemStackBase::getEnchantValue

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.IsStackable

Go
func (i Item) IsStackable() (bool, error)

读取 PIER_IPROP_IS_STACKABLE:取自 ItemStackBase::isStackable

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsMusicDisc

Go
func (i Item) IsMusicDisc() (bool, error)

读取 PIER_IPROP_IS_MUSIC_DISC:取自 ItemStackBase::isMusicDiscItem

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsOffhand

Go
func (i Item) IsOffhand() (bool, error)

读取 PIER_IPROP_IS_OFFHAND:取自 ItemStackBase::isOffhandItem

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.UseDuration

Go
func (i Item) UseDuration() (float64, error)

读取 PIER_IPROP_USE_DURATION:取自 ItemStackBase::getMaxUseDuration

  • 返回值类型:(float64, error)
  • 对应槽位:item_get_num

Item.IsGlint

Go
func (i Item) IsGlint() (bool, error)

读取 PIER_IPROP_IS_GLINT:取自 ItemStackBase::isGlint

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.IsBundle

Go
func (i Item) IsBundle() (bool, error)

读取 PIER_IPROP_IS_BUNDLE:取自 ItemStackBase::isBundle

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.HasUserData

Go
func (i Item) HasUserData() (bool, error)

读取 PIER_IPROP_HAS_USER_DATA:取自 ItemStackBase::hasUserData

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.HasCustomName

Go
func (i Item) HasCustomName() (bool, error)

读取 PIER_IPROP_HAS_CUSTOM_NAME:取自 ItemStackBase::hasCustomHoverName

  • 返回值类型:(bool, error)
  • 对应槽位:item_get_num

Item.TypeName

Go
func (i Item) TypeName() (string, error)

读取 PIER_ISTR_TYPE_NAME:取自 ItemStackBase::getTypeName(形如 "minecraft:apple")

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.Name

Go
func (i Item) Name() (string, error)

读取 PIER_ISTR_NAME:取自 ItemStackBase::getName(显示名)

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.CustomName

Go
func (i Item) CustomName() (string, error)

读取 PIER_ISTR_CUSTOM_NAME:取自 ItemStackBase::getCustomName

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.RawNameId

Go
func (i Item) RawNameId() (string, error)

读取 PIER_ISTR_RAW_NAME_ID:取自 ItemStackBase::getRawNameId

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.Lore

Go
func (i Item) Lore() (string, error)

读取 PIER_ISTR_LORE:SNBT 列表 ["l1","l2"],取自 ItemStackBase::getCustomLore

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.CanDestroy

Go
func (i Item) CanDestroy() (string, error)

读取 PIER_ISTR_CAN_DESTROY:SNBT 列表 ["minecraft:stone",…]

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.CanPlaceOn

Go
func (i Item) CanPlaceOn() (string, error)

读取 PIER_ISTR_CAN_PLACE_ON:SNBT 列表

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.UserData

Go
func (i Item) UserData() (string, error)

读取 PIER_ISTR_USER_DATA:完整的 NBT 用户数据,以 SNBT 表示

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.HoverName

Go
func (i Item) HoverName() (string, error)

读取 PIER_ISTR_HOVER_NAME:取自 ItemStackBase::getHoverName

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.EffectName

Go
func (i Item) EffectName() (string, error)

读取 PIER_ISTR_EFFECT_NAME:取自 ItemStackBase::getEffectName

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Item.Color

Go
func (i Item) Color() (string, error)

读取 PIER_ISTR_COLOR:SNBT {r,g,b},取自 ItemStackBase::getColor

  • 返回值类型:(string, error)
  • 对应槽位:item_get_str

Container

Go
1
2
3
type Container struct {
    Ref ContainerRef
}

一名玩家或一个方块的容器。

Container.Size

Go
func (c Container) Size() (int32, error)

格子的数量。

Container.Item

Go
func (c Container) Item(slot int32) (Item, error)

某一格里的物品。

  • 参数:
    • slot : int32
  • 返回值类型:(Item, error)
  • 对应槽位:container_get_item

Container.SetItem

Go
func (c Container) SetItem(slot int32, item Item) error

把一个物品放进某一格。

  • 参数:
    • slot : int32
    • item : Item
  • 返回值类型:error
  • 对应槽位:container_set_item

Container.AddItem

Go
func (c Container) AddItem(item Item) error

把一个物品放进放得下的地方。

Container.RemoveItem

Go
func (c Container) RemoveItem(slot, count int32) error

从某一格移除 count 个物品。

Container.Clear

Go
func (c Container) Clear() error

清空这个容器。

Container.Items

Go
func (c Container) Items() ([]SlotItem, error)

列出有东西的格子。

SlotItem

Go
1
2
3
4
type SlotItem struct {
    Slot int32
    SNBT string
}

容器里一个有东西的格子,以及以 SNBT 表示的物品。

ContainerRef

Go
1
2
3
4
5
6
type ContainerRef struct {
    Which   int32
    Player  PlayerSel
    Dim     int32
    X, Y, Z int32
}

指定一个容器:玩家的物品栏、末影箱、盔甲栏或副手,或者一个方块的容器。

IProp*

名称 值 说明
IPropCount 0 即 PIER_IPROP_COUNT:取自 ItemStackBase::mCount
IPropMaxStackSize 1 即 PIER_IPROP_MAX_STACK_SIZE:取自 ItemStackBase::getMaxStackSize
IPropAuxValue 2 即 PIER_IPROP_AUX_VALUE:取自 ItemStackBase::getAuxValue
IPropId 3 即 PIER_IPROP_ID:取自 ItemStackBase::getId
IPropDamage 4 即 PIER_IPROP_DAMAGE:取自 ItemStackBase::getDamageValue
IPropIsNull 5 即 PIER_IPROP_IS_NULL:取自 ItemStackBase::isNull
IPropIsBlock 6 即 PIER_IPROP_IS_BLOCK:取自 ItemStackBase::isBlock
IPropIsEnchanted 7 即 PIER_IPROP_IS_ENCHANTED:取自 ItemStackBase::isEnchanted
IPropIsArmor 8 即 PIER_IPROP_IS_ARMOR:取自 ItemStackBase::isArmorItem
IPropIsDamageable 9 即 PIER_IPROP_IS_DAMAGEABLE:取自 ItemStackBase::isDamageableItem
IPropIsDamaged 10 即 PIER_IPROP_IS_DAMAGED:取自 ItemStackBase::isDamaged
IPropMaxDamage 11 即 PIER_IPROP_MAX_DAMAGE:取自 ItemStackBase::getMaxDamage
IPropIsUnbreakable 12 即 PIER_IPROP_IS_UNBREAKABLE:取自 ItemStackBase::isUnbreakable
IPropHasDurability 13 即 PIER_IPROP_HAS_DURABILITY:取自 ItemStackBase::hasDurability
IPropIsPotion 14 即 PIER_IPROP_IS_POTION:取自 ItemStackBase::isPotionItem
IPropIsThrowable 15 即 PIER_IPROP_IS_THROWABLE:取自 ItemStackBase::isThrowable
IPropIsFireResistant 16 即 PIER_IPROP_IS_FIRE_RESISTANT:取自 ItemStackBase::isFireResistant
IPropAttackDamage 17 即 PIER_IPROP_ATTACK_DAMAGE:取自 ItemStackBase::getAttackDamage
IPropRepairCost 18 即 PIER_IPROP_REPAIR_COST:取自 ItemStackBase::getBaseRepairCost
IPropEnchantValue 19 即 PIER_IPROP_ENCHANT_VALUE:取自 ItemStackBase::getEnchantValue
IPropIsStackable 20 即 PIER_IPROP_IS_STACKABLE:取自 ItemStackBase::isStackable
IPropIsMusicDisc 21 即 PIER_IPROP_IS_MUSIC_DISC:取自 ItemStackBase::isMusicDiscItem
IPropIsOffhand 22 即 PIER_IPROP_IS_OFFHAND:取自 ItemStackBase::isOffhandItem
IPropUseDuration 23 即 PIER_IPROP_USE_DURATION:取自 ItemStackBase::getMaxUseDuration
IPropIsGlint 24 即 PIER_IPROP_IS_GLINT:取自 ItemStackBase::isGlint
IPropIsBundle 25 即 PIER_IPROP_IS_BUNDLE:取自 ItemStackBase::isBundle
IPropHasUserData 26 即 PIER_IPROP_HAS_USER_DATA:取自 ItemStackBase::hasUserData
IPropHasCustomName 27 即 PIER_IPROP_HAS_CUSTOM_NAME:取自 ItemStackBase::hasCustomHoverName

IStr*

名称 值 说明
IStrTypeName 0 即 PIER_ISTR_TYPE_NAME:取自 ItemStackBase::getTypeName(形如 "minecraft:apple")
IStrName 1 即 PIER_ISTR_NAME:取自 ItemStackBase::getName(显示名)
IStrCustomName 2 即 PIER_ISTR_CUSTOM_NAME:取自 ItemStackBase::getCustomName
IStrRawNameId 3 即 PIER_ISTR_RAW_NAME_ID:取自 ItemStackBase::getRawNameId
IStrLore 4 即 PIER_ISTR_LORE:SNBT 列表 ["l1","l2"],取自 ItemStackBase::getCustomLore
IStrCanDestroy 5 即 PIER_ISTR_CAN_DESTROY:SNBT 列表 ["minecraft:stone",…]
IStrCanPlaceOn 6 即 PIER_ISTR_CAN_PLACE_ON:SNBT 列表
IStrUserData 7 即 PIER_ISTR_USER_DATA:完整的 NBT 用户数据,以 SNBT 表示
IStrHoverName 8 即 PIER_ISTR_HOVER_NAME:取自 ItemStackBase::getHoverName
IStrEffectName 9 即 PIER_ISTR_EFFECT_NAME:取自 ItemStackBase::getEffectName
IStrColor 10 即 PIER_ISTR_COLOR:SNBT {r,g,b},取自 ItemStackBase::getColor

Container*

ContainerRef.Which 的取值。

名称 值 说明
ContainerInventory 0
ContainerEnderChest 1
ContainerArmor 2
ContainerOffhand 3
ContainerBlock 4