User Tools

Site Tools


tutorial:colorprovider

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:colorprovider [2019/10/25 17:43] – created draylartutorial:colorprovider [2019/10/25 17:48] draylar
Line 17: Line 17:
 Remember that the color provider is a client-side mechanic. Make sure to put any code related to it inside a client initializer. Remember that the color provider is a client-side mechanic. Make sure to put any code related to it inside a client initializer.
  
-==== Registering a Block Color Provider ====+===== Registering a Block Color Provider =====
 To register a block to the block color provider, you'll need to use Fabric's ''ColorProviderRegistry''. There is an instance of the ''BLOCK'' and ''ITEM'' provider inside this class, which you can call register on. The register method takes an instance of your color provider and a varargs of every block you want to color with the provider.  To register a block to the block color provider, you'll need to use Fabric's ''ColorProviderRegistry''. There is an instance of the ''BLOCK'' and ''ITEM'' provider inside this class, which you can call register on. The register method takes an instance of your color provider and a varargs of every block you want to color with the provider. 
-<code java [enable_line_numbers="true"]>+<code java [enable_line_numbers="false"]>
 ColorProviderRegistry.BLOCK.register(new BlockColorProvider() { ColorProviderRegistry.BLOCK.register(new BlockColorProvider() {
         @Override         @Override
Line 31: Line 31:
  
 The model is also important: the main note here is that you are //required// to define a tintindex for each portion of the model you want to hue. To see an example of this, check out ''leaves.json'', which is the base model used for vanilla leaves. Here's the model used for our block: The model is also important: the main note here is that you are //required// to define a tintindex for each portion of the model you want to hue. To see an example of this, check out ''leaves.json'', which is the base model used for vanilla leaves. Here's the model used for our block:
-<code json [enable_line_numbers="true"]>+<code json [enable_line_numbers="false"]>
 { {
   "parent": "block/block",   "parent": "block/block",
Line 57: Line 57:
 Here's the final result-- note that the original model used the ''white_concrete'' texture: Here's the final result-- note that the original model used the ''white_concrete'' texture:
 {{https://i.imgur.com/fZLS10g.png}} {{https://i.imgur.com/fZLS10g.png}}
 +
 +===== Registering an Item Color Provider =====
 +Items are similar; the difference is the context provided. Instead of having a state, world, or position, you have access to the ''ItemStack''.
 +<code java [enable_line_numbers="false"]>
 +ColorProviderRegistry.ITEM.register((itemStack, layer) -> {
 + return 0x3495eb;
 +}, COLORED_ITEM);
 +</code>
 +This would hue the item in our inventory in the same fashion as the block.
 +
 +=== Limitations ===
 +One key issue with using the color provider is the lack of context in the item provider. This is why vanilla grass doesn't change colors in your inventory depending on where you stand. For implementing things such as color variants of blocks (concrete, glass, wool, etc.), you're encouraged to simply provide an individual texture for each version.
tutorial/colorprovider.txt · Last modified: 2023/11/18 08:37 by solidblock