zh_cn:tutorial:model_predicate_providers
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
zh_cn:tutorial:model_predicate_providers [2021/07/25 01:55] – created solidblock | zh_cn:tutorial:model_predicate_providers [2024/08/23 14:05] (current) – 更新翻译 solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 模型谓词提供器 ======= | ====== 模型谓词提供器 ======= | ||
- | ==== 介绍 ==== | + | ===== 介绍 |
- | 模型谓词提供器用于动态改变Model providers are used to dynamically change the model of items based on data from '' | + | 模型谓词提供器用于给予 |
- | ==== 可行示例 ==== | + | ===== 可行示例 |
- | 在此例中,我们假定有了自定义的弓,叫做'' | + | 在此例中,我们假定有了自定义的弓,叫做 '' |
- | 在其方法中,使用其物品和一个'' | + | 在其方法中,使用其物品和一个 '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
+ | @Environment(EnvType.CLIENT) | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | public static void registerModelPredicateProviders() { | ||
+ | //对于 1.21 之前的版本,将 ' | ||
+ | ModelPredicateProviderRegistry.register(EXAMPLE_BOW, | ||
+ | if (livingEntity == null) { | ||
+ | return 0.0F; | ||
+ | } | ||
+ | return livingEntity.getActiveItem() != itemStack ? 0.0F : (itemStack.getMaxUseTime(livingEntity) - livingEntity.getItemUseTimeLeft()) / 20.0F; | ||
+ | }); | ||
- | FabricModelPredicateProviderRegistry.register(EXAMPLE_BOW, | + | ModelPredicateProviderRegistry.register(EXAMPLE_BOW, |
- | if (livingEntity == null) { | + | if (livingEntity == null) { |
- | return 0.0F; | + | return 0.0F; |
- | } | + | } |
- | return livingEntity.getActiveItem() | + | return |
- | }); | + | }); |
- | + | } | |
- | FabricModelPredicateProviderRegistry.register(EXAMPLE_BOW, | + | |
- | if (livingEntity == null) { | + | |
- | return 0.0F; | + | public void onInitializeClient() { |
- | } | + | // |
- | return livingEntity.isUsingItem() && livingEntity.getActiveItem() == itemStack ? 1.0F : 0.0F; | + | registerModelPredicateProviders(); |
- | }); | + | } |
+ | } | ||
</ | </ | ||
- | '' | + | 如果 |
- | 所有的'' | + | '' |
- | 仔细看看'' | + | 所有的 '' |
+ | |||
+ | 仔细看看 '' | ||
所有这些都是有用的,但为了让我们的物品改变其模型,我们只需要实现其一部分的特性。 | 所有这些都是有用的,但为了让我们的物品改变其模型,我们只需要实现其一部分的特性。 | ||
- | <code json [enable_line_numbers=" | + | < |
- | " | + | { |
- | { | + | // [...] |
- | " | + | " |
- | " | + | { |
- | }, | + | " |
- | " | + | " |
- | }, | + | }, |
- | { | + | " |
- | " | + | |
- | " | + | |
- | " | + | |
}, | }, | ||
- | | + | { |
- | }, | + | " |
- | | + | " |
- | " | + | " |
- | " | + | }, |
- | " | + | " |
}, | }, | ||
- | " | + | |
- | } | + | " |
- | ] | + | " |
+ | " | ||
+ | }, | ||
+ | | ||
+ | } | ||
+ | ] | ||
+ | } | ||
</ | </ | ||
- | Minecraft运作的方式是,在指定的值中,检查模型大于等于的值的最后一个值。所以拉伸值为'' | + | Minecraft 运作的方式是,在指定的值中,检查模型大于等于的值的最后一个值。所以拉伸值为 '' |
zh_cn/tutorial/model_predicate_providers.1627178123.txt.gz · Last modified: 2021/07/25 01:55 by solidblock