恢复基于模式的模糊匹配物品模型。
目的
Custom Item Textures (CIT) 模组最初是 McPatcher 的一部分,后来成为 Optifine 的内置功能,允许替换其元数据与不精确模式匹配的物品的纹理(及模型)。如今,标准 Minecraft 已通过条件客户端物品类型实现了近乎等效的物品纹理替换功能,尽管不再支持不精确匹配。本模组通过正则表达式为新的标准条件物品定义系统添加了 CIT 替换功能。
兼容性与依赖项
- Minecraft: 1.21.8
- 加载器: Fabric 0.136.1
不需要 Fabric API。
安装
将模组 JAR 文件添加到你的 Fabric mods 文件夹中。
使用方法(玩家)
本模组为资源包设计师提供了一种可用于物品模型定义的功能。当模组安装后,该功能始终处于激活状态。
资源包集成(资源包作者)
位于 assets/minecraft/item 的 JSON 文件是物品定义(item definitions)。这些并不一定是用于渲染物品的模型文件(即物品模型),物品模型文件位于 assets/minecraft/models/item。
在物品定义文件中,“model”字段中的 JSON 对象决定了使用哪个模型文件来渲染物品。通常,单一类型的物品始终使用相同的模型进行渲染,因此该对象的“type”设置为 minecraft:model。但是,通过使用具有其他类型的“model”对象(如 minecraft:condition 和 minecraft:select),可以在不同上下文中对同一物品使用不同的模型。
本模组添加了 inexactcit:match 物品定义模型类型。它与内置的 select 类型类似,包含一个带有相关条件的模型列表,当一个条件匹配时,其关联的模型将被用于渲染物品。与 Select 不同,Match 的条件是可能不精确的正则表达式。
Match 物品定义模型使用与 Select 相同的字段,特别是 "property"、"component"、"cases" 和 "fallback"。
标签字段结构
{ "model":
{ "type": "inexactcit:match"
, "property": ... # 通常总是 minecraft:component
, "component": ... # 要定位的组件名称
, "cases":
[ { "regex": ... # 此情况的正则表达式
, "model": { ... } # 当正则表达式匹配时使用的物品定义模型
}
, ... # 另一个情况,如上所述
, ... # 任意数量的额外情况
]
, "fallback": { ... } # 当没有情况匹配时使用的物品定义模型
}
}
必需字段
正则表达式匹配旨在用于文本元数据,因此“property”字段应为 minecraft:component。当“property”不是 minecraft:component 时的行为尚未测试。
“component”字段应设置为将由条件测试的组件的命名空间 ID,例如 minecraft:lore 或 minecraft:custom_name。
“cases”字段必须包含一个 JSON 对象列表。每个对象应包含“regex”字段和相应的“model”字段。它们分别是(Java 风格的)正则表达式和物品定义模型。当正则表达式与“component”字段中命名的组件内容匹配时,相应的模型将用于该物品。
“fallback”字段提供了一个模型,当没有任何“case”对象匹配时使用,这与标准的 Select 相同。
示例
以下是一个 Match 物品定义的示例。它将所有名称中包含单词 “Quarterstaff” 的木锄替换为位于 pixelatedvolume:item/quarterstaff 的模型。
{ "model":
{ "type": "inexactcit:match"
, "property": "minecraft:component"
, "component": "minecraft:custom_name"
, "cases":
[ { "model":
{ "model": "pixelatedvolume:item/quarterstaff"
, "type": "minecraft:model"
}
, "regex": ".*Quarterstaff.*"
}
]
, "fallback":
{ "model": "minecraft:item/wooden_hoe"
, "type": "minecraft:model"
}
}
, "oversized_in_gui": true
}
文本比较
被检查字段的内容使用 toString 进行序列化。文本组件(JSON)特性、节码格式等都会推入此比较字符串中,因此无法得知在游戏内可见文本之前或之后可能出现什么,也无法得知多行组件各行之间发生了什么。
正则表达式或模型错误
如果物品定义文件包含格式错误的正则表达式,则无法读取,该物品将显示为默认模型(紫黑相间的立方体)。失败情况(包含故障文件)会在资源包加载时记录为 Error。
多个目标组件
要为单个物品提供使用不同组件的多个替换规则(例如一组规则用于 lore,另一组用于 custom_name),请将 fallback 模型设置为一个新的 Match 客户端物品模型,以选择第二个组件。
状态
最终将添加匹配除 minecraft:component 之外的属性的能力。目前,此类匹配会被接受且不会报错,但它们不会产生任何效果。
Restoring pattern-based conditional item models.
Purpose
The Custom Item Textures (CIT) mod, originally part of McPatcher and then
Optifine, allowed the replacement of item textures (and models) whose
metadata matched inexact patterns. We now have near-equivalent item-texture
replacement in standard Minecraft with conditional client item types, though
inexact matching is no longer possible. This mod adds CIT replacement with
regular expressions to the new standard conditional item definition system.
Compatibility and Dependencies
- Minecraft: 1.21.8
- Loader: Fabric 0.136.1
Fabric API not required.
Installation
Add the mod JAR to your Fabric mods folder.
Usage (Players)
This mod adds a feature to item model definitions which can be used by
resource pack designers. It is always active when the mod is installed.
Resource Pack Integration (Pack Authors)
The JSON files found at assets/minecraft/item are item definitions.
These are not necessarily the model file used to render an item (i.e. an
item model), which are found at assets/minecraft/models/item.
In an item definition file, the JSON object in the "model" field determines
which model file is used to render an item. Typically, a single item type is
always rendered with the same model, so this object has its "type" set to
minecraft:model. But different models can be used for the same item in
different contexts by using "model" objects with other types, such as
minecraft:condition and minecraft:select.
This mod adds the inexactcit:match item definition model type. It is
similar to the built-in select type in that it contains a list of models
with associated conditions, and when one condition matches, its associated
model is used to render the item. Unlike Select, the Match conditions are
potentially-inexact regular expressions.
Match item definition models use the same fields as Select, particularly
"property", "component", "cases", and "fallback".
Labeled Field Structure
{ "model":
{ "type": "inexactcit:match"
, "property": ... # Probably always minecraft:component
, "component": ... # Name of component to target
, "cases":
[ { "regex": ... # Regular expression for this case
, "model": { ... } # Item def'n. model used when regexp matches
}
, ... # Another case, as above
, ... # Any number of additional cases
]
, "fallback": { ... } # Item def'n. model used when no case matches
}
}
Required Fields
Regular expression matching is intended for text metadata, so the "property"
field will be minecraft:component. Behavior when "property" is not
minecraft:component is as yet untested.
The "component" field should be set to the namespaced ID for the component
that will be tested by the condition, e.g. minecraft:lore,
minecraft:custom_name.
The "cases" field must contain a list of JSON objects. Each object is to
contain a "regex" field and corresponding "model" field. These must be a
(Java-flavored) regular expression and an item definition model, respectively.
When the regular expression matches against the contents of the component
named in the "component" field, the corresponding model is used for that item.
The "fallback" field gives a model that is used when none of the "case"
objects match, same as the standard Select.
Example
The following is an example of a Match item definition. It replaces all
wooden hoes whose names include the word "Quarterstaff" with the model at
pixelatedvolume:item/quarterstaff.
{ "model":
{ "type": "inexactcit:match"
, "property": "minecraft:component"
, "component": "minecraft:custom_name"
, "cases":
[ { "model":
{ "model": "pixelatedvolume:item/quarterstaff"
, "type": "minecraft:model"
}
, "regex": ".*Quarterstaff.*"
}
]
, "fallback":
{ "model": "minecraft:item/wooden_hoe"
, "type": "minecraft:model"
}
}
, "oversized_in_gui": true
}
Text Comparison
The contents of the field being examined is serialized with toString.
Text-component (JSON) features, section-code formatting, etc, is all pushed
into this comparison string, so there is no way of telling what might come
before or after the text that is visible in-game, or what happens between
lines of multiline compontents.
Regular Expression or Model Errors
An item definition file with a malformed regular expression cannot be read
so the item will appear with the default model (margenta-and-black cube).
The failure (with the faulty file) is logged as an Error at pack-load time.
Multiple Target Components
To give one item multiple replacement rules that use different components
(e.g. one set of rules for lore and one set for custom_name), set the
fallback model to a new Match client item model that selects the second
component.
Status
The ability to match properties other than minecraft:component will be added
eventually. Currently, such matches are accepted without error, but they have
no effect.
评论 0
登录后参与评分
还没有评论,来抢沙发吧