User Tools

Site Tools


tutorial:biomecoloring

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:biomecoloring [2019/02/19 14:20] – ↷ Page name changed from tutorial:biomecolouring to tutorial:biomecoloring mcrafterzztutorial:biomecoloring [2019/05/28 18:43] – mapping changes draylar
Line 1: Line 1:
 ====== Block Biome Coloring ====== ====== Block Biome Coloring ======
-In this tutorial we will show how to make blocks get affected by the biome colour similar to leaves and grassIt's very important that it's done on client side in //onInitializeClient// as it otherwise will cause crash. To register custom block colouring use //ColorProviderRegistry.BLOCK.register// and for items //ColorProviderRegistry.ITEM.register//. The color could be any but in this tutorial the grass biome color will be the one used.+In this tutorialwe'll look at adding biome-dependent colors to new blocks. To start, you'll need block with model that accounts for tintindexTo see an example of this, view the base leaves or grass_block model file
  
-   public class ExampleModClient implements ClientModInitializer { +Remember to keep visual-related logic client-side, (//onInitializeClient//or it will crash on a server. To register a custom block coloring, use //ColorProviderRegistry.BLOCK.register//and for itemsuse //ColorProviderRegistry.ITEM.register//In this tutorial, the grass biome color will be the one usedReplace the final argument by passing in your block.
-      @Override +
-      public void onInitializeClient(+
-         ColorProviderRegistry.BLOCK.register((blockposworld, layer) -> { +
-         BlockColorMapper provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS); +
-         return provider == null ? -1 : provider.getColor(block, pos, world, layer); +
-         }, block); +
-      } +
-   }+
  
-So what's happening here? Well, the register method wants a color returned and in this case that color is taken from the grass block, using the method's parameters block, pos, world and layer. Colouring an item is very similarLike blocks the returned color could be any //Color.black// for example but we will show how to get the default grass color.+<code java [enable_line_numbers="true"]> 
 +public class ExampleModClient implements ClientModInitializer { 
 +    @Override 
 +    public void onInitializeClient() { 
 +        ColorProviderRegistry.BLOCK.register((block, pos, worldlayer) -> { 
 +            BlockColorProvider provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS); 
 +            return provider == null ? -1 : provider.getColor(block, pos, world, layer); 
 +        }, YOUR_BLOCK_INSTANCE); 
 +    } 
 +
 +</code>
  
-   public class ExampleModClient implements ClientModInitializer { +So, what's happening here? The register method wants a color returnedand in this case, that color is taken from the grass blockColoring an item is very similarLike blocksthe returned color could be anyand also remember to replace the final argument with an instance of your item.
-      @Override +
-      public void onInitializeClient() { +
-         ColorProviderRegistry.ITEM.register((itemlayer) -> { +
-         return GrassColorHandler.getColor(0.5D1D); +
-         }block.getItem()); +
-      } +
-   }+
  
-0.5D is the temperature and 1D is the humidity of the biome.+<code java [enable_line_numbers="true"]> 
 +public class ExampleModClient implements ClientModInitializer { 
 +    @Override 
 +    public void onInitializeClient() { 
 +        ColorProviderRegistry.ITEM.register((item, layer) -> { 
 +            // These values are represented as temperature and humidity, and used as coordinates for the color map 
 +            double temperature = 0.5D; // a double value between 0 and 1 
 +            double humidity = 1.0D; // a double value between 0 and 1 
 +            return GrassColorHandler.getColor(temperature, humidity); 
 +        }, YOUR_ITEM_INSTANCE); 
 +    } 
 +
 +</code>
  
 +Finished!