物品-ItemStack
包含了一系列关于物品的操作
参考链接:微软文档 ItemStack
获取物品对象的方法
构建物品对象
Details
通过类的实例化获取
ItemStack(itemType, amount?)
- itemType
- 物品类型
- 类型:str
- amount?
- 数量,默认为1
- 类型:int
item = ItemStack("minecraft:dirt", 1)
从容器对象获取
Details
通过容器相关接口获取
- container.getItem
item = world.getAllPlayers()[0].container.getItem(0)
从事件获取
Details
- itemUse
- itemUseOn
- ...
def ItemUse(arg):
item = arg.itemStack
world.afterEvents.itemUse.subscribe(ItemUse)
属性
typeId
- 只读 物品类型
- 类型:int
isStackable
- 只读 能否堆叠
- 类型:bool
type
- 只读 物品类型(用typeId就行,这个没啥用)
- 类型:ItemType
maxAmount
- 只读 物品最大堆叠数
- 类型:int
amount
- 数量
- 类型:int(必须大于零)
keepOnDeath?
- 死亡时是否保留,默认不保留
- 类型:bool
lockMode?
- 物品锁定模式,默认不锁定
- 类型:str
nameTag?
- 物品自定义名称,默认为空
- 类型:str
方法
getLore
获取物品lore(lore即类似物品附魔信息文本)
setLore
设置物品lore