Skip to content

Commit 0c61e31

Browse files
committed
Add support for dry_foliage colormap and the leaf_litter block
1 parent d1e130e commit 0c61e31

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

core/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public class BlockColorCalculatorFactory {
5151
BLEND_MIN_Z = - BLEND_RADIUS_H,
5252
BLEND_MAX_Z = BLEND_RADIUS_H;
5353

54-
private final int[] foliageMap = new int[65536];
55-
private final int[] grassMap = new int[65536];
54+
private int[] foliageMap = new int[0];
55+
private int[] dryFoliageMap = new int[0];
56+
private int[] grassMap = new int[0];
5657

5758
private final Map<String, ColorFunction> blockColorMap;
5859

@@ -76,6 +77,9 @@ public void load(Path configFile) throws IOException {
7677
case "@foliage":
7778
colorFunction = BlockColorCalculator::getBlendedFoliageColor;
7879
break;
80+
case "@dry_foliage":
81+
colorFunction = BlockColorCalculator::getBlendedDryFoliageColor;
82+
break;
7983
case "@grass":
8084
colorFunction = BlockColorCalculator::getBlendedGrassColor;
8185
break;
@@ -100,12 +104,19 @@ public void load(Path configFile) throws IOException {
100104
}
101105
}
102106

103-
public void setFoliageMap(BufferedImage foliageMap) {
104-
foliageMap.getRGB(0, 0, 256, 256, this.foliageMap, 0, 256);
107+
public void setFoliageMap(BufferedImage map) {
108+
this.foliageMap = new int[65536];
109+
map.getRGB(0, 0, 256, 256, this.foliageMap, 0, 256);
110+
}
111+
112+
public void setDryFoliageMap(BufferedImage map) {
113+
this.dryFoliageMap = new int[65536];
114+
map.getRGB(0, 0, 256, 256, this.dryFoliageMap, 0, 256);
105115
}
106116

107-
public void setGrassMap(BufferedImage grassMap) {
108-
grassMap.getRGB(0, 0, 256, 256, this.grassMap, 0, 256);
117+
public void setGrassMap(BufferedImage map) {
118+
this.grassMap = new int[65536];
119+
map.getRGB(0, 0, 256, 256, this.grassMap, 0, 256);
109120
}
110121

111122
public BlockColorCalculator createCalculator() {
@@ -181,6 +192,29 @@ public Color getFoliageColor(Biome biome, Color target) {
181192
return target.overlay(biome.getOverlayFoliageColor());
182193
}
183194

195+
public Color getBlendedDryFoliageColor(BlockNeighborhood block, Color target) {
196+
target.set(0, 0, 0, 0, true);
197+
198+
int x, y, z;
199+
200+
Biome biome;
201+
for (y = BLEND_MIN_Y; y <= BLEND_MAX_Y; y++) {
202+
for (x = BLEND_MIN_X; x <= BLEND_MAX_X; x++) {
203+
for (z = BLEND_MIN_Z; z <= BLEND_MAX_Z; z++) {
204+
biome = block.getNeighborBlock(x, y, z).getBiome();
205+
target.add(getDryFoliageColor(biome, tempColor));
206+
}
207+
}
208+
}
209+
210+
return target.flatten();
211+
}
212+
213+
public Color getDryFoliageColor(Biome biome, Color target) {
214+
getColorFromMap(biome, dryFoliageMap, 0xff8f5f33, target);
215+
return target.overlay(biome.getOverlayFoliageColor());
216+
}
217+
184218
public Color getBlendedGrassColor(BlockNeighborhood block, Color target) {
185219
target.set(0, 0, 0, 0, true);
186220

core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/ResourcePack.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,16 @@ private void bake() throws IOException, InterruptedException {
322322
}
323323

324324
BufferedImage foliage = new ResourcePath<BufferedImage>("minecraft:colormap/foliage").getResource(colormaps::get);
325-
if (foliage == null) throw new IOException("Failed to bake resource-pack: No foliage-colormap found!");
326-
this.colorCalculatorFactory.setFoliageMap(foliage);
325+
if (foliage != null)
326+
this.colorCalculatorFactory.setFoliageMap(foliage);
327+
328+
BufferedImage dryFoliage = new ResourcePath<BufferedImage>("minecraft:colormap/dry_foliage").getResource(colormaps::get);
329+
if (dryFoliage != null)
330+
this.colorCalculatorFactory.setDryFoliageMap(dryFoliage);
327331

328332
BufferedImage grass = new ResourcePath<BufferedImage>("minecraft:colormap/grass").getResource(colormaps::get);
329-
if (grass == null) throw new IOException("Failed to bake resource-pack: No grass-colormap found!");
330-
this.colorCalculatorFactory.setGrassMap(grass);
333+
if (grass != null)
334+
this.colorCalculatorFactory.setGrassMap(grass);
331335

332336
// invoke extensions
333337
for (ResourcePackExtension extension : resourcePackExtensions.values()) {

core/src/main/resourceExtensions/assets/minecraft/blockColors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@
6565
"minecraft:purple_shulker_box": "#8932b8",
6666
"minecraft:magenta_shulker_box": "#c74ebd",
6767
"minecraft:pink_shulker_box": "#f38baa",
68-
"minecraft:pale_oak_leaves": "#ffffff"
68+
"minecraft:pale_oak_leaves": "#ffffff",
69+
"minecraft:leaf_litter": "@dry_foliage"
6970
}

0 commit comments

Comments
 (0)