Skip to content

Commit

Permalink
Add config for max. compression chain length
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Sep 2, 2023
1 parent 59b44b5 commit dbf9eae
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 22 deletions.
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions common/src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +46,8 @@ public static ResourceLocation makeId(String path) {
}

public static void initCommon() {
MEGAConfig.load();

MEGAItems.init();
MEGABlocks.init();
MEGABlockEntities.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import appeng.api.stacks.AEItemKey;

import gripe._90.megacells.definition.MEGAConfig;

public class CompressionChain extends ObjectArrayList<CompressionVariant> {
public void add(AEItemKey item, int factor) {
this.add(new CompressionVariant(item, factor));
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 4 additions & 5 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 3 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
"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"]
},
"mixins": ["megacells.mixins.json"],

"depends": {
"minecraft": "$minecraftVersion",
"ae2": ">=$ae2Version"
"ae2": ">=$ae2Version",
"cloth-config": "*"
},
"suggests": {
"ae2wtlib": ">=$ae2wtVersion",
Expand Down
1 change: 1 addition & 0 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dependencies {
forge(libs.forge)

modImplementation(libs.ae2.forge)
modImplementation(libs.cloth.forge)

modCompileOnly(libs.appmek)
modCompileOnly(libs.mekanism)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
13 changes: 13 additions & 0 deletions forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit dbf9eae

Please sign in to comment.