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. --- CHANGELOG.md | 3 + build.gradle | 1 + gradle.properties | 2 +- .../iceberg/mixin/ConfiguredConfigHelperMixin.java | 55 ++++++ .../ConfiguredModConfigSelectionScreenMixin.java | 212 +++++++++++++++++++++ .../iceberg/mixin/MinecraftMixin.java | 1 - .../anthonyhilyard/iceberg/mixin/MixinConfig.java | 60 ++++++ src/main/resources/META-INF/mods.toml | 7 + src/main/resources/iceberg.mixins.json | 6 +- 9 files changed, 344 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredConfigHelperMixin.java create mode 100644 src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredModConfigSelectionScreenMixin.java create mode 100644 src/main/java/com/anthonyhilyard/iceberg/mixin/MixinConfig.java diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d735b..0566ee9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### 1.0.45 +- Added support for Configured configuration menus to IcebergConfig. + ### 1.0.44 - Fixed incompatibility with some mods causing a crash at startup. diff --git a/build.gradle b/build.gradle index bc816f3..73cd42a 100644 --- a/build.gradle +++ b/build.gradle @@ -60,6 +60,7 @@ dependencies { minecraft "net.minecraftforge:forge:${project.mcVersion}-${project.forgeVersion}" annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' compileClasspath fg.deobf('curse.maven:configmenusforge-544048:3570070') + compileClasspath fg.deobf('curse.maven:configured-457570:3822820') } jar { diff --git a/gradle.properties b/gradle.properties index b075a86..239dfec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,6 @@ org.gradle.daemon=false name=${rootProject.name} group=com.anthonyhilyard.${name.toLowerCase()} author=anthonyhilyard -version=1.0.44 +version=1.0.45 mcVersion=1.19 forgeVersion=41.0.30 \ No newline at end of file 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 diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredModConfigSelectionScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredModConfigSelectionScreenMixin.java new file mode 100644 index 0000000..a682a00 --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfiguredModConfigSelectionScreenMixin.java @@ -0,0 +1,212 @@ +package com.anthonyhilyard.iceberg.mixin; + +import java.lang.reflect.Field; + +import com.anthonyhilyard.iceberg.Loader; +import com.anthonyhilyard.iceberg.config.IcebergConfigSpec; +import com.electronwill.nightconfig.core.UnmodifiableConfig; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.mrcrayfish.configured.client.screen.ConfigScreen; +import com.mrcrayfish.configured.client.screen.ListMenuScreen; +import com.mrcrayfish.configured.client.screen.ModConfigSelectionScreen; +import com.mrcrayfish.configured.client.screen.ModConfigSelectionScreen.FileItem; +import com.mrcrayfish.configured.client.screen.WorldSelectionScreen; +import com.mrcrayfish.configured.client.screen.ConfigScreen.FolderEntry; +import com.mrcrayfish.configured.client.screen.ConfigScreen.IEntry; +import com.mrcrayfish.configured.client.screen.widget.IconButton; +import com.mrcrayfish.configured.util.ConfigHelper; + +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.At; + +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.narration.ScreenNarrationCollector; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.config.ModConfig; +import net.minecraftforge.fml.unsafe.UnsafeHacks; + +@Mixin(FileItem.class) +public class ConfiguredModConfigSelectionScreenMixin +{ + @Shadow(aliases = "this$0", remap = false) + @Final + ModConfigSelectionScreen this$0; + + @Shadow(remap = false) + @Final + protected ModConfig config; + + @Shadow(remap = false) + @Final + protected Component title; + + @Shadow(remap = false) + private boolean hasRequiredPermission() { return true; } + + @Inject(method = "createModifyButton", at = @At(value = "HEAD"), remap = false, cancellable = true) + private void createModifyButton(ModConfig config, CallbackInfoReturnable