User Tools

Site Tools


tutorial:a_new_page

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revisionBoth sides next revision
tutorial:a_new_page [2021/03/05 18:47] – created oroarmortutorial:a_new_page [2022/08/17 21:43] – removed clomclem
Line 1: Line 1:
-====== Model Predicate Providers ======= 
- 
-==== Introduction ==== 
- 
-Model providers are used to dynamically change the model of items based on data from ''ItemStack''s. A common example is the bow, which has different textures based on how long the bow has been pulled. All providers are then used in the model file for the item, in the ''overrides'' section. 
- 
-==== Practical Example ==== 
- 
-For this example, let's say we have we have a custom bow item called ''EXAMPLE_BOW''. 
- 
-<code java [enable_line_numbers="true"]> 
- 
-FabricModelPredicateProviderRegistry.register(EXAMPLE_BOW, new Identifier("pull"), (itemStack, clientWorld, livingEntity) -> { 
- if (livingEntity == null) { 
- return 0.0F; 
- } 
- return livingEntity.getActiveItem() != itemStack ? 0.0F : (itemStack.getMaxUseTime() - livingEntity.getItemUseTimeLeft()) / 20.0F; 
-}); 
- 
-FabricModelPredicateProviderRegistry.register(EXAMPLE_BOW, new Identifier("pulling"), (itemStack, clientWorld, livingEntity) -> { 
- if (livingEntity == null) { 
- return 0.0F; 
- } 
- return livingEntity.isUsingItem() && livingEntity.getActiveItem() == itemStack ? 1.0F : 0.0F; 
-}); 
-</code> 
  
tutorial/a_new_page.txt · Last modified: 2022/12/16 06:55 by daomephsta