Reformat everything

- Switch to a fairly standard code format. This is largely based on
   IntelliJ defaults, with some minor tweaks applied via editor config.
   Should mean people don't need to import a config!

 - Use "var" everywhere instead of explicit types. Type inference is a
   joy, and I intend to use it to its fullest.

 - Start using switch expressions: we couldn't use them before because
   IntelliJ does silly things with our previous brace style, but now we
   have the luxury of them!
This commit is contained in:
Jonathan Coates
2022-11-04 13:41:38 +00:00
parent 7df0412c2d
commit f478c4ffc4
557 changed files with 17468 additions and 27721 deletions
@@ -24,9 +24,8 @@ import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD )
public final class Config
{
@Mod.EventBusSubscriber(modid = ComputerCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public final class Config {
private static final int MODEM_MAX_RANGE = 100000;
private static final String TRANSLATION_PREFIX = "gui.computercraft.config.";
@@ -83,102 +82,138 @@ public final class Config
private static final ForgeConfigSpec serverSpec;
private static final ForgeConfigSpec clientSpec;
private Config() {}
private Config() {
}
static
{
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
static {
var builder = new ForgeConfigSpec.Builder();
{ // General computers
computerSpaceLimit = builder
.comment( "The disk space limit for computers and turtles, in bytes." )
.translation( TRANSLATION_PREFIX + "computer_space_limit" )
.define( "computer_space_limit", ComputerCraft.computerSpaceLimit );
.comment("The disk space limit for computers and turtles, in bytes.")
.translation(TRANSLATION_PREFIX + "computer_space_limit")
.define("computer_space_limit", ComputerCraft.computerSpaceLimit);
floppySpaceLimit = builder
.comment( "The disk space limit for floppy disks, in bytes." )
.translation( TRANSLATION_PREFIX + "floppy_space_limit" )
.define( "floppy_space_limit", ComputerCraft.floppySpaceLimit );
.comment("The disk space limit for floppy disks, in bytes.")
.translation(TRANSLATION_PREFIX + "floppy_space_limit")
.define("floppy_space_limit", ComputerCraft.floppySpaceLimit);
maximumFilesOpen = builder
.comment( "Set how many files a computer can have open at the same time. Set to 0 for unlimited." )
.translation( TRANSLATION_PREFIX + "maximum_open_files" )
.defineInRange( "maximum_open_files", ComputerCraft.maximumFilesOpen, 0, Integer.MAX_VALUE );
.comment("Set how many files a computer can have open at the same time. Set to 0 for unlimited.")
.translation(TRANSLATION_PREFIX + "maximum_open_files")
.defineInRange("maximum_open_files", ComputerCraft.maximumFilesOpen, 0, Integer.MAX_VALUE);
disableLua51Features = builder
.comment( "Set this to true to disable Lua 5.1 functions that will be removed in a future\nupdate. Useful for ensuring forward compatibility of your programs now." )
.define( "disable_lua51_features", ComputerCraft.disableLua51Features );
.comment("""
Set this to true to disable Lua 5.1 functions that will be removed in a future
update. Useful for ensuring forward compatibility of your programs now.""")
.define("disable_lua51_features", ComputerCraft.disableLua51Features);
defaultComputerSettings = builder
.comment( "A comma separated list of default system settings to set on new computers.\nExample: \"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\"\nwill disable all autocompletion." )
.define( "default_computer_settings", ComputerCraft.defaultComputerSettings );
.comment("""
A comma separated list of default system settings to set on new computers.
Example: "shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false"
will disable all autocompletion.""")
.define("default_computer_settings", ComputerCraft.defaultComputerSettings);
logComputerErrors = builder
.comment( "Log exceptions thrown by peripherals and other Lua objects. This makes it easier\nfor mod authors to debug problems, but may result in log spam should people use\nbuggy methods." )
.define( "log_computer_errors", ComputerCraft.logComputerErrors );
.comment("""
Log exceptions thrown by peripherals and other Lua objects. This makes it easier
for mod authors to debug problems, but may result in log spam should people use
buggy methods.""")
.define("log_computer_errors", ComputerCraft.logComputerErrors);
commandRequireCreative = builder
.comment( "Require players to be in creative mode and be opped in order to interact with\ncommand computers. This is the default behaviour for vanilla's Command blocks." ).define( "command_require_creative", ComputerCraft.commandRequireCreative );
.comment("""
Require players to be in creative mode and be opped in order to interact with
command computers. This is the default behaviour for vanilla's Command blocks.""")
.define("command_require_creative", ComputerCraft.commandRequireCreative);
}
{
builder.comment( "Controls execution behaviour of computers. This is largely intended for\nfine-tuning servers, and generally shouldn't need to be touched." );
builder.push( "execution" );
builder.comment("""
Controls execution behaviour of computers. This is largely intended for
fine-tuning servers, and generally shouldn't need to be touched.""");
builder.push("execution");
computerThreads = builder
.comment( "Set the number of threads computers can run on. A higher number means more\ncomputers can run at once, but may induce lag. Please note that some mods may\nnot work with a thread count higher than 1. Use with caution." )
.comment("""
Set the number of threads computers can run on. A higher number means more
computers can run at once, but may induce lag. Please note that some mods may
not work with a thread count higher than 1. Use with caution.""")
.worldRestart()
.defineInRange( "computer_threads", ComputerCraft.computerThreads, 1, Integer.MAX_VALUE );
.defineInRange("computer_threads", ComputerCraft.computerThreads, 1, Integer.MAX_VALUE);
maxMainGlobalTime = builder
.comment( "The maximum time that can be spent executing tasks in a single tick, in\nmilliseconds.\nNote, we will quite possibly go over this limit, as there's no way to tell how\nlong a will take - this aims to be the upper bound of the average time." )
.defineInRange( "max_main_global_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainGlobalTime ), 1, Integer.MAX_VALUE );
.comment("""
The maximum time that can be spent executing tasks in a single tick, in
milliseconds.
Note, we will quite possibly go over this limit, as there's no way to tell how
long a will take - this aims to be the upper bound of the average time.""")
.defineInRange("max_main_global_time", (int) TimeUnit.NANOSECONDS.toMillis(ComputerCraft.maxMainGlobalTime), 1, Integer.MAX_VALUE);
maxMainComputerTime = builder
.comment( "The ideal maximum time a computer can execute for in a tick, in milliseconds.\nNote, we will quite possibly go over this limit, as there's no way to tell how\nlong a will take - this aims to be the upper bound of the average time." )
.defineInRange( "max_main_computer_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainComputerTime ), 1, Integer.MAX_VALUE );
.comment("""
The ideal maximum time a computer can execute for in a tick, in milliseconds.
Note, we will quite possibly go over this limit, as there's no way to tell how
long a will take - this aims to be the upper bound of the average time.""")
.defineInRange("max_main_computer_time", (int) TimeUnit.NANOSECONDS.toMillis(ComputerCraft.maxMainComputerTime), 1, Integer.MAX_VALUE);
builder.pop();
}
{ // HTTP
builder.comment( "Controls the HTTP API" );
builder.push( "http" );
builder.comment("Controls the HTTP API");
builder.push("http");
httpEnabled = builder
.comment( "Enable the \"http\" API on Computers. This also disables the \"pastebin\" and \"wget\"\nprograms, that many users rely on. It's recommended to leave this on and use the\n\"rules\" config option to impose more fine-grained control." )
.define( "enabled", ComputerCraft.httpEnabled );
.comment("""
Enable the "http" API on Computers. This also disables the "pastebin" and "wget"
programs, that many users rely on. It's recommended to leave this on and use the
"rules" config option to impose more fine-grained control.""")
.define("enabled", ComputerCraft.httpEnabled);
httpWebsocketEnabled = builder
.comment( "Enable use of http websockets. This requires the \"http_enable\" option to also be true." )
.define( "websocket_enabled", ComputerCraft.httpWebsocketEnabled );
.comment("Enable use of http websockets. This requires the \"http_enable\" option to also be true.")
.define("websocket_enabled", ComputerCraft.httpWebsocketEnabled);
httpRules = builder
.comment( "A list of rules which control behaviour of the \"http\" API for specific domains or\nIPs. Each rule is an item with a 'host' to match against, and a series of\nproperties. Rules are evaluated in order, meaning earlier rules override later\nones.\nThe host may be a domain name (\"pastebin.com\"), wildcard (\"*.pastebin.com\") or\nCIDR notation (\"127.0.0.0/8\").\nIf no rules, the domain is blocked." )
.defineList( "rules", Arrays.asList(
AddressRuleConfig.makeRule( "$private", Action.DENY ),
AddressRuleConfig.makeRule( "*", Action.ALLOW )
), x -> x instanceof UnmodifiableConfig && AddressRuleConfig.checkRule( (UnmodifiableConfig) x ) );
.comment("""
A list of rules which control behaviour of the "http" API for specific domains or
IPs. Each rule is an item with a 'host' to match against, and a series of
properties. Rules are evaluated in order, meaning earlier rules override later
ones.
The host may be a domain name ("pastebin.com"), wildcard ("*.pastebin.com") or
CIDR notation ("127.0.0.0/8").
If no rules, the domain is blocked.""")
.defineList("rules", Arrays.asList(
AddressRuleConfig.makeRule("$private", Action.DENY),
AddressRuleConfig.makeRule("*", Action.ALLOW)
), x -> x instanceof UnmodifiableConfig && AddressRuleConfig.checkRule((UnmodifiableConfig) x));
httpMaxRequests = builder
.comment( "The number of http requests a computer can make at one time. Additional requests\nwill be queued, and sent when the running requests have finished. Set to 0 for\nunlimited." )
.defineInRange( "max_requests", ComputerCraft.httpMaxRequests, 0, Integer.MAX_VALUE );
.comment("""
The number of http requests a computer can make at one time. Additional requests
will be queued, and sent when the running requests have finished. Set to 0 for
unlimited.""")
.defineInRange("max_requests", ComputerCraft.httpMaxRequests, 0, Integer.MAX_VALUE);
httpMaxWebsockets = builder
.comment( "The number of websockets a computer can have open at one time. Set to 0 for unlimited." )
.defineInRange( "max_websockets", ComputerCraft.httpMaxWebsockets, 1, Integer.MAX_VALUE );
.comment("The number of websockets a computer can have open at one time. Set to 0 for unlimited.")
.defineInRange("max_websockets", ComputerCraft.httpMaxWebsockets, 1, Integer.MAX_VALUE);
builder
.comment( "Limits bandwidth used by computers." )
.push( "bandwidth" );
.comment("Limits bandwidth used by computers.")
.push("bandwidth");
httpDownloadBandwidth = builder
.comment( "The number of bytes which can be downloaded in a second. This is shared across all computers. (bytes/s)." )
.defineInRange( "global_download", ComputerCraft.httpDownloadBandwidth, 1, Integer.MAX_VALUE );
.comment("The number of bytes which can be downloaded in a second. This is shared across all computers. (bytes/s).")
.defineInRange("global_download", ComputerCraft.httpDownloadBandwidth, 1, Integer.MAX_VALUE);
httpUploadBandwidth = builder
.comment( "The number of bytes which can be uploaded in a second. This is shared across all computers. (bytes/s)." )
.defineInRange( "global_upload", ComputerCraft.httpUploadBandwidth, 1, Integer.MAX_VALUE );
.comment("The number of bytes which can be uploaded in a second. This is shared across all computers. (bytes/s).")
.defineInRange("global_upload", ComputerCraft.httpUploadBandwidth, 1, Integer.MAX_VALUE);
builder.pop();
@@ -186,84 +221,99 @@ public final class Config
}
{ // Peripherals
builder.comment( "Various options relating to peripherals." );
builder.push( "peripheral" );
builder.comment("Various options relating to peripherals.");
builder.push("peripheral");
commandBlockEnabled = builder
.comment( "Enable Command Block peripheral support" )
.define( "command_block_enabled", ComputerCraft.enableCommandBlock );
.comment("Enable Command Block peripheral support")
.define("command_block_enabled", ComputerCraft.enableCommandBlock);
modemRange = builder
.comment( "The range of Wireless Modems at low altitude in clear weather, in meters." )
.defineInRange( "modem_range", ComputerCraft.modemRange, 0, MODEM_MAX_RANGE );
.comment("The range of Wireless Modems at low altitude in clear weather, in meters.")
.defineInRange("modem_range", ComputerCraft.modemRange, 0, MODEM_MAX_RANGE);
modemHighAltitudeRange = builder
.comment( "The range of Wireless Modems at maximum altitude in clear weather, in meters." )
.defineInRange( "modem_high_altitude_range", ComputerCraft.modemHighAltitudeRange, 0, MODEM_MAX_RANGE );
.comment("The range of Wireless Modems at maximum altitude in clear weather, in meters.")
.defineInRange("modem_high_altitude_range", ComputerCraft.modemHighAltitudeRange, 0, MODEM_MAX_RANGE);
modemRangeDuringStorm = builder
.comment( "The range of Wireless Modems at low altitude in stormy weather, in meters." )
.defineInRange( "modem_range_during_storm", ComputerCraft.modemRangeDuringStorm, 0, MODEM_MAX_RANGE );
.comment("The range of Wireless Modems at low altitude in stormy weather, in meters.")
.defineInRange("modem_range_during_storm", ComputerCraft.modemRangeDuringStorm, 0, MODEM_MAX_RANGE);
modemHighAltitudeRangeDuringStorm = builder
.comment( "The range of Wireless Modems at maximum altitude in stormy weather, in meters." )
.defineInRange( "modem_high_altitude_range_during_storm", ComputerCraft.modemHighAltitudeRangeDuringStorm, 0, MODEM_MAX_RANGE );
.comment("The range of Wireless Modems at maximum altitude in stormy weather, in meters.")
.defineInRange("modem_high_altitude_range_during_storm", ComputerCraft.modemHighAltitudeRangeDuringStorm, 0, MODEM_MAX_RANGE);
maxNotesPerTick = builder
.comment( "Maximum amount of notes a speaker can play at once." )
.defineInRange( "max_notes_per_tick", ComputerCraft.maxNotesPerTick, 1, Integer.MAX_VALUE );
.comment("Maximum amount of notes a speaker can play at once.")
.defineInRange("max_notes_per_tick", ComputerCraft.maxNotesPerTick, 1, Integer.MAX_VALUE);
monitorBandwidth = builder
.comment( "The limit to how much monitor data can be sent *per tick*. Note:\n - Bandwidth is measured before compression, so the data sent to the client is\n smaller.\n - This ignores the number of players a packet is sent to. Updating a monitor for\n one player consumes the same bandwidth limit as sending to 20.\n - A full sized monitor sends ~25kb of data. So the default (1MB) allows for ~40\n monitors to be updated in a single tick.\nSet to 0 to disable." )
.defineInRange( "monitor_bandwidth", (int) ComputerCraft.monitorBandwidth, 0, Integer.MAX_VALUE );
.comment("""
The limit to how much monitor data can be sent *per tick*. Note:
- Bandwidth is measured before compression, so the data sent to the client is
smaller.
- This ignores the number of players a packet is sent to. Updating a monitor for
one player consumes the same bandwidth limit as sending to 20.
- A full sized monitor sends ~25kb of data. So the default (1MB) allows for ~40
monitors to be updated in a single tick.
Set to 0 to disable.""")
.defineInRange("monitor_bandwidth", (int) ComputerCraft.monitorBandwidth, 0, Integer.MAX_VALUE);
builder.pop();
}
{ // Turtles
builder.comment( "Various options relating to turtles." );
builder.push( "turtle" );
builder.comment("Various options relating to turtles.");
builder.push("turtle");
turtlesNeedFuel = builder
.comment( "Set whether Turtles require fuel to move." )
.define( "need_fuel", ComputerCraft.turtlesNeedFuel );
.comment("Set whether Turtles require fuel to move.")
.define("need_fuel", ComputerCraft.turtlesNeedFuel);
turtleFuelLimit = builder
.comment( "The fuel limit for Turtles." )
.defineInRange( "normal_fuel_limit", ComputerCraft.turtleFuelLimit, 0, Integer.MAX_VALUE );
.comment("The fuel limit for Turtles.")
.defineInRange("normal_fuel_limit", ComputerCraft.turtleFuelLimit, 0, Integer.MAX_VALUE);
advancedTurtleFuelLimit = builder
.comment( "The fuel limit for Advanced Turtles." )
.defineInRange( "advanced_fuel_limit", ComputerCraft.advancedTurtleFuelLimit, 0, Integer.MAX_VALUE );
.comment("The fuel limit for Advanced Turtles.")
.defineInRange("advanced_fuel_limit", ComputerCraft.advancedTurtleFuelLimit, 0, Integer.MAX_VALUE);
turtlesObeyBlockProtection = builder
.comment( "If set to true, Turtles will be unable to build, dig, or enter protected areas\n(such as near the server spawn point)." )
.define( "obey_block_protection", ComputerCraft.turtlesObeyBlockProtection );
.comment("""
If set to true, Turtles will be unable to build, dig, or enter protected areas
(such as near the server spawn point).""")
.define("obey_block_protection", ComputerCraft.turtlesObeyBlockProtection);
turtlesCanPush = builder
.comment( "If set to true, Turtles will push entities out of the way instead of stopping if\n" +
"there is space to do so." )
.define( "can_push", ComputerCraft.turtlesCanPush );
.comment("""
If set to true, Turtles will push entities out of the way instead of stopping if
there is space to do so.""")
.define("can_push", ComputerCraft.turtlesCanPush);
builder.pop();
}
{
builder.comment( "Configure the size of various computer's terminals.\nLarger terminals require more bandwidth, so use with care." ).push( "term_sizes" );
builder
.comment("""
Configure the size of various computer's terminals.
Larger terminals require more bandwidth, so use with care.""")
.push("term_sizes");
builder.comment( "Terminal size of computers." ).push( "computer" );
computerTermWidth = builder.defineInRange( "width", ComputerCraft.computerTermWidth, 1, 255 );
computerTermHeight = builder.defineInRange( "height", ComputerCraft.computerTermHeight, 1, 255 );
builder.comment("Terminal size of computers.").push("computer");
computerTermWidth = builder.defineInRange("width", ComputerCraft.computerTermWidth, 1, 255);
computerTermHeight = builder.defineInRange("height", ComputerCraft.computerTermHeight, 1, 255);
builder.pop();
builder.comment( "Terminal size of pocket computers." ).push( "pocket_computer" );
pocketTermWidth = builder.defineInRange( "width", ComputerCraft.pocketTermWidth, 1, 255 );
pocketTermHeight = builder.defineInRange( "height", ComputerCraft.pocketTermHeight, 1, 255 );
builder.comment("Terminal size of pocket computers.").push("pocket_computer");
pocketTermWidth = builder.defineInRange("width", ComputerCraft.pocketTermWidth, 1, 255);
pocketTermHeight = builder.defineInRange("height", ComputerCraft.pocketTermHeight, 1, 255);
builder.pop();
builder.comment( "Maximum size of monitors (in blocks)." ).push( "monitor" );
monitorWidth = builder.defineInRange( "width", ComputerCraft.monitorWidth, 1, 32 );
monitorHeight = builder.defineInRange( "height", ComputerCraft.monitorHeight, 1, 32 );
builder.comment("Maximum size of monitors (in blocks).").push("monitor");
monitorWidth = builder.defineInRange("width", ComputerCraft.monitorWidth, 1, 32);
monitorHeight = builder.defineInRange("height", ComputerCraft.monitorHeight, 1, 32);
builder.pop();
builder.pop();
@@ -271,28 +321,31 @@ public final class Config
serverSpec = builder.build();
ForgeConfigSpec.Builder clientBuilder = new ForgeConfigSpec.Builder();
var clientBuilder = new ForgeConfigSpec.Builder();
monitorRenderer = clientBuilder
.comment( "The renderer to use for monitors. Generally this should be kept at \"best\" - if\nmonitors have performance issues, you may wish to experiment with alternative\nrenderers." )
.defineEnum( "monitor_renderer", MonitorRenderer.BEST );
.comment("""
The renderer to use for monitors. Generally this should be kept at "best" - if
monitors have performance issues, you may wish to experiment with alternative
renderers.""")
.defineEnum("monitor_renderer", MonitorRenderer.BEST);
monitorDistance = clientBuilder
.comment( "The maximum distance monitors will render at. This defaults to the standard tile\nentity limit, but may be extended if you wish to build larger monitors." )
.defineInRange( "monitor_distance", 64, 16, 1024 );
.comment("""
The maximum distance monitors will render at. This defaults to the standard tile
entity limit, but may be extended if you wish to build larger monitors.""")
.defineInRange("monitor_distance", 64, 16, 1024);
uploadNagDelay = clientBuilder
.comment( "The delay in seconds after which we'll notify about unhandled imports. Set to 0 to disable." )
.defineInRange( "upload_nag_delay", ComputerCraft.uploadNagDelay, 0, 60 );
.comment("The delay in seconds after which we'll notify about unhandled imports. Set to 0 to disable.")
.defineInRange("upload_nag_delay", ComputerCraft.uploadNagDelay, 0, 60);
clientSpec = clientBuilder.build();
}
public static void setup()
{
ModLoadingContext.get().registerConfig( ModConfig.Type.SERVER, serverSpec );
ModLoadingContext.get().registerConfig( ModConfig.Type.CLIENT, clientSpec );
public static void setup() {
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, serverSpec);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, clientSpec);
}
private static void syncServer()
{
private static void syncServer() {
// General
ComputerCraft.computerSpaceLimit = computerSpaceLimit.get();
ComputerCraft.floppySpaceLimit = floppySpaceLimit.get();
@@ -305,14 +358,14 @@ public final class Config
// Execution
ComputerCraft.computerThreads = computerThreads.get();
ComputerCraft.maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( maxMainGlobalTime.get() );
ComputerCraft.maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos( maxMainComputerTime.get() );
ComputerCraft.maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos(maxMainGlobalTime.get());
ComputerCraft.maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos(maxMainComputerTime.get());
// HTTP
ComputerCraft.httpEnabled = httpEnabled.get();
ComputerCraft.httpWebsocketEnabled = httpWebsocketEnabled.get();
ComputerCraft.httpRules = httpRules.get().stream()
.map( AddressRuleConfig::parseRule ).filter( Objects::nonNull ).toList();
.map(AddressRuleConfig::parseRule).filter(Objects::nonNull).toList();
ComputerCraft.httpMaxRequests = httpMaxRequests.get();
ComputerCraft.httpMaxWebsockets = httpMaxWebsockets.get();
@@ -345,29 +398,25 @@ public final class Config
ComputerCraft.monitorHeight = monitorHeight.get();
}
private static void syncClient()
{
private static void syncClient() {
ComputerCraft.monitorRenderer = monitorRenderer.get();
ComputerCraft.monitorDistance = monitorDistance.get();
ComputerCraft.uploadNagDelay = uploadNagDelay.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();
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
public static void sync( ModConfigEvent.Loading event )
{
sync( event.getConfig() );
public static void sync(ModConfigEvent.Loading event) {
sync(event.getConfig());
}
@SubscribeEvent
public static void sync( ModConfigEvent.Reloading event )
{
sync( event.getConfig() );
public static void sync(ModConfigEvent.Reloading event) {
sync(event.getConfig());
}
}