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 revisionBoth sides next revision
tutorial:biomecoloring [2019/03/25 03:22] draylartutorial:biomecoloring [2019/05/26 16:21] – Code highlighting jamieswhiteshirt
Line 4: Line 4:
 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 items, use //ColorProviderRegistry.ITEM.register//. In this tutorial, the grass biome color will be the one used. Replace the final argument by passing in your block. 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 items, use //ColorProviderRegistry.ITEM.register//. In this tutorial, the grass biome color will be the one used. Replace the final argument by passing in your block.
  
-   public class ExampleModClient implements ClientModInitializer { +<code java [enable_line_numbers="true"]> 
-      @Override +public class ExampleModClient implements ClientModInitializer { 
-      public void onInitializeClient() { +    @Override 
-         ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> { +    public void onInitializeClient() { 
-         BlockColorMapper provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS); +        ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> { 
-         return provider == null ? -1 : provider.getColor(block, pos, world, layer); +            BlockColorMapper provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS); 
-         }, YOUR_BLOCK_INSTANCE); +            return provider == null ? -1 : provider.getColor(block, pos, world, layer); 
-      +        }, YOUR_BLOCK_INSTANCE); 
-   }+    
 +} 
 +</code>
  
 So, what's happening here? The register method wants a color returned, and in this case, that color is taken from the grass block. Coloring an item is very similar. Like blocks, the returned color could be any, and also remember to replace the final argument with an instance of your item. So, what's happening here? The register method wants a color returned, and in this case, that color is taken from the grass block. Coloring an item is very similar. Like blocks, the returned color could be any, and also remember to replace the final argument with an instance of your item.
  
-   public class ExampleModClient implements ClientModInitializer { +<code java [enable_line_numbers="true"]> 
-      @Override +public class ExampleModClient implements ClientModInitializer { 
-      public void onInitializeClient() { +    @Override 
-         ColorProviderRegistry.ITEM.register((item, layer) -> { +    public void onInitializeClient() { 
-         // These values are represented as temperature and humidity, and used as coordinates for the color map +        ColorProviderRegistry.ITEM.register((item, layer) -> { 
-         double temperature = 0.5D; // a double value between 0 and 1 +            // These values are represented as temperature and humidity, and used as coordinates for the color map 
-         double humidity = 1.0D; // a double value between 0 and 1 +            double temperature = 0.5D; // a double value between 0 and 1 
-         return GrassColorHandler.getColor(temperature, humidity); +            double humidity = 1.0D; // a double value between 0 and 1 
-         }, YOUR_ITEM_INSTANCE); +            return GrassColorHandler.getColor(temperature, humidity); 
-      +        }, YOUR_ITEM_INSTANCE); 
-   }+    
 +} 
 +</code>
  
 Finished! Finished!