tutorial:biomecoloring
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
tutorial:biomecoloring [2019/02/19 14:20] – ↷ Page name changed from tutorial:biomecolouring to tutorial:biomecoloring mcrafterzz | tutorial:biomecoloring [2019/10/25 17:41] – rework page draylar | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | In this tutorial we will show how to make blocks get affected by the biome colour similar | + | Ever wonder |
- | | + | === Existing Examples === |
- | | + | First, what existing vanilla content uses color providers? A few examples include: |
- | | + | * grass |
- | ColorProviderRegistry.BLOCK.register((block, | + | * leaves |
- | BlockColorMapper provider = ColorProviderRegistry.BLOCK.get(Blocks.GRASS); | + | * leather armor dying |
- | return provider == null ? -1 : provider.getColor(block, pos, world, layer); | + | * redstone wire |
- | }, block); | + | * plants such as melons, sugarcane, and lilypads |
- | } | + | * tipped arrows |
- | } | + | |
- | 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' | + | The color provider |
- | | + | The concept behind color providers is simple. You register a block or item to them, and when the block or item's model is rendered, the color provider applies a hue tweak to each layer of the texture. Both providers give you access to the layer of the model, which means you can hue each portion of a model separately, which is the case in leather armor & tipped arrows. This is useful for when you only want to change a few pixels, but not the entire texture. |
- | | + | |
- | | + | Remember that the color provider is a client-side mechanic. Make sure to put any code related to it inside a client initializer. |
- | | + | |
- | return GrassColorHandler.getColor(0.5D, 1D); | + | ==== Registering a Block Color Provider ==== |
- | | + | To register a block to the block color provider, you'll need to use Fabric' |
+ | <code java [enable_line_numbers=" | ||
+ | ColorProviderRegistry.BLOCK.register(new BlockColorProvider() { | ||
+ | | ||
+ | public int getColor(BlockState state, ExtendedBlockView world, BlockPos pos, int layer) { | ||
+ | return 0x3495eb; | ||
+ | } | ||
+ | }, MY_BLOCK); | ||
+ | </ | ||
+ | |||
+ | All we do here is say, "Hi, '' | ||
+ | |||
+ | The model is also important: the main note here is that you are // | ||
+ | <code json [enable_line_numbers=" | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | { " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
} | } | ||
- | } | + | |
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | In this instance, we're adding a single tintindex, which is what would appear in the `layer` parameter (layer 0). | ||
+ | |||
+ | Here's the final result-- note that the original model used the '' | ||
+ | {{https:// | ||
- | 0.5D is the temperature and 1D is the humidity of the biome. | ||