tutorial:model_predicate_providers
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorial:model_predicate_providers [2021/03/05 18:49] – created oroarmor | tutorial:model_predicate_providers [2025/04/02 04:20] (current) – [Model Predicate Providers (before 1.21.5)] solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Model Predicate Providers ======= | + | ====== Model Predicate Providers |
- | ==== Introduction ==== | + | :!: Model predicate providers are removed since 1.21.4. Since 1.21.4, please use items model definition instead. See [[https:// |
+ | |||
+ | ===== Introduction | ||
Model providers are used to dynamically change the model of items based on data from '' | Model providers are used to dynamically change the model of items based on data from '' | ||
- | ==== Practical Example ==== | + | ===== Practical Example |
- | For this example, | + | For this example, |
+ | |||
+ | Inside a method, we register a '' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
+ | @Environment(EnvType.CLIENT) | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | public static void registerModelPredicateProviders() { | ||
+ | // For versions before 1.21, replace ' | ||
+ | ModelPredicateProviderRegistry.register(EXAMPLE_BOW, | ||
+ | if (livingEntity == null) { | ||
+ | return 0.0F; | ||
+ | } | ||
+ | return livingEntity.getActiveItem() != itemStack ? 0.0F : (itemStack.getMaxUseTime(livingEntity) - livingEntity.getItemUseTimeLeft()) / 20.0F; | ||
+ | }); | ||
+ | |||
+ | ModelPredicateProviderRegistry.register(EXAMPLE_BOW, | ||
+ | if (livingEntity == null) { | ||
+ | return 0.0F; | ||
+ | } | ||
+ | return livingEntity.isUsingItem() && livingEntity.getActiveItem() == itemStack ? 1.0F : 0.0F; | ||
+ | }); | ||
+ | } | ||
+ | | ||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | // ... | ||
+ | registerModelPredicateProviders(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | If the '' | ||
+ | |||
+ | The '' | ||
+ | |||
+ | All '' | ||
+ | |||
+ | Taking a closer look at the '' | ||
- | FabricModelPredicateProviderRegistry.register(EXAMPLE_BOW, new Identifier(" | + | All of this is useful, but is only half of the features we need to implement in order to have our item change its model. |
- | if (livingEntity == null) { | + | |
- | return 0.0F; | + | |
- | } | + | |
- | return livingEntity.getActiveItem() != itemStack ? 0.0F : (itemStack.getMaxUseTime() - livingEntity.getItemUseTimeLeft()) / 20.0F; | + | |
- | }); | + | |
- | FabricModelPredicateProviderRegistry.register(EXAMPLE_BOW, | + | <code javascript resources/ |
- | if (livingEntity == null) { | + | { |
- | return | + | // [...] |
- | } | + | " |
- | return livingEntity.isUsingItem() && livingEntity.getActiveItem() == itemStack ? 1.0F : 0.0F; | + | { |
- | }); | + | " |
+ | | ||
+ | }, | ||
+ | " | ||
+ | }, | ||
+ | | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
</ | </ | ||
+ | The way that Minecraft works is that it checks to see which model is last in the list that either matches or has values greater than specified. so with a pull value of '' |
tutorial/model_predicate_providers.1614970189.txt.gz · Last modified: 2021/03/05 18:49 by oroarmor