BlockColors .java

net.minecraft.client.color.block.BlockColors (class): members: getColoringProperties, LILY_PAD_IN_WORLD, LILY_PAD_DEFAULT, getTintSources, getTintSource.

net.minecraft.client.color.blockclass85 linesclient3.3 KB

API Surface (4)

BlockColors createDefault()
List<BlockTintSource> getTintSources(final BlockState state)
void register(final List<BlockTintSource> layers, final Block... blocks)
Set<Property<?>> getColoringProperties(final Block block)

Fields & Constants (4)

LILY_PAD_IN_WORLD
LILY_PAD_DEFAULT
BLANK_LAYER
sources

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

BlockColors.java85 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.color.block;
2
3
import java.util.HashSet;
4
import java.util.IdentityHashMap;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.Set;
8
import net.fabricmc.api.EnvType;
9
import net.fabricmc.api.Environment;
10
import net.minecraft.world.level.block.Block;
11
import net.minecraft.world.level.block.Blocks;
12
import net.minecraft.world.level.block.state.BlockState;
13
import net.minecraft.world.level.block.state.properties.Property;
14
import org.jspecify.annotations.Nullable;
15
16
@Environment(EnvType.CLIENT)
17
public class BlockColors {
18
	public static final int LILY_PAD_IN_WORLD = -14647248;
19
	public static final int LILY_PAD_DEFAULT = -9321636;
20
	private static final BlockTintSource BLANK_LAYER = BlockTintSources.constant(-1);
21
	private final Map<Block, List<BlockTintSource>> sources = new IdentityHashMap<>();
22
23
	public static BlockColors createDefault() {
24
		BlockColors colors = new BlockColors();
25
		colors.register(List.of(BlockTintSources.doubleTallGrass()), Blocks.LARGE_FERN, Blocks.TALL_GRASS);
26
		colors.register(List.of(BlockTintSources.grass()), Blocks.FERN, Blocks.SHORT_GRASS, Blocks.POTTED_FERN, Blocks.BUSH);
27
		colors.register(List.of(BlockTintSources.grassBlock()), Blocks.GRASS_BLOCK);
28
		colors.register(List.of(BLANK_LAYER, BlockTintSources.grass()), Blocks.PINK_PETALS, Blocks.WILDFLOWERS);
29
		colors.register(List.of(BlockTintSources.constant(-10380959)), Blocks.SPRUCE_LEAVES);
30
		colors.register(List.of(BlockTintSources.constant(-8345771)), Blocks.BIRCH_LEAVES);
31
		colors.register(
32
			List.of(BlockTintSources.foliage()),
33
			Blocks.OAK_LEAVES,
34
			Blocks.JUNGLE_LEAVES,
35
			Blocks.ACACIA_LEAVES,
36
			Blocks.DARK_OAK_LEAVES,
37
			Blocks.VINE,
38
			Blocks.MANGROVE_LEAVES
39
		);
40
		colors.register(List.of(BlockTintSources.dryFoliage()), Blocks.LEAF_LITTER);
41
		colors.register(List.of(BlockTintSources.water()), Blocks.WATER_CAULDRON);
42
		colors.register(List.of(BlockTintSources.waterParticles()), Blocks.WATER, Blocks.BUBBLE_COLUMN);
43
		colors.register(List.of(BlockTintSources.redstone()), Blocks.REDSTONE_WIRE);
44
		colors.register(List.of(BlockTintSources.sugarCane()), Blocks.SUGAR_CANE);
45
		colors.register(List.of(BlockTintSources.constant(-2046180)), Blocks.ATTACHED_MELON_STEM, Blocks.ATTACHED_PUMPKIN_STEM);
46
		colors.register(List.of(BlockTintSources.stem()), Blocks.MELON_STEM, Blocks.PUMPKIN_STEM);
47
		colors.register(List.of(BlockTintSources.constant(-9321636, -14647248)), Blocks.LILY_PAD);
48
		return colors;
49
	}
50
51
	public List<BlockTintSource> getTintSources(final BlockState state) {
52
		return this.sources.getOrDefault(state.getBlock(), List.of());
53
	}
54
55
	public @Nullable BlockTintSource getTintSource(final BlockState state, final int layer) {
56
		List<BlockTintSource> layers = this.getTintSources(state);
57
		return layer >= layers.size() ? null : layers.get(layer);
58
	}
59
60
	public void register(final List<BlockTintSource> layers, final Block... blocks) {
61
		for (Block block : blocks) {
62
			this.sources.put(block, layers);
63
		}
64
	}
65
66
	public Set<Property<?>> getColoringProperties(final Block block) {
67
		List<BlockTintSource> sources = this.sources.getOrDefault(block, List.of());
68
		if (sources.isEmpty()) {
69
			return Set.of();
70
		}
71
72
		if (sources.size() == 1) {
73
			return sources.getFirst().relevantProperties();
74
		}
75
76
		Set<Property<?>> result = new HashSet<>();
77
78
		for (BlockTintSource source : sources) {
79
			result.addAll(source.relevantProperties());
80
		}
81
82
		return result;
83
	}
84
}
85

Decompiled Minecraft 26.3 source of BlockColors (net/minecraft/client/color/block/BlockColors.java) with Mojang official mappings, stored verbatim on the site.