Skip to content

Commit

Permalink
Add default color override for pale oak leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Oct 24, 2024
1 parent 0932485 commit a638e04
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
package xyz.jpenilla.squaremap.common.config;

import io.leangen.geantyref.TypeToken;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.NodePath;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import xyz.jpenilla.squaremap.common.data.DirectoryProvider;
import xyz.jpenilla.squaremap.common.util.ReflectionUtil;

@SuppressWarnings("unused")
public final class Advanced extends AbstractConfig {
private static final int LATEST_VERSION = 3;
private static final int LATEST_VERSION = 4;

Advanced(final DirectoryProvider directoryProvider) {
super(directoryProvider.dataDirectory(), Advanced.class, "advanced.yml", LATEST_VERSION);
}

@Override
protected void addVersions(ConfigurationTransformation.VersionedBuilder versionedBuilder) {
final ConfigurationTransformation oneToTwo = ConfigurationTransformation.builder()
.addAction(NodePath.path("world-settings", "default", "color-overrides"), (path, node) -> {
final TypeToken<Map<String, String>> type = new TypeToken<>() {};

final ConfigurationNode foliageNode = node.node("biomes", "foliage");
final Map<String, String> foliageMap = foliageNode.get(type, new HashMap<>());
foliageMap.put("minecraft:mangrove_swamp", "#6f9623");
foliageNode.set(type, foliageMap);
final NodePath defaultColorOverridesPath = NodePath.path("world-settings", "default", "color-overrides");

final ConfigurationNode blocksNode = node.node("blocks");
final Map<String, String> blocksMap = blocksNode.get(type, new HashMap<>());
blocksMap.put("minecraft:pink_petals", "#FFB4DB");
blocksNode.set(type, blocksMap);
return null;
})
final ConfigurationTransformation oneToTwo = ConfigurationTransformation.builder()
.addAction(
defaultColorOverridesPath.withAppendedChild("biomes").withAppendedChild("foliage"),
Transformations.modifyStringMap(map -> {
map.put("minecraft:mangrove_swamp", "#6f9623");
})
)
.addAction(
defaultColorOverridesPath.withAppendedChild("blocks"),
Transformations.modifyStringMap(map -> {
map.put("minecraft:pink_petals", "#FFB4DB");
})
)
.build();
final ConfigurationTransformation twoToThree = ConfigurationTransformation.builder()
.addAction(NodePath.path("world-settings"), Transformations.eachMapChild(worldSection -> {
Expand All @@ -50,9 +47,17 @@ protected void addVersions(ConfigurationTransformation.VersionedBuilder versione
);
}))
.build();
final ConfigurationTransformation threeToFour = ConfigurationTransformation.builder()
.addAction(
defaultColorOverridesPath.withAppendedChild("blocks"),
Transformations.modifyStringMap(map -> {
map.put("minecraft:pale_oak_leaves", "#626760");
}))
.build();

versionedBuilder.addVersion(2, oneToTwo);
versionedBuilder.addVersion(LATEST_VERSION, twoToThree);
versionedBuilder.addVersion(3, twoToThree);
versionedBuilder.addVersion(LATEST_VERSION, threeToFour);
}

static Advanced config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package xyz.jpenilla.squaremap.common.config;

import io.leangen.geantyref.TypeFactory;
import io.leangen.geantyref.TypeToken;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
Expand Down Expand Up @@ -34,6 +38,27 @@ static TransformAction eachMapChild(final CheckedConsumer<ConfigurationNode, Con
};
}

static TransformAction modifyStringMap(
final Consumer<Map<String, String>> consumer
) {
return modifyMap(String.class, String.class, consumer);
}

@SuppressWarnings("unchecked")
static <K, V> TransformAction modifyMap(
final Class<K> keyType,
final Class<V> valueType,
final Consumer<Map<K, V>> consumer
) {
return (path, node) -> {
final Type type = TypeFactory.parameterizedClass(Map.class, keyType, valueType);
final Map<K, V> map = (Map<K, V>) node.get(type, new HashMap<>());
consumer.accept(map);
node.set(type, map);
return null;
};
}

// expects nodes to be round-trip representable as List<String> or Map<String, String>
static void applyMapKeyOrListValueRenames(final List<ConfigurationNode> sections, final Map<Set<String>, String> renames) throws SerializationException {
for (final ConfigurationNode sectionNode : sections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private void colorOverrideBlocksSettings() {
Map.entry("minecraft:attached_pumpkin_stem", "#E0C71C"),
Map.entry("minecraft:spruce_leaves", "#619961"),
Map.entry("minecraft:birch_leaves", "#80A755"),
Map.entry("minecraft:pale_oak_leaves", "#626760"),
Map.entry("minecraft:lava", "#EA5C0F"),
Map.entry("minecraft:glass", "#FFFFFF")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import xyz.jpenilla.squaremap.common.util.Colors;
import xyz.jpenilla.squaremap.common.util.chunksnapshot.ChunkSnapshot;

// TODO(1.21.2): pale forest colors, general foliage colors (dark forest?)
@DefaultQualifier(NonNull.class)
public final class BiomeColors {
private static final int BLOCKPOS_BIOME_CACHE_SIZE = 4096;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import xyz.jpenilla.squaremap.common.data.DirectoryProvider;

// TODO(1.21.2): test fabric & neoforge
@DefaultQualifier(NonNull.class)
public abstract class AbstractFluidColorExporter {
private final DirectoryProvider directoryProvider;
Expand Down

0 comments on commit a638e04

Please sign in to comment.