tutorial:biomecoloring
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:biomecoloring [2019/03/25 03:19] – clarification on block model tintindex draylar | tutorial:biomecoloring [2019/05/26 16:21] – Code highlighting jamieswhiteshirt | ||
---|---|---|---|
Line 2: | Line 2: | ||
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. | 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, | + | Remember to keep visual-related logic client-side, |
- | public class ExampleModClient implements ClientModInitializer { | + | <code java [enable_line_numbers=" |
- | @Override | + | public class ExampleModClient implements ClientModInitializer { |
- | public void onInitializeClient() { | + | @Override |
- | | + | public void onInitializeClient() { |
- | | + | ColorProviderRegistry.BLOCK.register((block, |
- | | + | BlockColorMapper provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS); |
- | | + | return provider == null ? -1 : provider.getColor(block, |
- | } | + | }, YOUR_BLOCK_INSTANCE); |
- | | + | } |
+ | } | ||
+ | </ | ||
- | 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. | + | 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 |
- | public class ExampleModClient implements ClientModInitializer { | + | <code java [enable_line_numbers=" |
- | @Override | + | public class ExampleModClient implements ClientModInitializer { |
- | public void onInitializeClient() { | + | @Override |
- | | + | public void onInitializeClient() { |
- | | + | ColorProviderRegistry.ITEM.register((item, |
- | | + | // 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, |
- | } | + | }, YOUR_ITEM_INSTANCE); |
- | | + | } |
+ | } | ||
+ | </ | ||
Finished! | Finished! |