1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-26 08:56:54 +00:00

Sync each config type separately

Forge checks for early access now which is sensible, but given we
sidestep Forge's ConfigValue system anyway, not very useful for us :D:.

Fixes #1117
This commit is contained in:
Jonathan Coates 2022-06-20 19:58:10 +01:00
parent a2e3d9d9bd
commit 8fc7820a12
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 14 additions and 11 deletions

View File

@ -6,5 +6,5 @@ mod_version=1.100.7
# Minecraft properties (update mods.toml when changing) # Minecraft properties (update mods.toml when changing)
mc_version=1.19 mc_version=1.19
mapping_version=2022.03.13 mapping_version=2022.03.13
forge_version=41.0.35 forge_version=41.0.38
# NO SERIOUSLY, UPDATE mods.toml WHEN CHANGING # NO SERIOUSLY, UPDATE mods.toml WHEN CHANGING

View File

@ -5,9 +5,7 @@
*/ */
package dan200.computercraft.shared; package dan200.computercraft.shared;
import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.UnmodifiableConfig; import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import com.google.common.base.Converter; import com.google.common.base.Converter;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
@ -291,7 +289,7 @@ public final class Config
ModLoadingContext.get().registerConfig( ModConfig.Type.CLIENT, clientSpec ); ModLoadingContext.get().registerConfig( ModConfig.Type.CLIENT, clientSpec );
} }
public static void sync() private static void syncServer()
{ {
// General // General
ComputerCraft.computerSpaceLimit = computerSpaceLimit.get(); ComputerCraft.computerSpaceLimit = computerSpaceLimit.get();
@ -343,26 +341,31 @@ public final class Config
ComputerCraft.pocketTermHeight = pocketTermHeight.get(); ComputerCraft.pocketTermHeight = pocketTermHeight.get();
ComputerCraft.monitorWidth = monitorWidth.get(); ComputerCraft.monitorWidth = monitorWidth.get();
ComputerCraft.monitorHeight = monitorHeight.get(); ComputerCraft.monitorHeight = monitorHeight.get();
}
// Client private static void syncClient()
{
ComputerCraft.monitorRenderer = monitorRenderer.get(); ComputerCraft.monitorRenderer = monitorRenderer.get();
ComputerCraft.monitorDistance = monitorDistance.get(); ComputerCraft.monitorDistance = monitorDistance.get();
} }
private static void sync( ModConfig config )
{
if( !config.getModId().equals( ComputerCraft.MOD_ID ) ) return;
if( config.getType() == ModConfig.Type.SERVER ) syncServer();
if( config.getType() == ModConfig.Type.CLIENT ) syncClient();
}
@SubscribeEvent @SubscribeEvent
public static void sync( ModConfigEvent.Loading event ) public static void sync( ModConfigEvent.Loading event )
{ {
sync(); sync( event.getConfig() );
} }
@SubscribeEvent @SubscribeEvent
public static void sync( ModConfigEvent.Reloading event ) public static void sync( ModConfigEvent.Reloading event )
{ {
// Ensure file configs are reloaded. Forge should probably do this, so worth checking in the future. sync( event.getConfig() );
CommentedConfig config = event.getConfig().getConfigData();
if( config instanceof CommentedFileConfig loadable ) loadable.load();
sync();
} }
private static final Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE ); private static final Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE );