From 427f975d78b64ec4433e8e0542729feb0e618608 Mon Sep 17 00:00:00 2001 From: Anthony Hilyard Date: Wed, 22 Jun 2022 18:07:55 -0700 Subject: Added support for Configured to IcebergConfig. --- .../iceberg/mixin/ConfiguredConfigHelperMixin.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredConfigHelperMixin.java (limited to 'src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredConfigHelperMixin.java') diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredConfigHelperMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredConfigHelperMixin.java new file mode 100644 index 0000000..682fcb8 --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredConfigHelperMixin.java @@ -0,0 +1,55 @@ +package com.anthonyhilyard.iceberg.mixin; + +import java.util.ArrayList; +import java.util.List; + +import com.anthonyhilyard.iceberg.config.IcebergConfigSpec; +import com.electronwill.nightconfig.core.AbstractConfig; +import com.electronwill.nightconfig.core.UnmodifiableConfig; + + +import org.apache.commons.lang3.tuple.Pair; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.config.ModConfig; + + +import com.mrcrayfish.configured.util.ConfigHelper; + + +@Mixin(ConfigHelper.class) +public class ConfiguredConfigHelperMixin +{ + @Inject(method = "gatherAllConfigValues(Lnet/minecraftforge/fml/config/ModConfig;)Ljava/util/List;", + at = @At(value = "HEAD"), cancellable = true, remap = false) + private static void gatherAllConfigValuesIcebergSupport(ModConfig config, CallbackInfoReturnable> info) + { + if (config.getSpec() instanceof IcebergConfigSpec icebergConfigSpec) + { + List, ForgeConfigSpec.ValueSpec>> values = new ArrayList<>(); + gatherValuesFromIcebergConfig(icebergConfigSpec.getValues(), icebergConfigSpec, values); + info.setReturnValue(values); + } + } + + private static void gatherValuesFromIcebergConfig(UnmodifiableConfig config, IcebergConfigSpec spec, List, ForgeConfigSpec.ValueSpec>> values) + { + config.valueMap().forEach((s, o) -> + { + if (o instanceof AbstractConfig) + { + gatherValuesFromIcebergConfig((UnmodifiableConfig) o, spec, values); + } + else if (o instanceof ForgeConfigSpec.ConfigValue) + { + ForgeConfigSpec.ConfigValue configValue = (ForgeConfigSpec.ConfigValue) o; + ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(configValue.getPath()); + values.add(Pair.of(configValue, valueSpec)); + } + }); + } +} \ No newline at end of file -- cgit