diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/Advanced.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/Advanced.java index 0273dbb1..fff5a5fb 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/config/Advanced.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/Advanced.java @@ -1,10 +1,7 @@ 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; @@ -12,7 +9,7 @@ @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); @@ -20,21 +17,21 @@ public final class Advanced extends AbstractConfig { @Override protected void addVersions(ConfigurationTransformation.VersionedBuilder versionedBuilder) { - final ConfigurationTransformation oneToTwo = ConfigurationTransformation.builder() - .addAction(NodePath.path("world-settings", "default", "color-overrides"), (path, node) -> { - final TypeToken> type = new TypeToken<>() {}; - - final ConfigurationNode foliageNode = node.node("biomes", "foliage"); - final Map 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 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 -> { @@ -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; diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/Transformations.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/Transformations.java index 2575f4e6..2a4020f6 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/config/Transformations.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/Transformations.java @@ -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; @@ -34,6 +38,27 @@ static TransformAction eachMapChild(final CheckedConsumer> consumer + ) { + return modifyMap(String.class, String.class, consumer); + } + + @SuppressWarnings("unchecked") + static TransformAction modifyMap( + final Class keyType, + final Class valueType, + final Consumer> consumer + ) { + return (path, node) -> { + final Type type = TypeFactory.parameterizedClass(Map.class, keyType, valueType); + final Map map = (Map) node.get(type, new HashMap<>()); + consumer.accept(map); + node.set(type, map); + return null; + }; + } + // expects nodes to be round-trip representable as List or Map static void applyMapKeyOrListValueRenames(final List sections, final Map, String> renames) throws SerializationException { for (final ConfigurationNode sectionNode : sections) { diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldAdvanced.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldAdvanced.java index 72cd95e0..73b027d8 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldAdvanced.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldAdvanced.java @@ -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") ) diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/data/BiomeColors.java b/common/src/main/java/xyz/jpenilla/squaremap/common/data/BiomeColors.java index d92cf86e..2506e2b5 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/data/BiomeColors.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/data/BiomeColors.java @@ -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; diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/util/AbstractFluidColorExporter.java b/common/src/main/java/xyz/jpenilla/squaremap/common/util/AbstractFluidColorExporter.java index b7186803..b0a10939 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/util/AbstractFluidColorExporter.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/util/AbstractFluidColorExporter.java @@ -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;