|  | 
| 1 | 1 | package net.pedroksl.advanced_ae; | 
| 2 | 2 | 
 | 
| 3 |  | -import net.neoforged.bus.api.SubscribeEvent; | 
| 4 |  | -import net.neoforged.fml.common.EventBusSubscriber; | 
| 5 |  | -import net.neoforged.fml.event.config.ModConfigEvent; | 
|  | 3 | +import net.neoforged.fml.ModContainer; | 
|  | 4 | +import net.neoforged.fml.config.ModConfig; | 
| 6 | 5 | import net.neoforged.neoforge.common.ModConfigSpec; | 
| 7 | 6 | 
 | 
| 8 |  | -@EventBusSubscriber(modid = AdvancedAE.MOD_ID, bus = EventBusSubscriber.Bus.MOD) | 
| 9 | 7 | public class AAEConfig { | 
| 10 | 8 | 
 | 
| 11 |  | -    private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder(); | 
|  | 9 | +    private final AAEConfig.ClientConfig client = new AAEConfig.ClientConfig(); | 
|  | 10 | +    private final AAEConfig.CommonConfig common = new AAEConfig.CommonConfig(); | 
| 12 | 11 | 
 | 
| 13 |  | -    public static final ModConfigSpec SPEC = BUILDER.build(); | 
|  | 12 | +    private static AAEConfig INSTANCE; | 
| 14 | 13 | 
 | 
| 15 |  | -    @SubscribeEvent | 
| 16 |  | -    static void onLoad(final ModConfigEvent event) { | 
| 17 |  | -        if (event.getConfig().getSpec() == SPEC) {} | 
|  | 14 | +    AAEConfig(ModContainer container) { | 
|  | 15 | +        container.registerConfig(ModConfig.Type.CLIENT, client.spec); | 
|  | 16 | +        container.registerConfig(ModConfig.Type.COMMON, common.spec); | 
|  | 17 | +    } | 
|  | 18 | + | 
|  | 19 | +    public int getQuantumComputerMaxSize() { | 
|  | 20 | +        return common.quantumComputerMaxSize.get(); | 
|  | 21 | +    } | 
|  | 22 | + | 
|  | 23 | +    public int getQuantumComputerMaxMultiThreaders() { | 
|  | 24 | +        return common.quantumComputerMaxMultiThreaders.get(); | 
|  | 25 | +    } | 
|  | 26 | + | 
|  | 27 | +    public int getQuantumComputermaxDataEntanglers() { | 
|  | 28 | +        return common.quantumComputermaxDataEntanglers.get(); | 
|  | 29 | +    } | 
|  | 30 | + | 
|  | 31 | +    public int getQuantumComputerMultiThreaderMultiplication() { | 
|  | 32 | +        return common.quantumComputerMultiThreaderMultiplication.get(); | 
|  | 33 | +    } | 
|  | 34 | + | 
|  | 35 | +    public int getQuantumComputerDataEntanglerMultiplication() { | 
|  | 36 | +        return common.quantumComputerDataEntanglerMultiplication.get(); | 
|  | 37 | +    } | 
|  | 38 | + | 
|  | 39 | +    public void save() { | 
|  | 40 | +        common.spec.save(); | 
|  | 41 | +        client.spec.save(); | 
|  | 42 | +    } | 
|  | 43 | + | 
|  | 44 | +    public static void register(ModContainer container) { | 
|  | 45 | +        if (!container.getModId().equals(AdvancedAE.MOD_ID)) { | 
|  | 46 | +            throw new IllegalArgumentException(); | 
|  | 47 | +        } | 
|  | 48 | +        INSTANCE = new AAEConfig(container); | 
|  | 49 | +    } | 
|  | 50 | + | 
|  | 51 | +    public static AAEConfig instance() { | 
|  | 52 | +        return INSTANCE; | 
|  | 53 | +    } | 
|  | 54 | + | 
|  | 55 | +    private static class ClientConfig { | 
|  | 56 | +        private final ModConfigSpec spec; | 
|  | 57 | + | 
|  | 58 | +        public ClientConfig() { | 
|  | 59 | +            var builder = new ModConfigSpec.Builder(); | 
|  | 60 | + | 
|  | 61 | +            this.spec = builder.build(); | 
|  | 62 | +        } | 
|  | 63 | +    } | 
|  | 64 | + | 
|  | 65 | +    private static class CommonConfig { | 
|  | 66 | +        private final ModConfigSpec spec; | 
|  | 67 | + | 
|  | 68 | +        public final ModConfigSpec.IntValue quantumComputerMaxSize; | 
|  | 69 | +        public final ModConfigSpec.IntValue quantumComputerMaxMultiThreaders; | 
|  | 70 | +        public final ModConfigSpec.IntValue quantumComputermaxDataEntanglers; | 
|  | 71 | +        public final ModConfigSpec.IntValue quantumComputerMultiThreaderMultiplication; | 
|  | 72 | +        public final ModConfigSpec.IntValue quantumComputerDataEntanglerMultiplication; | 
|  | 73 | + | 
|  | 74 | +        public CommonConfig() { | 
|  | 75 | +            var builder = new ModConfigSpec.Builder(); | 
|  | 76 | + | 
|  | 77 | +            builder.push("quantum computer"); | 
|  | 78 | +            quantumComputerMaxSize = define( | 
|  | 79 | +                    builder, | 
|  | 80 | +                    "quantumComputerMaxSize", | 
|  | 81 | +                    5, | 
|  | 82 | +                    5, | 
|  | 83 | +                    16, | 
|  | 84 | +                    "Define the maximum dimensions of the Quantum Computer Multiblock."); | 
|  | 85 | +            quantumComputerMaxMultiThreaders = define( | 
|  | 86 | +                    builder, | 
|  | 87 | +                    "quantumComputerMaxMultiThreaders", | 
|  | 88 | +                    1, | 
|  | 89 | +                    0, | 
|  | 90 | +                    2, | 
|  | 91 | +                    "Define the maximum amount of multi threaders per Quantum Computer Multiblock."); | 
|  | 92 | +            quantumComputermaxDataEntanglers = define( | 
|  | 93 | +                    builder, | 
|  | 94 | +                    "quantumComputermaxDataEntanglers", | 
|  | 95 | +                    1, | 
|  | 96 | +                    0, | 
|  | 97 | +                    2, | 
|  | 98 | +                    "Define the maximum amount of Data Entanglers per Quantum Computer Multiblock."); | 
|  | 99 | +            quantumComputerMultiThreaderMultiplication = define( | 
|  | 100 | +                    builder, | 
|  | 101 | +                    "quantumComputerMultiThreaderMultiplication", | 
|  | 102 | +                    4, | 
|  | 103 | +                    2, | 
|  | 104 | +                    8, | 
|  | 105 | +                    "Define the multiplication factor of the multi threaders."); | 
|  | 106 | +            quantumComputerDataEntanglerMultiplication = define( | 
|  | 107 | +                    builder, | 
|  | 108 | +                    "quantumComputerDataEntanglerMultiplication", | 
|  | 109 | +                    4, | 
|  | 110 | +                    2, | 
|  | 111 | +                    8, | 
|  | 112 | +                    "Define the multiplication factor of the data entanglers."); | 
|  | 113 | +            builder.pop(); | 
|  | 114 | + | 
|  | 115 | +            this.spec = builder.build(); | 
|  | 116 | +        } | 
|  | 117 | + | 
|  | 118 | +        private static ModConfigSpec.IntValue define( | 
|  | 119 | +                ModConfigSpec.Builder builder, String name, int defaultValue, String comment) { | 
|  | 120 | +            builder.comment(comment); | 
|  | 121 | +            return define(builder, name, defaultValue); | 
|  | 122 | +        } | 
|  | 123 | + | 
|  | 124 | +        private static ModConfigSpec.IntValue define( | 
|  | 125 | +                ModConfigSpec.Builder builder, String name, int defaultValue, int min, int max, String comment) { | 
|  | 126 | +            builder.comment(comment); | 
|  | 127 | +            return define(builder, name, defaultValue, min, max); | 
|  | 128 | +        } | 
|  | 129 | + | 
|  | 130 | +        private static ModConfigSpec.IntValue define( | 
|  | 131 | +                ModConfigSpec.Builder builder, String name, int defaultValue, int min, int max) { | 
|  | 132 | +            return builder.defineInRange(name, defaultValue, min, max); | 
|  | 133 | +        } | 
|  | 134 | + | 
|  | 135 | +        private static ModConfigSpec.IntValue define(ModConfigSpec.Builder builder, String name, int defaultValue) { | 
|  | 136 | +            return define(builder, name, defaultValue, Integer.MIN_VALUE, Integer.MAX_VALUE); | 
|  | 137 | +        } | 
| 18 | 138 |     } | 
| 19 | 139 | } | 
0 commit comments