User Tools

Site Tools


tutorial:biomecoloring

This is an old revision of the document!


Block Biome Coloring

In this tutorial, we will look at adding biome-dependent colors to new blocks. 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.

 public class ExampleModClient implements ClientModInitializer {
    @Override
    public void onInitializeClient() {
       ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> {
       BlockColorMapper provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS);
       return provider == null ? -1 : provider.getColor(block, pos, world, layer);
       }, block);
    }
 }

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, but we'll once again use grass blocks for the example.

 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);
       }, block.getItem());
    }
 }

Finished!

tutorial/biomecoloring.1553478329.txt.gz · Last modified: 2019/03/25 01:45 by draylar