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:27] mcrafterzztutorial:biomecoloring [2019/03/25 01:46] – block is not a reference usable 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 color similar to leaves and grass. It's very important that it's done on client side in //onInitializeClient// as it otherwise will cause crash. To register a custom block coloring 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 will look at adding biome-dependent colors to new blocks. Remember to keep visual-related logic client-side, (//onInitializeClient//) or it will crash on server. To register a custom block coloringuse //ColorProviderRegistry.BLOCK.register//and for items, use //ColorProviderRegistry.ITEM.register//In this tutorialthe grass biome color will be the one used.
  
    public class ExampleModClient implements ClientModInitializer {    public class ExampleModClient implements ClientModInitializer {
Line 8: Line 8:
          BlockColorMapper provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS);          BlockColorMapper provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS);
          return provider == null ? -1 : provider.getColor(block, pos, world, layer);          return provider == null ? -1 : provider.getColor(block, pos, world, layer);
-         }, block);+         }, Blocks.SPONGE);
       }       }
    }    }
  
-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. Coloring an item is very similar. Like blocks the returned color could be any //Color.black// for example but we will show how to get the default grass color.+Sowhat's happening here? The register method wants a color returnedand in this casethat color is taken from the grass block. Coloring an item is very similar. Like blocksthe returned color could be anybut we'll once again use grass blocks for the example.
  
    public class ExampleModClient implements ClientModInitializer {    public class ExampleModClient implements ClientModInitializer {
Line 18: Line 18:
       public void onInitializeClient() {       public void onInitializeClient() {
          ColorProviderRegistry.ITEM.register((item, layer) -> {          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 temperature = 0.5D; // a double value between 0 and 1
          double humidity = 1.0D; // a double value between 0 and 1          double humidity = 1.0D; // a double value between 0 and 1