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 [2024/08/04 07:44] – fix: use ClientModInitializer instead of ModInitializer l1ttle | 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 |
+ | |||
+ | :!: Model predicate providers are removed since 1.21.4. Since 1.21.4, please use items model definition instead. See [[https:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 7: | Line 9: | ||
===== 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 class ExampleModClient implements ClientModInitializer { | ||
public static void registerModelPredicateProviders() { | public static void registerModelPredicateProviders() { | ||
// For versions before 1.21, replace ' | // For versions before 1.21, replace ' | ||
- | ModelPredicateProviderRegistry.register(EXAMPLE_BOW, | + | ModelPredicateProviderRegistry.register(EXAMPLE_BOW, |
if (livingEntity == null) { | if (livingEntity == null) { | ||
return 0.0F; | return 0.0F; | ||
} | } | ||
- | return livingEntity.getActiveItem() != itemStack ? 0.0F : (itemStack.getMaxUseTime() - livingEntity.getItemUseTimeLeft()) / 20.0F; | + | return livingEntity.getActiveItem() != itemStack ? 0.0F : (itemStack.getMaxUseTime(livingEntity) - livingEntity.getItemUseTimeLeft()) / 20.0F; |
}); | }); | ||
- | ModelPredicateProviderRegistry.register(EXAMPLE_BOW, | + | ModelPredicateProviderRegistry.register(EXAMPLE_BOW, |
if (livingEntity == null) { | if (livingEntity == null) { | ||
return 0.0F; | return 0.0F; | ||
Line 44: | Line 47: | ||
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 javascript [enable_line_numbers=" | + | <code javascript |
- | " | + | { |
- | { | + | // [...] |
- | " | + | " |
- | " | + | { |
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
}, | }, | ||
- | | + | { |
- | }, | + | " |
- | | + | " |
- | " | + | " |
- | " | + | }, |
- | " | + | " |
}, | }, | ||
- | | + | { |
- | }, | + | " |
- | | + | " |
- | " | + | " |
- | " | + | }, |
- | " | + | " |
- | }, | + | } |
- | " | + | ] |
- | } | + | } |
- | ] | + | |
</ | </ | ||
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.1722757454.txt.gz · Last modified: 2024/08/04 07:44 by l1ttle