✅ 枚举条件型
简介
枚举条件型物品模型映射类型。此物品模型映射类型会先计算物品堆叠内给定的一个枚举属性,游戏会使用枚举属性值对应的物品模型映射。如果没有匹配的枚举值,则使用回落物品模型映射。
使用 minecraft:select
时,你需要指定一个枚举属性类型。cases
表示枚举值和对应的物品模型映射。枚举值不能重复出现,否则游戏将报错Duplicate case conditions: <重复的枚举值列表>
,而 fallback
则表示回落物品模型映射。如果读取结果不匹配任何一个枚举值,则使用此映射。如果此项不存在,且读取结果不匹配任何一个枚举值,则使用无效模型。
items:
default:select_item:
model:
type: "minecraft:select"
property: "minecraft:charge_type"
cases:
- when: arrow
model:
type: minecraft:model
path: "minecraft:item/custom/model_1"
- when: rocket
model:
type: minecraft:model
path: "minecraft:item/custom/model_2"
fallback:
type: minecraft:model
path: "minecraft:item/custom/model_3"
枚举属性
请查看 https://zh.minecraft.wiki/w/物品模型映射#select 以获取每个参数的解释。
minecraft:charge_type
弩内部包含的物品类型,检查物品堆叠的
charged_projectiles
组件 如果此组件为空或不存在,则为none
;如果组件内存在烟花火箭,则为rocket
;其他情况下为arrow
minecraft:context_dimension
当前玩家所在维度的命名空间ID
minecraft:context_entity_type
持有此物品堆叠的实体类型
minecraft:display_context
获取当前物品堆叠渲染位置,枚举值见模型 § 渲染变换
minecraft:main_hand
获取玩家的主手是左手(
left
)还是右手(right
);如果物品堆叠不在玩家身上,则为null,无法匹配
minecraft:trim_material
读取物品堆叠的
trim
组件并获取盔甲纹饰材料;如果物品堆叠无此组件则为null,无法匹配
minecraft:block_state
读取物品堆叠的
block_state
组件,并获取指定方块属性的值作为返回值。如果物品堆叠不存在此组件,或方块不具有对应方块属性,则返回null,无法匹配。
type: "minecraft:select"
property: "minecraft:block_state"
block-state-property: "facing"
minecraft:component (1.21.5+)
读取物品堆叠的可持久化组件数据,获取此组件的数据作为返回值。指定不可持久化的组件或枚举值不符合对应组件的数据要求时此模型映射会直接加载失败。 游戏会完全匹配物品模型映射指定的组件值和物品的组件值。例如,对于
custom_data
组件而言,{a:data,b:true}
和"{\"a\":\"data\",\"b\":true}"
最终都会被序列化为{"a":"data","b":true}
,因此这两种写法尽管形式不同,但会被视为相同的组件值:枚举值同时指定会被游戏警告重复的枚举值,物品数据定义和枚举值定义使用任何一种形式都被视为匹配成功。由于游戏会完全匹配,因此不能单独筛选组件中某个键值对的精确值,例如枚举值{"a":"data"}
不会匹配上述示例。
type: "minecraft:select"
property: "minecraft:component"
component: "minecraft:unbreakable"
minecraft:custom_model_data
读取物品堆叠的
custom_model_data
组件中的strings,获取指定下标的字符串。如果下标超过strings的长度范围,或物品堆叠不存在custom_model_data
组件,则返回null,无法匹配。
type: "minecraft:select"
property: "minecraft:custom_model_data"
index: 0
minecraft:local_time
读取当前时间,并根据指定时区、地区设置和日期格式获得日期字符串。此字符串每秒最多获取一次。
type: "minecraft:select"
property: "minecraft:local_time"
locale: "zh_CN"
time-zone: "GMT+8:00"
pattern: "HH:mm:ss"