tutorial:colorprovider
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:colorprovider [2019/10/25 17:48] – draylar | tutorial:colorprovider [2023/11/18 08:37] (current) – [Registering a Block Color Provider] solidblock | ||
---|---|---|---|
Line 8: | Line 8: | ||
* leather armor dying | * leather armor dying | ||
* redstone wire | * redstone wire | ||
- | * plants such as melons, sugarcane, and lilypads | + | * plants such as melons, sugarcane, and lily pads |
* tipped arrows | * tipped arrows | ||
Line 20: | Line 20: | ||
To register a block to the block color provider, you'll need to use Fabric' | To register a block to the block color provider, you'll need to use Fabric' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | ColorProviderRegistry.BLOCK.register(new BlockColorProvider() { | + | ColorProviderRegistry.BLOCK.register((state, |
- | @Override | + | |
- | public int getColor(BlockState | + | |
- | return | + | |
- | } | + | |
- | }, MY_BLOCK); | + | |
</ | </ | ||
- | All we do here is say, "Hi, '' | + | All we do here is say, "Hi, '' |
+ | |||
+ | If you need to access '' | ||
The model is also important: the main note here is that you are // | The model is also important: the main note here is that you are // | ||
- | < | + | < |
{ | { | ||
" | " | ||
Line 39: | Line 36: | ||
}, | }, | ||
" | " | ||
- | { | + | { " |
" | " | ||
" | " | ||
Line 53: | Line 50: | ||
} | } | ||
</ | </ | ||
- | In this instance, we're adding a single tintindex, which is what would appear in the `layer` | + | In this instance, we're adding a single tintindex, which is what would appear in the '' |
Here's the final result-- note that the original model used the '' | Here's the final result-- note that the original model used the '' | ||
Line 61: | Line 58: | ||
Items are similar; the difference is the context provided. Instead of having a state, world, or position, you have access to the '' | Items are similar; the difference is the context provided. Instead of having a state, world, or position, you have access to the '' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | ColorProviderRegistry.ITEM.register((itemStack, layer) -> { | + | ColorProviderRegistry.ITEM.register((stack, tintIndex) -> 0x3495eb, COLORED_ITEM); |
- | return | + | |
- | }, COLORED_ITEM); | + | |
</ | </ | ||
This would hue the item in our inventory in the same fashion as the block. | This would hue the item in our inventory in the same fashion as the block. |
tutorial/colorprovider.1572025696.txt.gz · Last modified: 2019/10/25 17:48 by draylar