From a0bba060a85f04817ad4b4dea9c6ec77ce48057c Mon Sep 17 00:00:00 2001 From: pedroksl Date: Mon, 9 Sep 2024 20:45:57 -0300 Subject: [PATCH] Added configs for the quantum computer --- gradle.properties | 2 +- .../net/pedroksl/advanced_ae/AAEConfig.java | 138 ++++++++++++++++-- .../net/pedroksl/advanced_ae/AdvancedAE.java | 5 +- .../common/blocks/AAECraftingUnitType.java | 5 +- .../cluster/AdvCraftingCPUCalculator.java | 23 +-- .../xmod/emi/recipes/AAERecipeCategory.java | 2 +- 6 files changed, 150 insertions(+), 25 deletions(-) diff --git a/gradle.properties b/gradle.properties index dba5c05a..7e8322a9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ loader_version_range=[4,) mod_id=advanced_ae mod_name=Advanced AE mod_license=LGPL-3.0 -mod_version=0.4.1-1.21.1 +mod_version=0.4.2-1.21.1 mod_group_id=net.pedroksl.advanced_ae mod_authors=Pedroksl mod_description=This mod aims to expand on the added capabilities of Extended AE. diff --git a/src/main/java/net/pedroksl/advanced_ae/AAEConfig.java b/src/main/java/net/pedroksl/advanced_ae/AAEConfig.java index 91161957..2b9e8e84 100644 --- a/src/main/java/net/pedroksl/advanced_ae/AAEConfig.java +++ b/src/main/java/net/pedroksl/advanced_ae/AAEConfig.java @@ -1,19 +1,139 @@ package net.pedroksl.advanced_ae; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.EventBusSubscriber; -import net.neoforged.fml.event.config.ModConfigEvent; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.config.ModConfig; import net.neoforged.neoforge.common.ModConfigSpec; -@EventBusSubscriber(modid = AdvancedAE.MOD_ID, bus = EventBusSubscriber.Bus.MOD) public class AAEConfig { - private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder(); + private final AAEConfig.ClientConfig client = new AAEConfig.ClientConfig(); + private final AAEConfig.CommonConfig common = new AAEConfig.CommonConfig(); - public static final ModConfigSpec SPEC = BUILDER.build(); + private static AAEConfig INSTANCE; - @SubscribeEvent - static void onLoad(final ModConfigEvent event) { - if (event.getConfig().getSpec() == SPEC) {} + AAEConfig(ModContainer container) { + container.registerConfig(ModConfig.Type.CLIENT, client.spec); + container.registerConfig(ModConfig.Type.COMMON, common.spec); + } + + public int getQuantumComputerMaxSize() { + return common.quantumComputerMaxSize.get(); + } + + public int getQuantumComputerMaxMultiThreaders() { + return common.quantumComputerMaxMultiThreaders.get(); + } + + public int getQuantumComputermaxDataEntanglers() { + return common.quantumComputermaxDataEntanglers.get(); + } + + public int getQuantumComputerMultiThreaderMultiplication() { + return common.quantumComputerMultiThreaderMultiplication.get(); + } + + public int getQuantumComputerDataEntanglerMultiplication() { + return common.quantumComputerDataEntanglerMultiplication.get(); + } + + public void save() { + common.spec.save(); + client.spec.save(); + } + + public static void register(ModContainer container) { + if (!container.getModId().equals(AdvancedAE.MOD_ID)) { + throw new IllegalArgumentException(); + } + INSTANCE = new AAEConfig(container); + } + + public static AAEConfig instance() { + return INSTANCE; + } + + private static class ClientConfig { + private final ModConfigSpec spec; + + public ClientConfig() { + var builder = new ModConfigSpec.Builder(); + + this.spec = builder.build(); + } + } + + private static class CommonConfig { + private final ModConfigSpec spec; + + public final ModConfigSpec.IntValue quantumComputerMaxSize; + public final ModConfigSpec.IntValue quantumComputerMaxMultiThreaders; + public final ModConfigSpec.IntValue quantumComputermaxDataEntanglers; + public final ModConfigSpec.IntValue quantumComputerMultiThreaderMultiplication; + public final ModConfigSpec.IntValue quantumComputerDataEntanglerMultiplication; + + public CommonConfig() { + var builder = new ModConfigSpec.Builder(); + + builder.push("quantum computer"); + quantumComputerMaxSize = define( + builder, + "quantumComputerMaxSize", + 5, + 5, + 16, + "Define the maximum dimensions of the Quantum Computer Multiblock."); + quantumComputerMaxMultiThreaders = define( + builder, + "quantumComputerMaxMultiThreaders", + 1, + 0, + 2, + "Define the maximum amount of multi threaders per Quantum Computer Multiblock."); + quantumComputermaxDataEntanglers = define( + builder, + "quantumComputermaxDataEntanglers", + 1, + 0, + 2, + "Define the maximum amount of Data Entanglers per Quantum Computer Multiblock."); + quantumComputerMultiThreaderMultiplication = define( + builder, + "quantumComputerMultiThreaderMultiplication", + 4, + 2, + 8, + "Define the multiplication factor of the multi threaders."); + quantumComputerDataEntanglerMultiplication = define( + builder, + "quantumComputerDataEntanglerMultiplication", + 4, + 2, + 8, + "Define the multiplication factor of the data entanglers."); + builder.pop(); + + this.spec = builder.build(); + } + + private static ModConfigSpec.IntValue define( + ModConfigSpec.Builder builder, String name, int defaultValue, String comment) { + builder.comment(comment); + return define(builder, name, defaultValue); + } + + private static ModConfigSpec.IntValue define( + ModConfigSpec.Builder builder, String name, int defaultValue, int min, int max, String comment) { + builder.comment(comment); + return define(builder, name, defaultValue, min, max); + } + + private static ModConfigSpec.IntValue define( + ModConfigSpec.Builder builder, String name, int defaultValue, int min, int max) { + return builder.defineInRange(name, defaultValue, min, max); + } + + private static ModConfigSpec.IntValue define(ModConfigSpec.Builder builder, String name, int defaultValue) { + return define(builder, name, defaultValue, Integer.MIN_VALUE, Integer.MAX_VALUE); + } } } diff --git a/src/main/java/net/pedroksl/advanced_ae/AdvancedAE.java b/src/main/java/net/pedroksl/advanced_ae/AdvancedAE.java index 2711aa70..4df315e1 100644 --- a/src/main/java/net/pedroksl/advanced_ae/AdvancedAE.java +++ b/src/main/java/net/pedroksl/advanced_ae/AdvancedAE.java @@ -7,7 +7,6 @@ import net.neoforged.fml.ModList; import net.neoforged.fml.ModLoader; import net.neoforged.fml.common.Mod; -import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; @@ -42,6 +41,8 @@ public AdvancedAE(IEventBus eventBus, ModContainer container) { } INSTANCE = this; + AAEConfig.register(container); + AAEBlocks.DR.register(eventBus); AAEItems.DR.register(eventBus); AAEBlockEntities.DR.register(eventBus); @@ -52,8 +53,6 @@ public AdvancedAE(IEventBus eventBus, ModContainer container) { eventBus.addListener(AdvancedAE::initUpgrades); eventBus.addListener(AdvancedAE::initCapabilities); - container.registerConfig(ModConfig.Type.COMMON, AAEConfig.SPEC); - eventBus.addListener(AAENetworkHandler.INSTANCE::onRegister); eventBus.addListener((RegisterEvent event) -> { if (event.getRegistryKey() == Registries.RECIPE_TYPE) { diff --git a/src/main/java/net/pedroksl/advanced_ae/common/blocks/AAECraftingUnitType.java b/src/main/java/net/pedroksl/advanced_ae/common/blocks/AAECraftingUnitType.java index 94a87b4c..77bda5a4 100644 --- a/src/main/java/net/pedroksl/advanced_ae/common/blocks/AAECraftingUnitType.java +++ b/src/main/java/net/pedroksl/advanced_ae/common/blocks/AAECraftingUnitType.java @@ -1,6 +1,7 @@ package net.pedroksl.advanced_ae.common.blocks; import net.minecraft.world.item.Item; +import net.pedroksl.advanced_ae.AAEConfig; import net.pedroksl.advanced_ae.common.definitions.AAEBlocks; import appeng.block.crafting.ICraftingUnitType; @@ -30,7 +31,7 @@ public long getStorageBytes() { } public int getStorageMultiplier() { - return this == STORAGE_MULTIPLIER ? 4 : 0; + return this == STORAGE_MULTIPLIER ? AAEConfig.instance().getQuantumComputerDataEntanglerMultiplication() : 0; } @Override @@ -42,7 +43,7 @@ public int getAcceleratorThreads() { } public int getAccelerationMultiplier() { - return this == MULTI_THREADER ? 4 : 0; + return this == MULTI_THREADER ? AAEConfig.instance().getQuantumComputerMultiThreaderMultiplication() : 0; } public String getAffix() { diff --git a/src/main/java/net/pedroksl/advanced_ae/common/cluster/AdvCraftingCPUCalculator.java b/src/main/java/net/pedroksl/advanced_ae/common/cluster/AdvCraftingCPUCalculator.java index 064d0a6e..d91a34d2 100644 --- a/src/main/java/net/pedroksl/advanced_ae/common/cluster/AdvCraftingCPUCalculator.java +++ b/src/main/java/net/pedroksl/advanced_ae/common/cluster/AdvCraftingCPUCalculator.java @@ -5,6 +5,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.block.entity.BlockEntity; +import net.pedroksl.advanced_ae.AAEConfig; import net.pedroksl.advanced_ae.common.blocks.AAECraftingUnitType; import net.pedroksl.advanced_ae.common.entities.AdvCraftingBlockEntity; @@ -21,15 +22,17 @@ public AdvCraftingCPUCalculator(AdvCraftingBlockEntity t) { @Override public boolean checkMultiblockScale(BlockPos min, BlockPos max) { - if (max.getX() - min.getX() > 4) { + var maxSize = AAEConfig.instance().getQuantumComputerMaxSize() - 1; + + if (max.getX() - min.getX() > maxSize) { return false; } - if (max.getY() - min.getY() > 4) { + if (max.getY() - min.getY() > maxSize) { return false; } - return max.getZ() - min.getZ() <= 4; + return max.getZ() - min.getZ() <= maxSize; } @Override @@ -41,8 +44,10 @@ public AdvCraftingCPUCluster createCluster(ServerLevel level, BlockPos min, Bloc public boolean verifyInternalStructure(ServerLevel level, BlockPos min, BlockPos max) { boolean core = false; boolean storage = false; - boolean entangler = false; - boolean multi = false; + int entangler = 0; + int entanglerLimit = AAEConfig.instance().getQuantumComputermaxDataEntanglers(); + int multi = 0; + int multiLimit = AAEConfig.instance().getQuantumComputerMaxMultiThreaders(); for (BlockPos blockPos : BlockPos.betweenClosed(min, max)) { final IAEMultiBlock te = (IAEMultiBlock) level.getBlockEntity(blockPos); @@ -80,16 +85,16 @@ public boolean verifyInternalStructure(ServerLevel level, BlockPos min, BlockPos break; } case STORAGE_MULTIPLIER: { - if (!isBoundary && !entangler) { - entangler = true; + if (!isBoundary && entangler < entanglerLimit) { + entangler++; } else { return false; } break; } case MULTI_THREADER: { - if (!isBoundary && !multi) { - multi = true; + if (!isBoundary && multi < multiLimit) { + multi++; } else { return false; } diff --git a/src/main/java/net/pedroksl/advanced_ae/xmod/emi/recipes/AAERecipeCategory.java b/src/main/java/net/pedroksl/advanced_ae/xmod/emi/recipes/AAERecipeCategory.java index 45769d82..c655eb88 100644 --- a/src/main/java/net/pedroksl/advanced_ae/xmod/emi/recipes/AAERecipeCategory.java +++ b/src/main/java/net/pedroksl/advanced_ae/xmod/emi/recipes/AAERecipeCategory.java @@ -1,10 +1,10 @@ package net.pedroksl.advanced_ae.xmod.emi.recipes; import net.minecraft.network.chat.Component; +import net.pedroksl.advanced_ae.AdvancedAE; import dev.emi.emi.api.recipe.EmiRecipeCategory; import dev.emi.emi.api.render.EmiRenderable; -import net.pedroksl.advanced_ae.AdvancedAE; public class AAERecipeCategory extends EmiRecipeCategory { private final Component name;