User Tools

Site Tools


Sidebar

Setup

Basics

Items and Item Groups

Blocks and Block Entities

Entities

World Generation

Miscellaneous

Advanced

Documentation

Examples


Fabric Сontributors

If you'd like to contribute to Fabric, you might be interested in these links:


Extremely Strange People


Wiki Meta

  • Wiki Meta - Starting point for contributing to the wiki
  • Wiki Agenda - See what is on the current agenda, and what other contributors are currently working on.
tutorial:biomecoloring

Block Biome Coloring

In this tutorial, we'll look at adding biome-dependent colors to new blocks. To start, you'll need a block with a model that accounts for tintindex. To see an example of this, view the base leaves or grass_block model file.

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.

  1. public class ExampleModClient implements ClientModInitializer {
  2. @Override
  3. public void onInitializeClient() {
  4. ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> {
  5. BlockColorProvider provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS);
  6. return provider == null ? -1 : provider.getColor(block, pos, world, layer);
  7. }, YOUR_BLOCK_INSTANCE);
  8. }
  9. }

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.

  1. public class ExampleModClient implements ClientModInitializer {
  2. @Override
  3. public void onInitializeClient() {
  4. ColorProviderRegistry.ITEM.register((item, layer) -> {
  5. // These values are represented as temperature and humidity, and used as coordinates for the color map
  6. double temperature = 0.5D; // a double value between 0 and 1
  7. double humidity = 1.0D; // a double value between 0 and 1
  8. return GrassColorHandler.getColor(temperature, humidity);
  9. }, YOUR_ITEM_INSTANCE);
  10. }
  11. }

Finished!

tutorial/biomecoloring.txt · Last modified: 2019/05/28 18:43 by draylar