tutorial:colorprovider
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:colorprovider [2024/08/27 03:13] – solidblock | tutorial:colorprovider [2025/12/05 17:03] (current) – redirect to docs cassiancc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ~~REDIRECT> | ||
| + | ~~REDIRECT> | ||
| ======= Color Providers ======= | ======= Color Providers ======= | ||
| Ever wonder how grass and leaves change hues depending on the biome, or how leather armor can have seemingly infinite color patterns? Meet **color providers**, | Ever wonder how grass and leaves change hues depending on the biome, or how leather armor can have seemingly infinite color patterns? Meet **color providers**, | ||
| Line 24: | Line 26: | ||
| public final class TutorialBlocks { | public final class TutorialBlocks { | ||
| [...] | [...] | ||
| + | // Before 1.21.2 | ||
| public static final Block COLOR_BLOCK = register(" | public static final Block COLOR_BLOCK = register(" | ||
| + | | ||
| + | // 1.21.2 and after: | ||
| + | public static final Block COLOR_BLOCK = register(" | ||
| } | } | ||
| </ | </ | ||
| Line 131: | Line 136: | ||
| } | } | ||
| + | // Since 1.21.4, this method is not required anymore, because all block entities use their block model by default. | ||
| @Override | @Override | ||
| protected BlockRenderType getRenderType(BlockState state) { | protected BlockRenderType getRenderType(BlockState state) { | ||
| Line 151: | Line 157: | ||
| protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { | protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { | ||
| super.readNbt(nbt, | super.readNbt(nbt, | ||
| + | | ||
| + | // For versions before 1.21.5, please directly use nbt.getInt(" | ||
| color = nbt.getInt(" | color = nbt.getInt(" | ||
| | | ||
| Line 188: | Line 196: | ||
| In the '' | In the '' | ||
| <code java> | <code java> | ||
| + | // Before 1.21.2: | ||
| public static final ColorBlock COLOR_BLOCK = register(" | public static final ColorBlock COLOR_BLOCK = register(" | ||
| + | | ||
| + | // Since 1.21.2: | ||
| + | public static final Block COLOR_BLOCK = register(" | ||
| </ | </ | ||
| Line 203: | Line 215: | ||
| | | ||
| @Override | @Override | ||
| - | protected | + | protected |
| if (stack.getItem() instanceof DyeItem dyeItem) { | if (stack.getItem() instanceof DyeItem dyeItem) { | ||
| if (world.getBlockEntity(pos) instanceof ColorBlockEntity colorBlockEntity) { | if (world.getBlockEntity(pos) instanceof ColorBlockEntity colorBlockEntity) { | ||
| final int newColor = dyeItem.getColor().getEntityColor(); | final int newColor = dyeItem.getColor().getEntityColor(); | ||
| final int originalColor = colorBlockEntity.color; | final int originalColor = colorBlockEntity.color; | ||
| - | colorBlockEntity.color = ColorHelper.Argb.averageArgb(newColor, originalColor); | + | colorBlockEntity.color = ColorHelper.average(newColor, originalColor); |
| stack.decrementUnlessCreative(1, | stack.decrementUnlessCreative(1, | ||
| colorBlockEntity.markDirty(); | colorBlockEntity.markDirty(); | ||
| Line 240: | Line 252: | ||
| * When you pick (press mouse wheel) the block with '' | * When you pick (press mouse wheel) the block with '' | ||
| * When you leave the world and re-enter, the color should be kept. | * When you leave the world and re-enter, the color should be kept. | ||
| - | ===== Item Color Provider | + | |
| - | Items are similar; | + | ===== Custom item tint (1.21.4 and after) |
| + | Since 1.21.4, tints of items are defined in the Items model definition. Some common tint source types are provided in vanilla, see [[https:// | ||
| + | <code javascript / | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | If you need to specify a custom tint source, you can register with '' | ||
| + | |||
| + | > If the tint does not work, check the value of tintindex in the model, which should be consistent with the element subscript in the '' | ||
| + | |||
| + | In version 1.21.3 and before, item model providers were instead registered with Fabric API. Different from blocks, | ||
| For item models, we can directly inherite the block model that uses tintindex: | For item models, we can directly inherite the block model that uses tintindex: | ||
tutorial/colorprovider.1724728405.txt.gz · Last modified: 2024/08/27 03:13 by solidblock