diff --git a/common/build.gradle.kts b/common/build.gradle.kts index d00305b9..5bcca906 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -8,6 +8,7 @@ dependencies { modImplementation(libs.fabric.loader) modCompileOnly(libs.fabric.api) modCompileOnly(libs.ae2.fabric) + modCompileOnly(libs.cloth.fabric) modCompileOnly(libs.ae2wtlib.fabric) modCompileOnly(libs.appbot.fabric) } diff --git a/common/src/main/java/gripe/_90/megacells/MEGACells.java b/common/src/main/java/gripe/_90/megacells/MEGACells.java index e0378176..b8b6833c 100644 --- a/common/src/main/java/gripe/_90/megacells/MEGACells.java +++ b/common/src/main/java/gripe/_90/megacells/MEGACells.java @@ -24,6 +24,7 @@ import gripe._90.megacells.crafting.DecompressionService; import gripe._90.megacells.definition.MEGABlockEntities; import gripe._90.megacells.definition.MEGABlocks; +import gripe._90.megacells.definition.MEGAConfig; import gripe._90.megacells.definition.MEGAItems; import gripe._90.megacells.integration.ae2wt.AE2WTIntegration; import gripe._90.megacells.integration.appbot.AppBotIntegration; @@ -45,6 +46,8 @@ public static ResourceLocation makeId(String path) { } public static void initCommon() { + MEGAConfig.load(); + MEGAItems.init(); MEGABlocks.init(); MEGABlockEntities.init(); diff --git a/common/src/main/java/gripe/_90/megacells/definition/MEGAConfig.java b/common/src/main/java/gripe/_90/megacells/definition/MEGAConfig.java new file mode 100644 index 00000000..75ed7a4e --- /dev/null +++ b/common/src/main/java/gripe/_90/megacells/definition/MEGAConfig.java @@ -0,0 +1,32 @@ +package gripe._90.megacells.definition; + +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.ConfigData; +import me.shedaniel.autoconfig.annotation.Config; +import me.shedaniel.autoconfig.annotation.ConfigEntry; +import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; + +import gripe._90.megacells.MEGACells; + +@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"}) +@Config(name = MEGACells.MODID) +public class MEGAConfig implements ConfigData { + @ConfigEntry.Gui.Excluded + public static MEGAConfig INSTANCE; + + @ConfigEntry.BoundedDiscrete(min = 2, max = 12) + private int CompressionChainLength = 3; + + public int getCompressionChainLength() { + return CompressionChainLength; + } + + public static void load() { + if (INSTANCE != null) { + throw new IllegalStateException("Config has already been loaded"); + } + + AutoConfig.register(MEGAConfig.class, GsonConfigSerializer::new); + INSTANCE = AutoConfig.getConfigHolder(MEGAConfig.class).getConfig(); + } +} diff --git a/common/src/main/java/gripe/_90/megacells/definition/MEGACreativeTab.java b/common/src/main/java/gripe/_90/megacells/definition/MEGACreativeTab.java index 83e15339..8c1cc45e 100644 --- a/common/src/main/java/gripe/_90/megacells/definition/MEGACreativeTab.java +++ b/common/src/main/java/gripe/_90/megacells/definition/MEGACreativeTab.java @@ -17,7 +17,7 @@ public final class MEGACreativeTab { public static final CreativeModeTab TAB = MEGACells.PLATFORM .getCreativeTabBuilder() - .title(MEGATranslations.CreativeTab.text()) + .title(MEGATranslations.ModName.text()) .icon(MEGAItems.ITEM_CELL_256M::stack) .displayItems(MEGACreativeTab::populateTab) .build(); diff --git a/common/src/main/java/gripe/_90/megacells/definition/MEGATranslations.java b/common/src/main/java/gripe/_90/megacells/definition/MEGATranslations.java index 5f4db4f7..cc54b80d 100644 --- a/common/src/main/java/gripe/_90/megacells/definition/MEGATranslations.java +++ b/common/src/main/java/gripe/_90/megacells/definition/MEGATranslations.java @@ -8,13 +8,14 @@ public enum MEGATranslations implements LocalizationEnum { AcceleratorThreads("Provides 4 co-processing threads per block.", Type.TOOLTIP), ALot("A lot.", Type.TOOLTIP), Compression("Compression: %s", Type.TOOLTIP), + CompressionChainLength("Bulk Compression chain length", Type.CONFIG), Contains("Contains: %s", Type.TOOLTIP), - CreativeTab("MEGA Cells", Type.GUI), Disabled("Disabled", Type.TOOLTIP), Empty("Empty", Type.TOOLTIP), Enabled("Enabled", Type.TOOLTIP), FilterChemicalUnsupported("Filter chemical unsupported!", Type.TOOLTIP), MismatchedFilter("Mismatched filter!", Type.TOOLTIP), + ModName("MEGA Cells", Type.GUI), PartitionedFor("Partitioned for: %s", Type.TOOLTIP), ProcessingOnly("Supports processing patterns only.", Type.TOOLTIP), Quantity("Quantity: %s", Type.TOOLTIP), @@ -35,21 +36,20 @@ public String getEnglishText() { @Override public String getTranslationKey() { - return String.format("%s.%s.%s", type.getRoot(), MEGACells.MODID, this.name()); + return type == Type.CONFIG + ? type.root.formatted(MEGACells.MODID) + "." + name() + : String.format("%s.%s.%s", type.root, MEGACells.MODID, name()); } private enum Type { GUI("gui"), - TOOLTIP("gui.tooltips"); + TOOLTIP("gui.tooltips"), + CONFIG("text.autoconfig.%s.option"); private final String root; Type(String root) { this.root = root; } - - private String getRoot() { - return root; - } } } diff --git a/common/src/main/java/gripe/_90/megacells/util/CompressionChain.java b/common/src/main/java/gripe/_90/megacells/util/CompressionChain.java index 08fa8e07..ad21cfb7 100644 --- a/common/src/main/java/gripe/_90/megacells/util/CompressionChain.java +++ b/common/src/main/java/gripe/_90/megacells/util/CompressionChain.java @@ -8,6 +8,8 @@ import appeng.api.stacks.AEItemKey; +import gripe._90.megacells.definition.MEGAConfig; + public class CompressionChain extends ObjectArrayList { public void add(AEItemKey item, int factor) { this.add(new CompressionVariant(item, factor)); @@ -48,15 +50,14 @@ public CompressionChain lastMultiplierSwapped() { } public CompressionChain limited() { - // TODO: make this configurable - var variantLimit = 3; + var chainLength = MEGAConfig.INSTANCE.getCompressionChainLength(); - if (size <= variantLimit) { + if (size <= chainLength) { return this; } var chain = new CompressionChain(); - chain.addAll(this.subList(0, variantLimit)); + chain.addAll(this.subList(0, chainLength)); return chain; } diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index a8a0bffb..d9677d31 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -68,18 +68,17 @@ repositories { dependencies { modImplementation(libs.fabric.loader) - modApi(libs.fabric.api) + modImplementation(libs.fabric.api) modImplementation(libs.ae2.fabric) + modImplementation(libs.cloth.fabric) modCompileOnly(libs.appbot.fabric) { exclude(group = "dev.emi", module = "emi-fabric") } modRuntimeOnly(libs.botania.fabric) { exclude(group = "dev.emi", module = "emi-fabric") } - // Still seems to have issues in dev environments - // modImplementation(libs.ae2wtlib.fabric) - // modRuntimeOnly(libs.cloth.fabric) + // modRuntimeOnly(libs.ae2wtlib.fabric) - modRuntimeOnly(libs.modmenu) + modImplementation(libs.modmenu) modRuntimeOnly(libs.jei.fabric) modRuntimeOnly(libs.jade.fabric) } diff --git a/fabric/src/data/java/gripe/_90/megacells/datagen/LocalisationProvider.java b/fabric/src/data/java/gripe/_90/megacells/datagen/LocalisationProvider.java index 8ef55790..62e726ab 100644 --- a/fabric/src/data/java/gripe/_90/megacells/datagen/LocalisationProvider.java +++ b/fabric/src/data/java/gripe/_90/megacells/datagen/LocalisationProvider.java @@ -3,6 +3,7 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; +import gripe._90.megacells.MEGACells; import gripe._90.megacells.definition.MEGABlocks; import gripe._90.megacells.definition.MEGAItems; import gripe._90.megacells.definition.MEGATranslations; @@ -20,5 +21,7 @@ public void generateTranslations(TranslationBuilder builder) { for (var translation : MEGATranslations.values()) { builder.add(translation.getTranslationKey(), translation.getEnglishText()); } + + builder.add("text.autoconfig.%s.title".formatted(MEGACells.MODID), MEGATranslations.ModName.getEnglishText()); } } diff --git a/fabric/src/main/java/gripe/_90/megacells/integration/modmenu/ModMenuIntegration.java b/fabric/src/main/java/gripe/_90/megacells/integration/modmenu/ModMenuIntegration.java new file mode 100644 index 00000000..ba23e3a7 --- /dev/null +++ b/fabric/src/main/java/gripe/_90/megacells/integration/modmenu/ModMenuIntegration.java @@ -0,0 +1,15 @@ +package gripe._90.megacells.integration.modmenu; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; + +import me.shedaniel.autoconfig.AutoConfig; + +import gripe._90.megacells.definition.MEGAConfig; + +public class ModMenuIntegration implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return parent -> AutoConfig.getConfigScreen(MEGAConfig.class, parent).get(); + } +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 1f425f53..62c6ff3a 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -18,6 +18,7 @@ "entrypoints": { "ae2": ["gripe._90.megacells.fabric.MEGACellsFabric"], "ae2:client": ["gripe._90.megacells.fabric.MEGACellsClient"], + "modmenu": ["gripe._90.megacells.integration.modmenu.ModMenuIntegration"], "fabric-datagen": ["gripe._90.megacells.datagen.MEGADataGenerators"] }, @@ -25,7 +26,8 @@ "depends": { "minecraft": "$minecraftVersion", - "ae2": ">=$ae2Version" + "ae2": ">=$ae2Version", + "cloth-config": "*" }, "suggests": { "ae2wtlib": ">=$ae2wtVersion", diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index f6361374..e61aac76 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -69,6 +69,7 @@ dependencies { forge(libs.forge) modImplementation(libs.ae2.forge) + modImplementation(libs.cloth.forge) modCompileOnly(libs.appmek) modCompileOnly(libs.mekanism) diff --git a/forge/src/data/java/gripe/_90/megacells/datagen/LocalisationProvider.java b/forge/src/data/java/gripe/_90/megacells/datagen/LocalisationProvider.java index b59dd1e3..3f64390f 100644 --- a/forge/src/data/java/gripe/_90/megacells/datagen/LocalisationProvider.java +++ b/forge/src/data/java/gripe/_90/megacells/datagen/LocalisationProvider.java @@ -21,5 +21,7 @@ protected void addTranslations() { for (var translation : MEGATranslations.values()) { add(translation.getTranslationKey(), translation.getEnglishText()); } + + add("text.autoconfig.%s.title".formatted(MEGACells.MODID), MEGATranslations.ModName.getEnglishText()); } } diff --git a/forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java b/forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java index 668e39a0..5d74bd8c 100644 --- a/forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java +++ b/forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java @@ -9,8 +9,10 @@ import net.minecraft.world.level.ItemLike; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.ConfigScreenHandler; import net.minecraftforge.client.event.ModelEvent; import net.minecraftforge.client.event.RegisterColorHandlersEvent; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -25,12 +27,15 @@ import appeng.items.storage.BasicStorageCell; import appeng.items.tools.powered.PortableCellItem; +import me.shedaniel.autoconfig.AutoConfig; + import gripe._90.megacells.MEGACells; import gripe._90.megacells.block.MEGACraftingUnitType; import gripe._90.megacells.client.render.MEGACraftingUnitModelProvider; import gripe._90.megacells.core.Addons; import gripe._90.megacells.definition.MEGABlockEntities; import gripe._90.megacells.definition.MEGABlocks; +import gripe._90.megacells.definition.MEGAConfig; import gripe._90.megacells.definition.MEGAItems; import gripe._90.megacells.integration.appbot.AppBotItems; import gripe._90.megacells.integration.appmek.AppMekItems; @@ -48,6 +53,14 @@ static void init() { bus.addListener(MEGACellsClient::initRenderTypes); bus.addListener(MEGACellsClient::initModels); bus.addListener(MEGACellsClient::initItemColors); + + // the absolute state + ModLoadingContext.get() + .registerExtensionPoint( + ConfigScreenHandler.ConfigScreenFactory.class, + () -> new ConfigScreenHandler.ConfigScreenFactory( + (client, parent) -> AutoConfig.getConfigScreen(MEGAConfig.class, parent) + .get())); } private static void initScreens(FMLClientSetupEvent ignoredEvent) { diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 657ad451..b0e95de9 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -42,6 +42,13 @@ description = "ME Greater Accumulation Cells - For when kilobytes just won't do. ordering = "AFTER" side = "BOTH" +[[dependencies.megacells]] + modId = "cloth_config" + mandatory = true + versionRange = "*" + ordering = "AFTER" + side = "BOTH" + [[dependencies.megacells]] modId = "minecraft" mandatory = true diff --git a/settings.gradle.kts b/settings.gradle.kts index 91330557..ae46c9f3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -27,16 +27,16 @@ dependencyResolutionManagement { library("ae2-fabric", "appeng", "appliedenergistics2-fabric").versionRef("ae2") library("ae2-forge", "appeng", "appliedenergistics2-forge").versionRef("ae2") + version("cloth-config", "11.1.106") + library("cloth-fabric", "me.shedaniel.cloth", "cloth-config-fabric").versionRef("cloth-config") + library("cloth-forge", "me.shedaniel.cloth", "cloth-config-forge").versionRef("cloth-config") + // AE2WTLib val ae2wtVersion = "15.0.1-beta" version("ae2wtlib", ae2wtVersion) library("ae2wtlib-fabric", "maven.modrinth", "applied-energistics-2-wireless-terminals").version("$ae2wtVersion-fabric") library("ae2wtlib-forge", "maven.modrinth", "applied-energistics-2-wireless-terminals").version("${ae2wtVersion}g-forge") - version("cloth-config", "11.1.106") - library("cloth-fabric", "me.shedaniel.cloth", "cloth-config-fabric").versionRef("cloth-config") - library("cloth-forge", "me.shedaniel.cloth", "cloth-config-forge").versionRef("cloth-config") - library("architectury-forge", "dev.architectury", "architectury-forge").version("9.1.10") library("curios", "top.theillusivec4.curios", "curios-forge").version("5.2.0-beta.3+$minecraftVersion")