tutorial:model_predicate_providers
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:model_predicate_providers [2021/03/05 19:11] – Add example 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 '' | + | 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; | ||
| + | }); | ||
| - | 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(); |
| - | }); | + | } |
| + | } | ||
| </ | </ | ||
| + | |||
| + | If the '' | ||
| The '' | The '' | ||
| - | All '' | + | All '' |
| - | Taking a closer look at the '' | + | Taking a closer look at the '' |
| 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. | 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. | ||
| - | <code json [enable_line_numbers=" | + | < |
| - | " | + | { |
| - | { | + | // [...] |
| - | " | + | " |
| - | " | + | { |
| - | }, | + | " |
| - | " | + | " |
| - | }, | + | }, |
| - | { | + | " |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| }, | }, | ||
| - | | + | { |
| - | }, | + | " |
| - | | + | " |
| - | " | + | " |
| - | " | + | }, |
| - | " | + | " |
| }, | }, | ||
| - | " | + | |
| - | } | + | " |
| - | ] | + | " |
| + | " | ||
| + | }, | ||
| + | | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| </ | </ | ||
| 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 '' | 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.1614971507.txt.gz · Last modified: 2021/03/05 19:11 by oroarmor