mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-26 23:42:18 +00:00
Add a button to change monitor renderer in mod menu.
Probably useful for now.
This commit is contained in:
parent
52bb06d250
commit
f596af059d
@ -7,10 +7,18 @@ package dan200.computercraft.shared.integration;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import dan200.computercraft.shared.util.Config;
|
||||
import me.shedaniel.clothconfig2.api.ConfigBuilder;
|
||||
import me.shedaniel.clothconfig2.api.ConfigCategory;
|
||||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
// A stub modmenu entrypoint for when we get there
|
||||
// A poor mod menu integration just for testing the monitor rendering changes we've been making :)
|
||||
|
||||
@Environment( EnvType.CLIENT )
|
||||
public class ModMenuIntegration implements ModMenuApi
|
||||
@ -18,6 +26,27 @@ public class ModMenuIntegration implements ModMenuApi
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory()
|
||||
{
|
||||
return parent -> null;
|
||||
return parent -> {
|
||||
ConfigBuilder builder = ConfigBuilder.create().setParentScreen( parent )
|
||||
.setTitle( new LiteralText( "Computer Craft" ) )
|
||||
.setSavingRunnable( () -> {
|
||||
Config.clientSpec.correct( Config.clientConfig );
|
||||
Config.sync();
|
||||
Config.save();
|
||||
ComputerCraft.log.info( "Monitor renderer: {}", ComputerCraft.monitorRenderer );
|
||||
} );
|
||||
|
||||
ConfigCategory client = builder.getOrCreateCategory( new LiteralText( "Client" ) );
|
||||
|
||||
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
|
||||
|
||||
client.addEntry( entryBuilder.startEnumSelector( new LiteralText( "Monitor Renderer" ), MonitorRenderer.class, ComputerCraft.monitorRenderer )
|
||||
.setDefaultValue( MonitorRenderer.BEST )
|
||||
.setSaveConsumer( renderer -> { Config.clientConfig.set( "monitor_renderer", renderer ); } )
|
||||
.setTooltip( Text.of( Config.clientConfig.getComment( "monitor_renderer" ) ) )
|
||||
.build() );
|
||||
|
||||
return builder.build();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.util;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.electronwill.nightconfig.core.ConfigSpec;
|
||||
import com.electronwill.nightconfig.core.EnumGetMethod;
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
@ -39,11 +38,13 @@ public final class Config
|
||||
public static final CommentedConfigSpec serverSpec;
|
||||
public static final CommentedConfigSpec clientSpec;
|
||||
|
||||
public static CommentedConfig serverConfig;
|
||||
public static CommentedConfig clientConfig;
|
||||
public static CommentedFileConfig serverConfig;
|
||||
public static CommentedFileConfig clientConfig;
|
||||
|
||||
private static final WorldSavePath serverDir = WorldSavePathAccess.createWorldSavePath( "serverconfig" );
|
||||
private static final String serverFileName = "computercraft-server.toml";
|
||||
|
||||
private static Path serverPath = null;
|
||||
private static final Path clientPath = FabricLoader.INSTANCE.getConfigDir().resolve( "computercraft-client.toml" );
|
||||
|
||||
private Config()
|
||||
@ -243,7 +244,7 @@ public final class Config
|
||||
clientSpec.defineInRange( "monitor_distance", 64, 16, 1024 );
|
||||
}
|
||||
|
||||
private static final FileNotFoundAction MAKE_DIRECTORIES = ( file, configFormat ) -> {
|
||||
private static final FileNotFoundAction MAKE_DIRECTORIES_AND_FILE = ( file, configFormat ) -> {
|
||||
Files.createDirectories( file.getParent() );
|
||||
Files.createFile( file );
|
||||
configFormat.initEmptyFile( file );
|
||||
@ -253,14 +254,36 @@ public final class Config
|
||||
private static CommentedFileConfig buildFileConfig( Path path )
|
||||
{
|
||||
return CommentedFileConfig.builder( path )
|
||||
.onFileNotFound( MAKE_DIRECTORIES )
|
||||
.onFileNotFound( MAKE_DIRECTORIES_AND_FILE )
|
||||
.preserveInsertionOrder()
|
||||
.build();
|
||||
}
|
||||
|
||||
private static void saveConfig( UnmodifiableConfig config, CommentedConfigSpec spec, Path path )
|
||||
{
|
||||
try( CommentedFileConfig fileConfig = buildFileConfig( path ) )
|
||||
{
|
||||
fileConfig.putAll( config );
|
||||
spec.correct( fileConfig );
|
||||
fileConfig.save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void save()
|
||||
{
|
||||
if( clientConfig != null )
|
||||
{
|
||||
saveConfig( clientConfig, clientSpec, clientPath );
|
||||
}
|
||||
if( serverConfig != null && serverPath != null )
|
||||
{
|
||||
saveConfig( serverConfig, serverSpec, serverPath );
|
||||
}
|
||||
}
|
||||
|
||||
public static void serverStarting( MinecraftServer server )
|
||||
{
|
||||
Path serverPath = server.getSavePath( serverDir ).resolve( serverFileName );
|
||||
serverPath = server.getSavePath( serverDir ).resolve( serverFileName );
|
||||
|
||||
try( CommentedFileConfig config = buildFileConfig( serverPath ) )
|
||||
{
|
||||
@ -275,6 +298,7 @@ public final class Config
|
||||
public static void serverStopping( MinecraftServer server )
|
||||
{
|
||||
serverConfig = null;
|
||||
serverPath = null;
|
||||
}
|
||||
|
||||
public static void clientStarted( MinecraftClient client )
|
||||
|
Loading…
x
Reference in New Issue
Block a user