User Tools

Site Tools


tutorial:biomecoloring

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 a 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.

 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? 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.

 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.txt · Last modified: 2019/02/19 14:28 by mcrafterzz