From 23bd8ab968a4fb57f5819be36f547ad8c5a55de9 Mon Sep 17 00:00:00 2001 From: Bawnorton Date: Sun, 20 Oct 2024 15:12:37 -0700 Subject: [PATCH] fabric already unzips them --- gradle.properties | 2 +- .../configurable/ConfigurableMain.java | 44 ++++++++++++++++++- .../sourceprovider/FabricSourceProvider.java | 4 +- .../NeoForgeSourceProvider.java | 4 +- .../ap/sourceprovider/SourceProviders.java | 4 +- .../configurable/api/ConfigurableApi.java | 6 +-- .../client/mixin/ModMenuMixin.java | 16 +++---- .../platform/ConfigurableClientWrapper.java | 8 ++-- .../load/ConfigurableApiImplLoader.java | 18 ++++---- .../platform/ConfigurableMainWrapper.java | 8 ++-- .../configurable/platform/Platform.java | 8 ++-- stonecutter.gradle.kts | 2 +- 12 files changed, 83 insertions(+), 41 deletions(-) diff --git a/gradle.properties b/gradle.properties index 77f3c13..b95221a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx4G fabric_versions=1.20.1, 1.21.1 neoforge_versions=1.21.1 -mod_version=2.1.1 +mod_version=2.1.2 mod_group=com.bawnorton mod_id=configurable mod_name=Configurable diff --git a/src/main/java/com/bawnorton/configurable/ConfigurableMain.java b/src/main/java/com/bawnorton/configurable/ConfigurableMain.java index 923f920..8fdd016 100644 --- a/src/main/java/com/bawnorton/configurable/ConfigurableMain.java +++ b/src/main/java/com/bawnorton/configurable/ConfigurableMain.java @@ -50,7 +50,8 @@ public static void init() { Networking.init(); Platform.forEachJar(path -> { - List sourceSetSettings = new ArrayList<>(); + //? if neoforge { + /*List sourceSetSettings = new ArrayList<>(); try (ZipFile zipFile = new ZipFile(path.toFile())) { zipFile.stream() .filter(entry -> entry.getName().startsWith("configurable/") && !entry.isDirectory()) @@ -91,7 +92,48 @@ public static void init() { } } } catch (IOException ignored) {} + *///?} else { + Path configurable = path.resolve("configurable"); + if (!(Files.exists(configurable) && Files.isDirectory(configurable))) return; + + List sourceSetSettings = new ArrayList<>(); + try (Stream stream = Files.list(configurable)) { + stream.filter(Files::isRegularFile).forEach(sourceSetSettings::add); + } catch (IOException e) { + ConfigurableMain.LOGGER.error("Could not find configurable settings", e); + } + + for(Path sourceSetSetting : sourceSetSettings) { + ConfigurableSettings settings; + try { + settings = GSON.fromJson(Files.newBufferedReader(sourceSetSetting), ConfigurableSettings.class); + } catch (IOException e) { + LOGGER.error("Could not load configurable settings", e); + return; + } + + String configName = settings.name(); + String sourceSet = settings.sourceSet(); + if(WRAPPERS.containsKey(configName)) { + Map wrappers = WRAPPERS.get(configName); + if(wrappers.containsKey(sourceSet)) { + throw new IllegalStateException("Conflicting config name \"%s\" for source set \"%s\" found in \"%s\"".formatted(configName, sourceSet, sourceSetSetting)); + } + } + + try { + ConfigurableWrapper wrapper = new ConfigurableWrapper(ConfigurableApiImplLoader.getImpl(configName)); + WRAPPERS.computeIfAbsent(configName, k -> new HashMap<>()).put(sourceSet, wrapper); + addToWrapped(settings::fullyQualifiedLoader, wrapper::setLoader, configName); + if(settings.hasScreenFactory() && !Platform.isServer()) { + addToWrapped(settings::fullyQualifiedScreenFactory, wrapper::setScreenFactory, configName); + } + } catch (IllegalStateException e) { + LOGGER.error("Could not create configurable wrapper for \"%s\"".formatted(configName), e); + } + } + //?} }); WRAPPERS.values().forEach(sourceSetWrappers -> sourceSetWrappers.values().forEach(wrapper -> { wrapper.loadConfig(); diff --git a/src/main/java/com/bawnorton/configurable/ap/sourceprovider/FabricSourceProvider.java b/src/main/java/com/bawnorton/configurable/ap/sourceprovider/FabricSourceProvider.java index 278c99a..067d6d8 100644 --- a/src/main/java/com/bawnorton/configurable/ap/sourceprovider/FabricSourceProvider.java +++ b/src/main/java/com/bawnorton/configurable/ap/sourceprovider/FabricSourceProvider.java @@ -2,7 +2,7 @@ //? if fabric { -/*import com.google.gson.Gson; +import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import javax.annotation.processing.Filer; @@ -46,4 +46,4 @@ public String getName() { return fmj.get("id").getAsString(); } } -*///?} +//?} diff --git a/src/main/java/com/bawnorton/configurable/ap/sourceprovider/NeoForgeSourceProvider.java b/src/main/java/com/bawnorton/configurable/ap/sourceprovider/NeoForgeSourceProvider.java index 63ebaa0..412b224 100644 --- a/src/main/java/com/bawnorton/configurable/ap/sourceprovider/NeoForgeSourceProvider.java +++ b/src/main/java/com/bawnorton/configurable/ap/sourceprovider/NeoForgeSourceProvider.java @@ -2,7 +2,7 @@ //? if neoforge { -import com.electronwill.nightconfig.core.Config; +/*import com.electronwill.nightconfig.core.Config; import com.electronwill.nightconfig.toml.TomlParser; import javax.annotation.processing.Filer; import java.io.IOException; @@ -42,4 +42,4 @@ public String getName() { return config.>get("mods").getFirst().get("modId"); } } -//?} +*///?} diff --git a/src/main/java/com/bawnorton/configurable/ap/sourceprovider/SourceProviders.java b/src/main/java/com/bawnorton/configurable/ap/sourceprovider/SourceProviders.java index 14bd7d8..098a064 100644 --- a/src/main/java/com/bawnorton/configurable/ap/sourceprovider/SourceProviders.java +++ b/src/main/java/com/bawnorton/configurable/ap/sourceprovider/SourceProviders.java @@ -10,9 +10,9 @@ public final class SourceProviders { public static void registerDefaultSourceProviders() { //? if fabric - /*registerSourceProvider(FabricSourceProvider::new);*/ + registerSourceProvider(FabricSourceProvider::new); //? if neoforge - registerSourceProvider(NeoForgeSourceProvider::new); + /*registerSourceProvider(NeoForgeSourceProvider::new);*/ } public static void registerSourceProvider(SourceProviderFactory factory) { diff --git a/src/main/java/com/bawnorton/configurable/api/ConfigurableApi.java b/src/main/java/com/bawnorton/configurable/api/ConfigurableApi.java index 557b04e..512568f 100644 --- a/src/main/java/com/bawnorton/configurable/api/ConfigurableApi.java +++ b/src/main/java/com/bawnorton/configurable/api/ConfigurableApi.java @@ -34,13 +34,13 @@ default FieldNamingStrategy defaultFieldNamingStrategy() { } //? if !fabric { - /** + /*/^* * The name of the config this API impl belongs to, this is necessary for non-fabric implementations *
* THIS DOES NOT SET THE NAME OF THE CONFIG - */ + ^/ default String getConfigName() { throw new UnsupportedOperationException(); } - //?} + *///?} } diff --git a/src/main/java/com/bawnorton/configurable/client/mixin/ModMenuMixin.java b/src/main/java/com/bawnorton/configurable/client/mixin/ModMenuMixin.java index b0cdf27..03b9add 100644 --- a/src/main/java/com/bawnorton/configurable/client/mixin/ModMenuMixin.java +++ b/src/main/java/com/bawnorton/configurable/client/mixin/ModMenuMixin.java @@ -3,7 +3,7 @@ import org.spongepowered.asm.mixin.Mixin; //? if fabric { -/*import com.bawnorton.configurable.ConfigurableMain; +import com.bawnorton.configurable.ConfigurableMain; import com.bawnorton.configurable.load.ConfigurableWrapper; import com.terraformersmc.modmenu.ModMenu; import com.terraformersmc.modmenu.api.ConfigScreenFactory; @@ -25,10 +25,10 @@ public abstract class ModMenuMixin { @Shadow @Final private static List apiImplementations; //?} else { - /^@Shadow private static Map> configScreenFactories; + /*@Shadow private static Map> configScreenFactories; @Shadow private static List>> delayedScreenFactoryProviders; - ^///?} + *///?} @Inject( @@ -59,14 +59,14 @@ public ConfigScreenFactory getModConfigScreenFactory() { //? if >=1.21 { apiImplementations.add(api); //?} else { - /^delayedScreenFactoryProviders.add(api.getProvidedConfigScreenFactories()); - ^///?} + /*delayedScreenFactoryProviders.add(api.getProvidedConfigScreenFactories()); + *///?} })); } } -*///?} else { -import com.bawnorton.configurable.client.ConfigurableClient; +//?} else { +/*import com.bawnorton.configurable.client.ConfigurableClient; @Mixin(ConfigurableClient.class) public abstract class ModMenuMixin {} -//?} +*///?} diff --git a/src/main/java/com/bawnorton/configurable/client/platform/ConfigurableClientWrapper.java b/src/main/java/com/bawnorton/configurable/client/platform/ConfigurableClientWrapper.java index 5c514c7..a57b2e3 100644 --- a/src/main/java/com/bawnorton/configurable/client/platform/ConfigurableClientWrapper.java +++ b/src/main/java/com/bawnorton/configurable/client/platform/ConfigurableClientWrapper.java @@ -3,7 +3,7 @@ import com.bawnorton.configurable.client.ConfigurableClient; //? if fabric { -/*import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.ClientModInitializer; public final class ConfigurableClientWrapper implements ClientModInitializer { @Override @@ -11,8 +11,8 @@ public void onInitializeClient() { ConfigurableClient.init(); } } -*///?} elif neoforge { -import com.bawnorton.configurable.ConfigurableMain; +//?} elif neoforge { +/*import com.bawnorton.configurable.ConfigurableMain; import com.bawnorton.configurable.platform.Platform; import net.minecraft.client.MinecraftClient; import net.neoforged.api.distmarker.Dist; @@ -43,4 +43,4 @@ public ConfigurableClientWrapper() { })); } } -//?} +*///?} diff --git a/src/main/java/com/bawnorton/configurable/load/ConfigurableApiImplLoader.java b/src/main/java/com/bawnorton/configurable/load/ConfigurableApiImplLoader.java index 77cb4c8..58af742 100644 --- a/src/main/java/com/bawnorton/configurable/load/ConfigurableApiImplLoader.java +++ b/src/main/java/com/bawnorton/configurable/load/ConfigurableApiImplLoader.java @@ -6,19 +6,19 @@ import java.util.Map; //? if fabric { -/*import net.fabricmc.loader.api.FabricLoader; -*///?} elif neoforge { -import java.util.ServiceLoader; -//?} +import net.fabricmc.loader.api.FabricLoader; +//?} elif neoforge { +/*import java.util.ServiceLoader; +*///?} public final class ConfigurableApiImplLoader { //? if neoforge - private static final ServiceLoader serviceLoader = ServiceLoader.load(ConfigurableApi.class); + /*private static final ServiceLoader serviceLoader = ServiceLoader.load(ConfigurableApi.class);*/ private static final Map impls = new HashMap<>(); public static void load() { //? if fabric { - /*FabricLoader.getInstance().getEntrypointContainers("configurable", ConfigurableApi.class).forEach(container -> { + FabricLoader.getInstance().getEntrypointContainers("configurable", ConfigurableApi.class).forEach(container -> { String id = container.getProvider().getMetadata().getId(); try { impls.put(id, container.getEntrypoint()); @@ -26,9 +26,9 @@ public static void load() { ConfigurableMain.LOGGER.error("Mod {} provides a broken ConfigurableApi implemenation", id, e); } }); - *///?} elif neoforge { - serviceLoader.forEach(apiImpl -> impls.put(apiImpl.getConfigName(), apiImpl)); - //?} + //?} elif neoforge { + /*serviceLoader.forEach(apiImpl -> impls.put(apiImpl.getConfigName(), apiImpl)); + *///?} } public static ConfigurableApi getImpl(String name) { diff --git a/src/main/java/com/bawnorton/configurable/platform/ConfigurableMainWrapper.java b/src/main/java/com/bawnorton/configurable/platform/ConfigurableMainWrapper.java index 93dbbd5..ed72897 100644 --- a/src/main/java/com/bawnorton/configurable/platform/ConfigurableMainWrapper.java +++ b/src/main/java/com/bawnorton/configurable/platform/ConfigurableMainWrapper.java @@ -3,7 +3,7 @@ import com.bawnorton.configurable.ConfigurableMain; //? if fabric { -/*import net.fabricmc.api.ModInitializer; +import net.fabricmc.api.ModInitializer; public final class ConfigurableMainWrapper implements ModInitializer { @Override @@ -11,8 +11,8 @@ public void onInitialize() { ConfigurableMain.init(); } } -*///?} elif neoforge { -import net.neoforged.fml.common.Mod; +//?} elif neoforge { +/*import net.neoforged.fml.common.Mod; @Mod(ConfigurableMain.MOD_ID) public final class ConfigurableMainWrapper { @@ -20,4 +20,4 @@ public ConfigurableMainWrapper() { ConfigurableMain.init(); } } -//?} +*///?} diff --git a/src/main/java/com/bawnorton/configurable/platform/Platform.java b/src/main/java/com/bawnorton/configurable/platform/Platform.java index 84bde8a..ac25312 100644 --- a/src/main/java/com/bawnorton/configurable/platform/Platform.java +++ b/src/main/java/com/bawnorton/configurable/platform/Platform.java @@ -4,7 +4,7 @@ import java.util.function.Consumer; //? if fabric { -/*import net.fabricmc.api.EnvType; +import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import java.util.List; @@ -35,8 +35,8 @@ public static boolean isServer() { } } -*///?} elif neoforge { -import net.neoforged.fml.ModContainer; +//?} elif neoforge { +/*import net.neoforged.fml.ModContainer; import net.neoforged.fml.loading.FMLEnvironment; import net.neoforged.fml.loading.FMLPaths; import net.neoforged.fml.loading.LoadingModList; @@ -80,4 +80,4 @@ public static boolean isServer() { return FMLEnvironment.dist.isDedicatedServer(); } } -//?} \ No newline at end of file +*///?} \ No newline at end of file diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index 6d34645..584861a 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -1,7 +1,7 @@ plugins { id("dev.kikugie.stonecutter") } -stonecutter active "1.21.1-neoforge-yarn" /* [SC] DO NOT EDIT */ +stonecutter active "1.21.1-fabric-yarn" /* [SC] DO NOT EDIT */ stonecutter registerChiseled tasks.register("chiseledBuildAndCollect", stonecutter.chiseled) { group = "project"