zh_cn:tutorial:colorprovider
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
zh_cn:tutorial:colorprovider [2019/12/19 05:39] – created lightcolour | zh_cn:tutorial:colorprovider [2022/03/29 13:23] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | Ever wonder how grass and leaves change hues depending on the biome, or how leather armor can have seemingly infinite color patterns? Meet color providers, which allow you to hue and tint block & item model textures based on properties such as location, NBT, or block states. | + | |
- | === Existing Examples === | + | 有没有想过,草和树叶如何根据生物群系(biome)而改变色调,或者皮革盔甲如何具有看似无限的颜色模式?答案是颜色提供器,这个可以允许你根据位置、NBT、方块状态等属性为方块或物品的模型纹理设置色调或者着色。 |
- | First, what existing vanilla content uses color providers? A few examples include: | + | |
- | * grass | + | |
- | * leaves | + | |
- | * leather armor dying | + | |
- | * redstone wire | + | |
- | * plants such as melons, sugarcane, and lilypads | + | |
- | * tipped arrows | + | |
- | The color provider is powerful, but Mojang has opted to stick with individual textures for colored blocks such as concrete, wool, and glass. The primary use case at this point is for biome shaded blocks and small tweaks to existing textures, such as the colored end of a tipped arrow. | + | === 现有例子 === |
+ | 首先,现有的哪些原版内容使用颜色提供器?一些示例包括: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
- | The concept behind color providers is simple. You register a block or item to them, and when the block or item's model is rendered, the color provider applies a hue tweak to each layer of the texture. Both providers give you access to the layer of the model, which means you can hue each portion of a model separately, which is the case in leather armor & tipped arrows. This is useful for when you only want to change a few pixels, but not the entire texture. | + | 颜色提供器功能强大,但是Mojang选择对混凝土、羊毛和玻璃等有色方块坚持使用单独的纹理。此时的主要用例是针对受生物群系的方块,以及对现有纹理的细微调整,例如药箭的彩色末端。 |
- | Remember that the color provider is a client-side mechanic. Make sure to put any code related to it inside a client initializer. | + | 颜色提供器背后的概念很简单。你为之注册方块和物品,并在渲染该方块或物品的模型时,颜色提供器对纹理的每一层应用色调调整。两个提供器都可以访问模型的层,这意味着您可以分别对模型的每个部分进行色调设置,皮革盔甲和药箭就是这种情况。当您只想更改几个像素而不是整个纹理时,这很有用。 |
- | ===== Registering a Block Color Provider | + | 请记住,颜色提供器是客户端机制。确保将与其相关的所有代码放入客户端初始化器中。 |
- | To register a block to the block color provider, you'll need to use Fabric' | + | ===== 注册方块颜色提供器 |
+ | 要将方块注册到方块颜色提供器,您需要使用 | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | ColorProviderRegistry.BLOCK.register(new BlockColorProvider() { | + | ColorProviderRegistry.BLOCK.register((state, |
- | @Override | + | |
- | public int getColor(BlockState | + | |
- | return | + | |
- | } | + | |
- | }, MY_BLOCK); | + | |
</ | </ | ||
- | All we do here is say, "Hi, '' | + | 我们在这里所做的只是说:“Hi,'' |
- | The model is also important: the main note here is that you are //required// to define a tintindex | + | 如果你需要在颜色提供器中访问 '' |
- | < | + | |
+ | 模型也重要的:这里需要注意的是,你//一定要//为模型的每一个你需要着色的部分定义tintindex。如要查看这个的例子,请参考 | ||
+ | < | ||
{ | { | ||
" | " | ||
Line 39: | Line 36: | ||
}, | }, | ||
" | " | ||
- | { | + | { " |
" | " | ||
" | " | ||
Line 53: | Line 50: | ||
} | } | ||
</ | </ | ||
- | In this instance, we're adding a single | + | 在这种情况下,我们添加了一个单一的 |
- | Here's the final result-- note that the original model used the '' | + | 这是最终结果——请注意,原始模型使用了 |
{{https:// | {{https:// | ||
- | ===== Registering an Item Color Provider | + | ===== 注册物品颜色提供器 |
- | Items are similar; the difference is the context provided. Instead of having a state, world, or position, you have access to the '' | + | 物品是类似的,区别在于提供的上下文。不访问状态、世界和位置,而是访问 |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
ColorProviderRegistry.ITEM.register((itemStack, | ColorProviderRegistry.ITEM.register((itemStack, | ||
Line 65: | Line 62: | ||
}, COLORED_ITEM); | }, COLORED_ITEM); | ||
</ | </ | ||
- | This would hue the item in our inventory in the same fashion as the block. | ||
- | === Limitations | + | 这会以像方块那样的方法为你物品栏中的物品提供色相。 |
- | One key issue with using the color provider is the lack of context in the item provider. This is why vanilla grass doesn' | + | |
+ | === 限制 | ||
+ | 使用颜色提供器的一个关键问题是物品的提供器中缺少上下文。这就是为什么原版草不会根据您站立的位置改变物品栏中的颜色的原因。为了实现诸如方块的颜色变体(混凝土、玻璃、羊毛等)之类的东西,建议您为每个版本简单地提供单独的纹理。 |
zh_cn/tutorial/colorprovider.txt · Last modified: 2023/11/18 08:37 by solidblock