fix: optional builder/dispatcher, moved cfg.pop

This commit is contained in:
ftbsc 2023-02-28 21:50:01 +01:00
parent c833568c4b
commit e3af53002f
2 changed files with 13 additions and 8 deletions

View file

@ -68,8 +68,6 @@ public abstract class AbstractModule implements IModule<AbstractModule.Group> {
return 1; return 1;
}) })
); );
this.getConfigBuilder().pop();
} }
protected void onEnabled() {} protected void onEnabled() {}

View file

@ -14,29 +14,36 @@ import net.minecraft.command.CommandSource;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
import java.util.HashSet; import java.util.HashSet;
import java.util.Optional;
import java.util.Set; import java.util.Set;
public class ModManager { public class ModManager {
private final ForgeConfigSpec.Builder cfgBuilder; private Optional<ForgeConfigSpec.Builder> cfgBuilder;
private final CommandDispatcher<CommandSource> dispatcher; private Optional<CommandDispatcher<CommandSource>> dispatcher;
public final Set<IModule<? extends Enum<?>> > mods; public final Set<IModule<? extends Enum<?>> > mods;
public ModManager(ForgeConfigSpec.Builder cfgBuilder, CommandDispatcher<CommandSource> dispatcher) { public ModManager(ForgeConfigSpec.Builder cfgBuilder, CommandDispatcher<CommandSource> dispatcher) {
this.cfgBuilder = cfgBuilder; this.cfgBuilder = Optional.of(cfgBuilder);
this.dispatcher = dispatcher; this.dispatcher = Optional.of(dispatcher);
this.mods = new HashSet<>(); this.mods = new HashSet<>();
} }
public void registerMod(IModule<? extends Enum<?>> mod) { public void registerMod(IModule<? extends Enum<?>> mod) {
this.mods.add(mod); this.mods.add(mod);
this.cfgBuilder.get().pop(); // TODO solved by AutoService, soon TM
}
public void finalize() {
this.cfgBuilder = Optional.empty();
this.dispatcher = Optional.empty();
} }
public ForgeConfigSpec.Builder getCfgBuilder() { public ForgeConfigSpec.Builder getCfgBuilder() {
return cfgBuilder; return cfgBuilder.get();
} }
public CommandDispatcher<CommandSource> getDispatcher() { public CommandDispatcher<CommandSource> getDispatcher() {
return dispatcher; return dispatcher.get();
} }
} }