User Tools

Site Tools


Sidebar

Setup

Basics

Advanced

Items

Blocks and Block Entities

Fluids

Entities

World Generation

Recipe Types

Miscellaneous

Events

Mixins

Dynamic Data Generation

Tutorials for Minecraft 1.15

Tutorials for Minecraft 1.14

Documentation

tutorial:a_new_page

Model Predicate Providers

Introduction

Model providers are used to dynamically change the model of items based on data from ItemStacks. 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.

  1. FabricModelPredicateProviderRegistry.register(EXAMPLE_BOW, new Identifier("pull"), (itemStack, clientWorld, livingEntity) -> {
  2. if (livingEntity == null) {
  3. return 0.0F;
  4. }
  5. return livingEntity.getActiveItem() != itemStack ? 0.0F : (itemStack.getMaxUseTime() - livingEntity.getItemUseTimeLeft()) / 20.0F;
  6. });
  7.  
  8. FabricModelPredicateProviderRegistry.register(EXAMPLE_BOW, new Identifier("pulling"), (itemStack, clientWorld, livingEntity) -> {
  9. if (livingEntity == null) {
  10. return 0.0F;
  11. }
  12. return livingEntity.isUsingItem() && livingEntity.getActiveItem() == itemStack ? 1.0F : 0.0F;
  13. });
tutorial/a_new_page.txt · Last modified: 2021/03/05 18:47 by oroarmor