+
+
+
diff --git a/config/license/api.txt b/config/license/api.txt
new file mode 100644
index 000000000..5c1d391fe
--- /dev/null
+++ b/config/license/api.txt
@@ -0,0 +1,3 @@
+This file is part of the public ComputerCraft API - http://www.computercraft.info
+Copyright Daniel Ratcliffe, 2011-${year}. This API may be redistributed unmodified and in full only.
+For help using the API, and posting your mods, visit the forums at computercraft.info.
diff --git a/config/license/main.txt b/config/license/main.txt
new file mode 100644
index 000000000..bab494b2e
--- /dev/null
+++ b/config/license/main.txt
@@ -0,0 +1,3 @@
+This file is part of ComputerCraft - http://www.computercraft.info
+Copyright Daniel Ratcliffe, 2011-${year}. Do not distribute without permission.
+Send enquiries to dratcliffe@gmail.com
diff --git a/config/pre-commit/config.yml b/config/pre-commit/config.yml
new file mode 100644
index 000000000..6d16e1978
--- /dev/null
+++ b/config/pre-commit/config.yml
@@ -0,0 +1,49 @@
+# See https://pre-commit.com for more information
+# See https://pre-commit.com/hooks.html for more hooks
+repos:
+- repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v3.2.0
+ hooks:
+ - id: trailing-whitespace
+ - id: end-of-file-fixer
+ - id: check-merge-conflict
+
+ # Quick syntax checkers
+ - id: check-xml
+ - id: check-yaml
+ - id: check-toml
+ - id: check-json
+ exclude: "tsconfig\\.json$"
+
+- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
+ rev: 2.3.5
+ hooks:
+ - id: editorconfig-checker
+ args: ['-disable-indentation']
+ exclude: "^(.*\\.(bat)|LICENSE)$"
+
+- repo: local
+ hooks:
+ - id: checkstyle
+ name: Check Java codestyle
+ files: ".*\\.java$"
+ language: system
+ entry: ./gradlew checkstyleMain checkstyleTest
+ pass_filenames: false
+ require_serial: true
+ - id: license
+ name: Check Java license headers
+ files: ".*\\.java$"
+ language: system
+ entry: ./gradlew licenseFormat
+ pass_filenames: false
+ require_serial: true
+
+exclude: |
+ (?x)^(
+ src/generated|
+ src/test/resources/test-rom/data/json-parsing/|
+ src/test/server-files/|
+ config/idea/|
+ .vscode/
+ )
diff --git a/config/pre-commit/illuaminate-lint.sh b/config/pre-commit/illuaminate-lint.sh
new file mode 100755
index 000000000..ac7b762bf
--- /dev/null
+++ b/config/pre-commit/illuaminate-lint.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env sh
+set -e
+
+test -d bin || mkdir bin
+test -f bin/illuaminate || curl -s -obin/illuaminate https://squiddev.cc/illuaminate/linux-x86-64/illuaminate
+chmod +x bin/illuaminate
+
+if [ -n ${GITHUB_ACTIONS+x} ]; then
+ # Register a problem matcher (see https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md)
+ # for illuaminate.
+ echo "::add-matcher::.github/matchers/illuaminate.json"
+ trap 'echo "::remove-matcher owner=illuaminate::"' EXIT
+fi
+
+./gradlew luaJavadoc
+bin/illuaminate lint
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 5c2d1cf01..e708b1c02 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index b343370e3..549d84424 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Tue Jul 07 13:15:43 EDT 2020
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index cccdd3d51..4f906e0c8 100755
--- a/gradlew
+++ b/gradlew
@@ -1,5 +1,21 @@
#!/usr/bin/env sh
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
##############################################################################
##
## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
@@ -66,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
@@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
- i=$((i+1))
+ i=`expr $i + 1`
done
case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
@@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
-APP_ARGS=$(save "$@")
+APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
-# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
- cd "$(dirname "$0")"
-fi
-
exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index f9553162f..107acd32c 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -1,3 +1,19 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
+if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -35,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-if exist "%JAVA_EXE%" goto init
+if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -45,28 +64,14 @@ echo location of your Java installation.
goto fail
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
diff --git a/patchwork.md b/patchwork.md
index 40372bb64..15f604097 100644
--- a/patchwork.md
+++ b/patchwork.md
@@ -9,7 +9,7 @@ SubScript // Desc of commit
```
If a edit that is present in CC:T is not needed, I will skip over it.
-Any and all references to an issue number, are to be found on CC:T's repo.
+Any and all references to an issue number, are to be found on CC:T's repo.
Any commit that starts with `[Patchwork]` are purely edits made by my hand, and not based on other commits from CC:T, this is to help differentiate my changes from the official changes
@@ -138,9 +138,9 @@ evidently need to lint examples too.
Add color table to docs (#553)
```
-All API Documentation updates,
+All API Documentation updates,
`Not Needed` for this repo.
-```
+```
93068402a2ffec00eedb8fe2d859ebdc005a1989
Document remaining OS functions (#554)
@@ -148,7 +148,7 @@ Document remaining OS functions (#554)
Update illuaminate CSS for deprecation (#556)
```
-```
+```
Not Needed
4766833cf2d041ed179529eecb9402ad09b2b79b
Bump JEI/crafttweaker versions
@@ -156,12 +156,12 @@ Bump JEI/crafttweaker versions
In my defence, they weren't out when I started the 1.15 update.
```
-```
+```
bf6053906dc6a3c7b0d40d5b097e745dce1f33bc
Fix TBO norm issues on old GPUs
```
-```
+```
Not Needed
113b560a201dbdea9de2a2ef536bcce1d6e51978
Update configuration to match latest illuaminate
@@ -201,7 +201,7 @@ to expose this.
Closes #452
```
-```
+```
Not Needed
6aae4e576621090840724e094aa25e51696530fc
Remove superfluous imports
@@ -210,7 +210,7 @@ Hah, this is embarassing
```
[TODO] [M3R1-01] Code has been applied, players still dont get achievments
-```
+```
f6160bdc57b3d9850607c2c7c2ce9734b4963478
Fix players not getting advancements when they own turtles
@@ -228,7 +228,7 @@ resolve this properly.
Fixes #564
```
-```
+```
17a932920711a5c0361a5048c9e0a5e7a58e6364
Bump cct-javadoc version
@@ -245,7 +245,7 @@ Tesselator, but this'll do for now.
Fixes Zundrel/cc-tweaked-fabric#20.
```
-```
+```
c58441b29c3715f092e7f3747bb3ec65ae5a3d29
Various SNBT parsing improvements
@@ -257,7 +257,7 @@ Correctly handle:
Fixes #559
```
-```
+```
e2a635b6e5f5942f999213434054e06833c5cb06
Dont fail when codecov is being finicky
```
@@ -270,13 +270,13 @@ Maybe I should run the whole test suite, not just the things I think
matter? Nah....
```
-```
+```
741adfa7bb2b950d2851c3f0072d6a4769f22773
Use blit to draw boxes, add colors.toBlit (#570)
```
-```
+```
d13bd2cce8d102ad7f61f557e707d6fe3731bc37
use arg[0] in all usage printouts (#571)
@@ -289,7 +289,7 @@ Bump to 1.94.0
```
[TODO] [M3R1-02] Zero Clue how to reimplement this in fabric.
-```
+```
c8aeddedd4ed430f9cb6428676ebb4fa39834182
Auto-generate monitor models
@@ -399,7 +399,7 @@ Hopefully fixes #585. Hopefully.
```
511eea39a11956c82e2c11a47b2e7cad27f9887e
-Remove s in usages
+Remove s in usages
```
```
@@ -426,7 +426,7 @@ Didn't port the lua tests over.
```
737b3cb57696fb5517252e7db38bc88ce960b4d8
-Don't use capabilities for generic peripherals
+Don't use capabilities for generic peripherals
```
Not ported, related to forges capability system which is not used in the port.
diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java
index 0e5ff357b..c77ba5d3c 100644
--- a/src/main/java/dan200/computercraft/ComputerCraft.java
+++ b/src/main/java/dan200/computercraft/ComputerCraft.java
@@ -6,15 +6,6 @@
package dan200.computercraft;
-import static dan200.computercraft.shared.ComputerCraftRegistry.ModBlocks;
-import static dan200.computercraft.shared.ComputerCraftRegistry.init;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
import dan200.computercraft.api.turtle.event.TurtleAction;
import dan200.computercraft.core.apis.http.options.Action;
import dan200.computercraft.core.apis.http.options.AddressRule;
@@ -32,22 +23,31 @@ import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
import dan200.computercraft.shared.turtle.recipes.TurtleRecipe;
import dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe;
-import dan200.computercraft.shared.util.*;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import net.minecraft.item.ItemGroup;
-import net.minecraft.item.ItemStack;
-import net.minecraft.util.Identifier;
-import net.minecraft.util.registry.Registry;
-
+import dan200.computercraft.shared.util.ImpostorRecipe;
+import dan200.computercraft.shared.util.ImpostorShapelessRecipe;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
+import net.minecraft.item.ItemGroup;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.registry.Registry;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
-public final class ComputerCraft implements ModInitializer {
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static dan200.computercraft.shared.ComputerCraftRegistry.ModBlocks;
+import static dan200.computercraft.shared.ComputerCraftRegistry.init;
+
+public final class ComputerCraft implements ModInitializer
+{
public static final String MOD_ID = "computercraft";
// Configuration fields
@@ -61,16 +61,15 @@ public final class ComputerCraft implements ModInitializer {
public static boolean commandRequireCreative = true;
public static int computerThreads = 1;
- public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos(10);
- public static long maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos(5);
+ public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( 10 );
+ public static long maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos( 5 );
public static boolean httpEnabled = true;
public static boolean httpWebsocketEnabled = true;
public static List httpRules = Collections.unmodifiableList( Arrays.asList(
- AddressRule.parse( "$private", null, Action.DENY.toPartial() ),
- AddressRule.parse( "*", null, Action.ALLOW.toPartial() )
- ));
-
+ AddressRule.parse( "$private", null, Action.DENY.toPartial() ),
+ AddressRule.parse( "*", null, Action.ALLOW.toPartial() )
+ ) );
public static int httpMaxRequests = 16;
public static int httpMaxWebsockets = 4;
@@ -89,7 +88,7 @@ public final class ComputerCraft implements ModInitializer {
public static int advancedTurtleFuelLimit = 100000;
public static boolean turtlesObeyBlockProtection = true;
public static boolean turtlesCanPush = true;
- public static EnumSet turtleDisabledActions = EnumSet.noneOf(TurtleAction.class);
+ public static EnumSet turtleDisabledActions = EnumSet.noneOf( TurtleAction.class );
public static int computerTermWidth = 51;
public static int computerTermHeight = 19;
@@ -99,7 +98,6 @@ public final class ComputerCraft implements ModInitializer {
public static int pocketTermWidth = 26;
public static int pocketTermHeight = 20;
-
public static int monitorWidth = 8;
public static int monitorHeight = 6;
@@ -108,30 +106,32 @@ public final class ComputerCraft implements ModInitializer {
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
// Logging
- public static final Logger log = LogManager.getLogger(MOD_ID);
+ public static final Logger log = LogManager.getLogger( MOD_ID );
- public static ItemGroup MAIN_GROUP = FabricItemGroupBuilder.build(new Identifier(MOD_ID, "main"), () -> new ItemStack(ModBlocks.COMPUTER_NORMAL));
+ public static ItemGroup MAIN_GROUP = FabricItemGroupBuilder.build( new Identifier( MOD_ID, "main" ), () -> new ItemStack( ModBlocks.COMPUTER_NORMAL ) );
@Override
- public void onInitialize() {
+ public void onInitialize()
+ {
ComputerCraftProxyCommon.init();
-
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "colour"), ColourableRecipe.SERIALIZER);
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "computer_upgrade"), ComputerUpgradeRecipe.SERIALIZER);
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "pocket_computer_upgrade"), PocketComputerUpgradeRecipe.SERIALIZER);
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "disk"), DiskRecipe.SERIALIZER);
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "printout"), PrintoutRecipe.SERIALIZER);
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "turtle"), TurtleRecipe.SERIALIZER);
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "turtle_upgrade"), TurtleUpgradeRecipe.SERIALIZER);
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "impostor_shaped"), ImpostorRecipe.SERIALIZER);
- Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(ComputerCraft.MOD_ID, "impostor_shapeless"), ImpostorShapelessRecipe.SERIALIZER);
- Registry.register(Registry.LOOT_CONDITION_TYPE, new Identifier(ComputerCraft.MOD_ID, "block_named"), BlockNamedEntityLootCondition.TYPE);
- Registry.register(Registry.LOOT_CONDITION_TYPE, new Identifier(ComputerCraft.MOD_ID, "player_creative"), PlayerCreativeLootCondition.TYPE);
- Registry.register(Registry.LOOT_CONDITION_TYPE, new Identifier(ComputerCraft.MOD_ID, "has_id"), HasComputerIdLootCondition.TYPE);
+ Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "colour" ), ColourableRecipe.SERIALIZER );
+ Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "computer_upgrade" ), ComputerUpgradeRecipe.SERIALIZER );
+ Registry.register( Registry.RECIPE_SERIALIZER,
+ new Identifier( ComputerCraft.MOD_ID, "pocket_computer_upgrade" ),
+ PocketComputerUpgradeRecipe.SERIALIZER );
+ Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "disk" ), DiskRecipe.SERIALIZER );
+ Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "printout" ), PrintoutRecipe.SERIALIZER );
+ Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "turtle" ), TurtleRecipe.SERIALIZER );
+ Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "turtle_upgrade" ), TurtleUpgradeRecipe.SERIALIZER );
+ Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "impostor_shaped" ), ImpostorRecipe.SERIALIZER );
+ Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "impostor_shapeless" ), ImpostorShapelessRecipe.SERIALIZER );
+ Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "block_named" ), BlockNamedEntityLootCondition.TYPE );
+ Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "player_creative" ), PlayerCreativeLootCondition.TYPE );
+ Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "has_id" ), HasComputerIdLootCondition.TYPE );
init();
- FabricLoader.getInstance().getModContainer(MOD_ID).ifPresent(modContainer -> {
- ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID, "classic"), modContainer, ResourcePackActivationType.NORMAL);
- ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID, "overhaul"), modContainer, ResourcePackActivationType.NORMAL);
- });
+ FabricLoader.getInstance().getModContainer( MOD_ID ).ifPresent( modContainer -> {
+ ResourceManagerHelper.registerBuiltinResourcePack( new Identifier( MOD_ID, "classic" ), modContainer, ResourcePackActivationType.NORMAL );
+ ResourceManagerHelper.registerBuiltinResourcePack( new Identifier( MOD_ID, "overhaul" ), modContainer, ResourcePackActivationType.NORMAL );
+ } );
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java
index 7176f3e61..f7e630d02 100644
--- a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java
+++ b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java
@@ -6,13 +6,6 @@
package dan200.computercraft;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import dan200.computercraft.api.ComputerCraftAPI.IComputerCraftAPI;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
@@ -31,18 +24,14 @@ import dan200.computercraft.core.asm.GenericMethod;
import dan200.computercraft.core.filesystem.FileMount;
import dan200.computercraft.core.filesystem.ResourceMount;
import dan200.computercraft.fabric.mixin.MinecraftServerAccess;
-import dan200.computercraft.shared.BundledRedstone;
-import dan200.computercraft.shared.MediaProviders;
-import dan200.computercraft.shared.Peripherals;
-import dan200.computercraft.shared.PocketUpgrades;
-import dan200.computercraft.shared.TurtleUpgrades;
+import dan200.computercraft.shared.*;
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
import dan200.computercraft.shared.peripheral.modem.wired.TileWiredModemFull;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import dan200.computercraft.shared.util.IDAssigner;
import dan200.computercraft.shared.wired.WiredNode;
import me.shedaniel.cloth.api.utils.v1.GameInstanceUtils;
-
+import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.server.MinecraftServer;
@@ -52,24 +41,35 @@ import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
-import net.fabricmc.loader.api.FabricLoader;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
-public final class ComputerCraftAPIImpl implements IComputerCraftAPI {
+public final class ComputerCraftAPIImpl implements IComputerCraftAPI
+{
public static final ComputerCraftAPIImpl INSTANCE = new ComputerCraftAPIImpl();
private String version;
- private ComputerCraftAPIImpl() {
+ private ComputerCraftAPIImpl()
+ {
}
- public static InputStream getResourceFile(String domain, String subPath) {
+ public static InputStream getResourceFile( String domain, String subPath )
+ {
MinecraftServer server = GameInstanceUtils.getServer();
- if (server != null) {
- ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess)server).getServerResourceManager().getResourceManager();
- try {
- return manager.getResource(new Identifier(domain, subPath))
- .getInputStream();
- } catch (IOException ignored) {
+ if( server != null )
+ {
+ ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).getServerResourceManager().getResourceManager();
+ try
+ {
+ return manager.getResource( new Identifier( domain, subPath ) )
+ .getInputStream();
+ }
+ catch( IOException ignored )
+ {
return null;
}
}
@@ -78,71 +78,86 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI {
@Nonnull
@Override
- public String getInstalledVersion() {
- if (this.version != null) {
+ public String getInstalledVersion()
+ {
+ if( this.version != null )
+ {
return this.version;
}
return this.version = FabricLoader.getInstance()
- .getModContainer(ComputerCraft.MOD_ID)
- .map(x -> x.getMetadata()
- .getVersion()
- .toString())
- .orElse("unknown");
+ .getModContainer( ComputerCraft.MOD_ID )
+ .map( x -> x.getMetadata()
+ .getVersion()
+ .toString() )
+ .orElse( "unknown" );
}
@Override
- public int createUniqueNumberedSaveDir(@Nonnull World world, @Nonnull String parentSubPath) {
- return IDAssigner.getNextId(parentSubPath);
+ public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
+ {
+ return IDAssigner.getNextId( parentSubPath );
}
@Override
- public IWritableMount createSaveDirMount(@Nonnull World world, @Nonnull String subPath, long capacity) {
- try {
- return new FileMount(new File(IDAssigner.getDir(), subPath), capacity);
- } catch (Exception e) {
+ public IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
+ {
+ try
+ {
+ return new FileMount( new File( IDAssigner.getDir(), subPath ), capacity );
+ }
+ catch( Exception e )
+ {
return null;
}
}
@Override
- public IMount createResourceMount(@Nonnull String domain, @Nonnull String subPath) {
+ public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
+ {
MinecraftServer server = GameInstanceUtils.getServer();
- if (server != null) {
- ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess)server).getServerResourceManager().getResourceManager();
- ResourceMount mount = ResourceMount.get(domain, subPath, manager);
- return mount.exists("") ? mount : null;
+ if( server != null )
+ {
+ ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).getServerResourceManager().getResourceManager();
+ ResourceMount mount = ResourceMount.get( domain, subPath, manager );
+ return mount.exists( "" ) ? mount : null;
}
return null;
}
@Override
- public void registerPeripheralProvider(@Nonnull IPeripheralProvider provider) {
- Peripherals.register(provider);
+ public void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
+ {
+ Peripherals.register( provider );
}
@Override
- public void registerTurtleUpgrade(@Nonnull ITurtleUpgrade upgrade) {
- TurtleUpgrades.register(upgrade);
+ public void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
+ {
+ TurtleUpgrades.register( upgrade );
}
@Override
- public void registerBundledRedstoneProvider(@Nonnull IBundledRedstoneProvider provider) {
- BundledRedstone.register(provider);
+ public void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
+ {
+ BundledRedstone.register( provider );
}
@Override
- public int getBundledRedstoneOutput(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side) {
- return BundledRedstone.getDefaultOutput(world, pos, side);
+ public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
+ {
+ return BundledRedstone.getDefaultOutput( world, pos, side );
}
@Override
- public void registerMediaProvider(@Nonnull IMediaProvider provider) {
- MediaProviders.register(provider);
+ public void registerMediaProvider( @Nonnull IMediaProvider provider )
+ {
+ MediaProviders.register( provider );
}
@Override
- public void registerPocketUpgrade(@Nonnull IPocketUpgrade upgrade) {
- PocketUpgrades.register(upgrade);
+ public void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
+ {
+ PocketUpgrades.register( upgrade );
}
@Override
@@ -153,28 +168,35 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI {
@Nonnull
@Override
- public IPacketNetwork getWirelessNetwork() {
+ public IPacketNetwork getWirelessNetwork()
+ {
return WirelessNetwork.getUniversal();
}
@Override
- public void registerAPIFactory(@Nonnull ILuaAPIFactory factory) {
- ApiFactories.register(factory);
+ public void registerAPIFactory( @Nonnull ILuaAPIFactory factory )
+ {
+ ApiFactories.register( factory );
}
@Nonnull
@Override
- public IWiredNode createWiredNodeForElement(@Nonnull IWiredElement element) {
- return new WiredNode(element);
+ public IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
+ {
+ return new WiredNode( element );
}
@Nullable
@Override
- public IWiredElement getWiredElementAt(@Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side) {
- BlockEntity tile = world.getBlockEntity(pos);
- if (tile instanceof TileCable) {
- return ((TileCable) tile).getElement(side);
- } else if (tile instanceof TileWiredModemFull) {
+ public IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
+ {
+ BlockEntity tile = world.getBlockEntity( pos );
+ if( tile instanceof TileCable )
+ {
+ return ((TileCable) tile).getElement( side );
+ }
+ else if( tile instanceof TileWiredModemFull )
+ {
return ((TileWiredModemFull) tile).getElement();
}
return null;
diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java
index 9699b6173..c1f8ed540 100644
--- a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java
+++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java
@@ -6,9 +6,6 @@
package dan200.computercraft.api;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.lua.GenericSource;
@@ -24,43 +21,53 @@ import dan200.computercraft.api.peripheral.IPeripheralProvider;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
-
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* The static entry point to the ComputerCraft API.
*
* Members in this class must be called after mod_ComputerCraft has been initialised, but may be called before it is fully loaded.
*/
-public final class ComputerCraftAPI {
+public final class ComputerCraftAPI
+{
private static IComputerCraftAPI instance;
@Nonnull
@Deprecated
- public static String getAPIVersion() {
+ public static String getAPIVersion()
+ {
return getInstalledVersion();
}
@Nonnull
- public static String getInstalledVersion() {
+ public static String getInstalledVersion()
+ {
return getInstance().getInstalledVersion();
}
@Nonnull
- private static IComputerCraftAPI getInstance() {
- if (instance != null) {
+ private static IComputerCraftAPI getInstance()
+ {
+ if( instance != null )
+ {
return instance;
}
- try {
- return instance = (IComputerCraftAPI) Class.forName("dan200.computercraft.ComputerCraftAPIImpl")
- .getField("INSTANCE")
- .get(null);
- } catch (ReflectiveOperationException e) {
- throw new IllegalStateException("Cannot find ComputerCraft API", e);
+ try
+ {
+ return instance = (IComputerCraftAPI) Class.forName( "dan200.computercraft.ComputerCraftAPIImpl" )
+ .getField( "INSTANCE" )
+ .get( null );
+ }
+ catch( ReflectiveOperationException e )
+ {
+ throw new IllegalStateException( "Cannot find ComputerCraft API", e );
}
}
@@ -69,15 +76,16 @@ public final class ComputerCraftAPI {
*
* Use in conjunction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
*
- * @param world The world for which the save dir should be created. This should be the server side world object.
+ * @param world The world for which the save dir should be created. This should be the server side world object.
* @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk"
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
*
- * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing.
+ * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing.
* @see #createSaveDirMount(World, String, long)
*/
- public static int createUniqueNumberedSaveDir(@Nonnull World world, @Nonnull String parentSubPath) {
- return getInstance().createUniqueNumberedSaveDir(world, parentSubPath);
+ public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
+ {
+ return getInstance().createUniqueNumberedSaveDir( world, parentSubPath );
}
/**
@@ -86,12 +94,12 @@ public final class ComputerCraftAPI {
* Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the users save directory onto a computers
* file system.
*
- * @param world The world for which the save dir can be found. This should be the server side world object.
- * @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42". Use createUniqueNumberedSaveDir()
- * to create a new numbered folder to use.
+ * @param world The world for which the save dir can be found. This should be the server side world object.
+ * @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42". Use createUniqueNumberedSaveDir()
+ * to create a new numbered folder to use.
* @param capacity The amount of data that can be stored in the directory before it fills up, in bytes.
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() to mount this on a
- * Computers' file system.
+ * Computers' file system.
* @see #createUniqueNumberedSaveDir(World, String)
* @see IComputerAccess#mount(String, IMount)
* @see IComputerAccess#mountWritable(String, IWritableMount)
@@ -99,8 +107,9 @@ public final class ComputerCraftAPI {
* @see IWritableMount
*/
@Nullable
- public static IWritableMount createSaveDirMount(@Nonnull World world, @Nonnull String subPath, long capacity) {
- return getInstance().createSaveDirMount(world, subPath, capacity);
+ public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
+ {
+ return getInstance().createSaveDirMount( world, subPath, capacity );
}
/**
@@ -114,7 +123,7 @@ public final class ComputerCraftAPI {
* "/data/computercraft/lua/rom". We construct a mount for that with
* {@code createResourceMount("computercraft", "lua/rom")}.
*
- * @param domain The domain under which to look for resources. eg: "mymod".
+ * @param domain The domain under which to look for resources. eg: "mymod".
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
* @return The mount, or {@code null} if it could be created for some reason.
* @see IComputerAccess#mount(String, IMount)
@@ -122,8 +131,9 @@ public final class ComputerCraftAPI {
* @see IMount
*/
@Nullable
- public static IMount createResourceMount(@Nonnull String domain, @Nonnull String subPath) {
- return getInstance().createResourceMount(domain, subPath);
+ public static IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
+ {
+ return getInstance().createResourceMount( domain, subPath );
}
/**
@@ -133,8 +143,9 @@ public final class ComputerCraftAPI {
* @see IPeripheral
* @see IPeripheralProvider
*/
- public static void registerPeripheralProvider(@Nonnull IPeripheralProvider provider) {
- getInstance().registerPeripheralProvider(provider);
+ public static void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
+ {
+ getInstance().registerPeripheralProvider( provider );
}
/**
@@ -155,8 +166,9 @@ public final class ComputerCraftAPI {
* @param upgrade The turtle upgrade to register.
* @see ITurtleUpgrade
*/
- public static void registerTurtleUpgrade(@Nonnull ITurtleUpgrade upgrade) {
- getInstance().registerTurtleUpgrade(upgrade);
+ public static void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
+ {
+ getInstance().registerTurtleUpgrade( upgrade );
}
/**
@@ -165,22 +177,24 @@ public final class ComputerCraftAPI {
* @param provider The bundled redstone provider to register.
* @see IBundledRedstoneProvider
*/
- public static void registerBundledRedstoneProvider(@Nonnull IBundledRedstoneProvider provider) {
- getInstance().registerBundledRedstoneProvider(provider);
+ public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
+ {
+ getInstance().registerBundledRedstoneProvider( provider );
}
/**
* If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output.
*
* @param world The world this block is in.
- * @param pos The position this block is at.
- * @param side The side to extract the bundled redstone output from.
+ * @param pos The position this block is at.
+ * @param side The side to extract the bundled redstone output from.
* @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. If there is no block
- * capable of emitting bundled redstone at the location, -1 will be returned.
+ * capable of emitting bundled redstone at the location, -1 will be returned.
* @see IBundledRedstoneProvider
*/
- public static int getBundledRedstoneOutput(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side) {
- return getInstance().getBundledRedstoneOutput(world, pos, side);
+ public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
+ {
+ return getInstance().getBundledRedstoneOutput( world, pos, side );
}
/**
@@ -189,12 +203,14 @@ public final class ComputerCraftAPI {
* @param provider The media provider to register.
* @see IMediaProvider
*/
- public static void registerMediaProvider(@Nonnull IMediaProvider provider) {
- getInstance().registerMediaProvider(provider);
+ public static void registerMediaProvider( @Nonnull IMediaProvider provider )
+ {
+ getInstance().registerMediaProvider( provider );
}
- public static void registerPocketUpgrade(@Nonnull IPocketUpgrade upgrade) {
- getInstance().registerPocketUpgrade(upgrade);
+ public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
+ {
+ getInstance().registerPocketUpgrade( upgrade );
}
/**
@@ -202,12 +218,14 @@ public final class ComputerCraftAPI {
*
* @return The global wireless network, or {@code null} if it could not be fetched.
*/
- public static IPacketNetwork getWirelessNetwork() {
+ public static IPacketNetwork getWirelessNetwork()
+ {
return getInstance().getWirelessNetwork();
}
- public static void registerAPIFactory(@Nonnull ILuaAPIFactory factory) {
- getInstance().registerAPIFactory(factory);
+ public static void registerAPIFactory( @Nonnull ILuaAPIFactory factory )
+ {
+ getInstance().registerAPIFactory( factory );
}
/**
@@ -218,59 +236,62 @@ public final class ComputerCraftAPI {
* @see IWiredElement#getNode()
*/
@Nonnull
- public static IWiredNode createWiredNodeForElement(@Nonnull IWiredElement element) {
- return getInstance().createWiredNodeForElement(element);
+ public static IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
+ {
+ return getInstance().createWiredNodeForElement( element );
}
/**
* Get the wired network element for a block in world.
*
* @param world The world the block exists in
- * @param pos The position the block exists in
- * @param side The side to extract the network element from
+ * @param pos The position the block exists in
+ * @param side The side to extract the network element from
* @return The element's node
* @see IWiredElement#getNode()
*/
@Nullable
- public static IWiredElement getWiredElementAt(@Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side) {
- return getInstance().getWiredElementAt(world, pos, side);
+ public static IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
+ {
+ return getInstance().getWiredElementAt( world, pos, side );
}
- public interface IComputerCraftAPI {
+ public interface IComputerCraftAPI
+ {
@Nonnull
String getInstalledVersion();
- int createUniqueNumberedSaveDir(@Nonnull World world, @Nonnull String parentSubPath);
+ int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath );
@Nullable
- IWritableMount createSaveDirMount(@Nonnull World world, @Nonnull String subPath, long capacity);
+ IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity );
@Nullable
- IMount createResourceMount(@Nonnull String domain, @Nonnull String subPath);
+ IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath );
- void registerPeripheralProvider(@Nonnull IPeripheralProvider provider);
+ void registerPeripheralProvider( @Nonnull IPeripheralProvider provider );
void registerGenericSource( @Nonnull GenericSource source );
- void registerTurtleUpgrade(@Nonnull ITurtleUpgrade upgrade);
+ void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade );
- void registerBundledRedstoneProvider(@Nonnull IBundledRedstoneProvider provider);
+ void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
- int getBundledRedstoneOutput(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side);
+ int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
- void registerMediaProvider(@Nonnull IMediaProvider provider);
+ void registerMediaProvider( @Nonnull IMediaProvider provider );
- void registerPocketUpgrade(@Nonnull IPocketUpgrade upgrade);
+ void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade );
@Nonnull
IPacketNetwork getWirelessNetwork();
- void registerAPIFactory(@Nonnull ILuaAPIFactory factory);
+ void registerAPIFactory( @Nonnull ILuaAPIFactory factory );
@Nonnull
- IWiredNode createWiredNodeForElement(@Nonnull IWiredElement element);
+ IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
@Nullable
- IWiredElement getWiredElementAt(@Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side);
+ IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side );
}
}
diff --git a/src/main/java/dan200/computercraft/api/client/TransformedModel.java b/src/main/java/dan200/computercraft/api/client/TransformedModel.java
index 911bfbb90..a62350b07 100644
--- a/src/main/java/dan200/computercraft/api/client/TransformedModel.java
+++ b/src/main/java/dan200/computercraft/api/client/TransformedModel.java
@@ -6,12 +6,9 @@
package dan200.computercraft.api.client;
-import java.util.Objects;
-
-import javax.annotation.Nonnull;
-
import dan200.computercraft.fabric.mixin.AffineTransformationAccess;
-
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
@@ -20,64 +17,78 @@ import net.minecraft.client.util.math.AffineTransformation;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
+import javax.annotation.Nonnull;
+import java.util.Objects;
/**
* A model to render, combined with a transformation matrix to apply.
*/
-@Environment (EnvType.CLIENT)
-public final class TransformedModel {
+@Environment( EnvType.CLIENT )
+public final class TransformedModel
+{
private final BakedModel model;
private final AffineTransformation matrix;
- public TransformedModel(@Nonnull BakedModel model, @Nonnull AffineTransformation matrix) {
- this.model = Objects.requireNonNull(model);
- this.matrix = Objects.requireNonNull(matrix);
+ public TransformedModel( @Nonnull BakedModel model, @Nonnull AffineTransformation matrix )
+ {
+ this.model = Objects.requireNonNull( model );
+ this.matrix = Objects.requireNonNull( matrix );
}
- public TransformedModel(@Nonnull BakedModel model) {
- this.model = Objects.requireNonNull(model);
+ public TransformedModel( @Nonnull BakedModel model )
+ {
+ this.model = Objects.requireNonNull( model );
this.matrix = AffineTransformation.identity();
}
- public static TransformedModel of(@Nonnull ModelIdentifier location) {
+ public static TransformedModel of( @Nonnull ModelIdentifier location )
+ {
BakedModelManager modelManager = MinecraftClient.getInstance()
- .getBakedModelManager();
- return new TransformedModel(modelManager.getModel(location));
+ .getBakedModelManager();
+ return new TransformedModel( modelManager.getModel( location ) );
}
- public static TransformedModel of(@Nonnull ItemStack item, @Nonnull AffineTransformation transform) {
+ public static TransformedModel of( @Nonnull ItemStack item, @Nonnull AffineTransformation transform )
+ {
BakedModel model = MinecraftClient.getInstance()
- .getItemRenderer()
- .getModels()
- .getModel(item);
- return new TransformedModel(model, transform);
+ .getItemRenderer()
+ .getModels()
+ .getModel( item );
+ return new TransformedModel( model, transform );
}
@Nonnull
- public BakedModel getModel() {
+ public BakedModel getModel()
+ {
return this.model;
}
@Nonnull
- public AffineTransformation getMatrix() {
+ public AffineTransformation getMatrix()
+ {
return this.matrix;
}
- public void push(MatrixStack matrixStack) {
+ public void push( MatrixStack matrixStack )
+ {
matrixStack.push();
AffineTransformationAccess access = (AffineTransformationAccess) (Object) this.matrix;
- if (access.getTranslation() != null)
- matrixStack.translate(access.getTranslation().getX(), access.getTranslation().getY(), access.getTranslation().getZ());
+ if( access.getTranslation() != null )
+ {
+ matrixStack.translate( access.getTranslation().getX(), access.getTranslation().getY(), access.getTranslation().getZ() );
+ }
- matrixStack.multiply(this.matrix.getRotation2());
+ matrixStack.multiply( this.matrix.getRotation2() );
- if (access.getScale() != null)
- matrixStack.scale(access.getScale().getX(), access.getScale().getY(), access.getScale().getZ());
+ if( access.getScale() != null )
+ {
+ matrixStack.scale( access.getScale().getX(), access.getScale().getY(), access.getScale().getZ() );
+ }
- if (access.getRotation1() != null)
- matrixStack.multiply(access.getRotation1());
+ if( access.getRotation1() != null )
+ {
+ matrixStack.multiply( access.getRotation1() );
+ }
}
}
diff --git a/src/main/java/dan200/computercraft/api/filesystem/FileAttributes.java b/src/main/java/dan200/computercraft/api/filesystem/FileAttributes.java
index 2c79271a0..ce05e8181 100644
--- a/src/main/java/dan200/computercraft/api/filesystem/FileAttributes.java
+++ b/src/main/java/dan200/computercraft/api/filesystem/FileAttributes.java
@@ -13,59 +13,70 @@ import java.time.Instant;
/**
* A simple version of {@link BasicFileAttributes}, which provides what information a {@link IMount} already exposes.
*/
-final class FileAttributes implements BasicFileAttributes {
- private static final FileTime EPOCH = FileTime.from(Instant.EPOCH);
+final class FileAttributes implements BasicFileAttributes
+{
+ private static final FileTime EPOCH = FileTime.from( Instant.EPOCH );
private final boolean isDirectory;
private final long size;
- FileAttributes(boolean isDirectory, long size) {
+ FileAttributes( boolean isDirectory, long size )
+ {
this.isDirectory = isDirectory;
this.size = size;
}
@Override
- public FileTime lastModifiedTime() {
+ public FileTime lastModifiedTime()
+ {
return EPOCH;
}
@Override
- public FileTime lastAccessTime() {
+ public FileTime lastAccessTime()
+ {
return EPOCH;
}
@Override
- public FileTime creationTime() {
+ public FileTime creationTime()
+ {
return EPOCH;
}
@Override
- public boolean isRegularFile() {
+ public boolean isRegularFile()
+ {
return !this.isDirectory;
}
@Override
- public boolean isDirectory() {
+ public boolean isDirectory()
+ {
return this.isDirectory;
}
@Override
- public boolean isSymbolicLink() {
+ public boolean isSymbolicLink()
+ {
return false;
}
@Override
- public boolean isOther() {
+ public boolean isOther()
+ {
return false;
}
@Override
- public long size() {
+ public long size()
+ {
return this.size;
}
@Override
- public Object fileKey() {
+ public Object fileKey()
+ {
return null;
}
}
diff --git a/src/main/java/dan200/computercraft/api/filesystem/FileOperationException.java b/src/main/java/dan200/computercraft/api/filesystem/FileOperationException.java
index a10ab5e43..a0d4de1aa 100644
--- a/src/main/java/dan200/computercraft/api/filesystem/FileOperationException.java
+++ b/src/main/java/dan200/computercraft/api/filesystem/FileOperationException.java
@@ -6,34 +6,37 @@
package dan200.computercraft.api.filesystem;
-import java.io.IOException;
-import java.util.Objects;
-
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.Objects;
/**
* An {@link IOException} which occurred on a specific file.
*
* This may be thrown from a {@link IMount} or {@link IWritableMount} to give more information about a failure.
*/
-public class FileOperationException extends IOException {
+public class FileOperationException extends IOException
+{
private static final long serialVersionUID = -8809108200853029849L;
private final String filename;
- public FileOperationException(@Nullable String filename, @Nonnull String message) {
- super(Objects.requireNonNull(message, "message cannot be null"));
+ public FileOperationException( @Nullable String filename, @Nonnull String message )
+ {
+ super( Objects.requireNonNull( message, "message cannot be null" ) );
this.filename = filename;
}
- public FileOperationException(@Nonnull String message) {
- super(Objects.requireNonNull(message, "message cannot be null"));
+ public FileOperationException( @Nonnull String message )
+ {
+ super( Objects.requireNonNull( message, "message cannot be null" ) );
this.filename = null;
}
@Nullable
- public String getFilename() {
+ public String getFilename()
+ {
return this.filename;
}
}
diff --git a/src/main/java/dan200/computercraft/api/filesystem/IFileSystem.java b/src/main/java/dan200/computercraft/api/filesystem/IFileSystem.java
index 8736fd865..8c74731e3 100644
--- a/src/main/java/dan200/computercraft/api/filesystem/IFileSystem.java
+++ b/src/main/java/dan200/computercraft/api/filesystem/IFileSystem.java
@@ -13,31 +13,32 @@ import java.io.IOException;
*
* This exists for use by various APIs - one should not attempt to mount it.
*/
-public interface IFileSystem extends IWritableMount {
+public interface IFileSystem extends IWritableMount
+{
/**
* Combine two paths together, reducing them into a normalised form.
*
- * @param path The main path.
+ * @param path The main path.
* @param child The path to append.
* @return The combined, normalised path.
*/
- String combine(String path, String child);
+ String combine( String path, String child );
/**
* Copy files from one location to another.
*
* @param from The location to copy from.
- * @param to The location to copy to. This should not exist.
+ * @param to The location to copy to. This should not exist.
* @throws IOException If the copy failed.
*/
- void copy(String from, String to) throws IOException;
+ void copy( String from, String to ) throws IOException;
/**
* Move files from one location to another.
*
* @param from The location to move from.
- * @param to The location to move to. This should not exist.
+ * @param to The location to move to. This should not exist.
* @throws IOException If the move failed.
*/
- void move(String from, String to) throws IOException;
+ void move( String from, String to ) throws IOException;
}
diff --git a/src/main/java/dan200/computercraft/api/filesystem/IMount.java b/src/main/java/dan200/computercraft/api/filesystem/IMount.java
index 055d0e464..f767bcd5a 100644
--- a/src/main/java/dan200/computercraft/api/filesystem/IMount.java
+++ b/src/main/java/dan200/computercraft/api/filesystem/IMount.java
@@ -6,18 +6,16 @@
package dan200.computercraft.api.filesystem;
+import dan200.computercraft.api.ComputerCraftAPI;
+import dan200.computercraft.api.peripheral.IComputerAccess;
+import net.minecraft.world.World;
+
+import javax.annotation.Nonnull;
import java.io.IOException;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
-import javax.annotation.Nonnull;
-
-import dan200.computercraft.api.ComputerCraftAPI;
-import dan200.computercraft.api.peripheral.IComputerAccess;
-
-import net.minecraft.world.World;
-
/**
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}.
*
@@ -29,26 +27,27 @@ import net.minecraft.world.World;
* @see IComputerAccess#mount(String, IMount)
* @see IWritableMount
*/
-public interface IMount {
+public interface IMount
+{
/**
* Returns the file names of all the files in a directory.
*
- * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
+ * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
* @param contents A list of strings. Add all the file names to this list.
* @throws IOException If the file was not a directory, or could not be listed.
*/
- void list(@Nonnull String path, @Nonnull List contents) throws IOException;
+ void list( @Nonnull String path, @Nonnull List contents ) throws IOException;
/**
* Opens a file with a given path, and returns an {@link ReadableByteChannel} representing its contents.
*
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return A channel representing the contents of the file. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to
- * seek to arbitrary positions when using binary mode.
+ * seek to arbitrary positions when using binary mode.
* @throws IOException If the file does not exist, or could not be opened.
*/
@Nonnull
- ReadableByteChannel openForRead(@Nonnull String path) throws IOException;
+ ReadableByteChannel openForRead( @Nonnull String path ) throws IOException;
/**
* Get attributes about the given file.
@@ -58,11 +57,13 @@ public interface IMount {
* @throws IOException If the file does not exist, or attributes could not be fetched.
*/
@Nonnull
- default BasicFileAttributes getAttributes(@Nonnull String path) throws IOException {
- if (!this.exists(path)) {
- throw new FileOperationException(path, "No such file");
+ default BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException
+ {
+ if( !this.exists( path ) )
+ {
+ throw new FileOperationException( path, "No such file" );
}
- return new FileAttributes(this.isDirectory(path), this.getSize(path));
+ return new FileAttributes( this.isDirectory( path ), this.getSize( path ) );
}
/**
@@ -72,7 +73,7 @@ public interface IMount {
* @return If the file exists.
* @throws IOException If an error occurs when checking the existence of the file.
*/
- boolean exists(@Nonnull String path) throws IOException;
+ boolean exists( @Nonnull String path ) throws IOException;
/**
* Returns whether a file with a given path is a directory or not.
@@ -81,7 +82,7 @@ public interface IMount {
* @return If the file exists and is a directory
* @throws IOException If an error occurs when checking whether the file is a directory.
*/
- boolean isDirectory(@Nonnull String path) throws IOException;
+ boolean isDirectory( @Nonnull String path ) throws IOException;
/**
* Returns the size of a file with a given path, in bytes.
@@ -90,5 +91,5 @@ public interface IMount {
* @return The size of the file, in bytes.
* @throws IOException If the file does not exist, or its size could not be determined.
*/
- long getSize(@Nonnull String path) throws IOException;
+ long getSize( @Nonnull String path ) throws IOException;
}
diff --git a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java
index 91ef9ae78..d39eec86c 100644
--- a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java
+++ b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java
@@ -6,18 +6,16 @@
package dan200.computercraft.api.filesystem;
+import dan200.computercraft.api.ComputerCraftAPI;
+import dan200.computercraft.api.peripheral.IComputerAccess;
+import net.minecraft.world.World;
+
+import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.WritableByteChannel;
import java.util.OptionalLong;
-import javax.annotation.Nonnull;
-
-import dan200.computercraft.api.ComputerCraftAPI;
-import dan200.computercraft.api.peripheral.IComputerAccess;
-
-import net.minecraft.world.World;
-
/**
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)} or {@link
* IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
@@ -30,14 +28,15 @@ import net.minecraft.world.World;
* @see IComputerAccess#mountWritable(String, IWritableMount)
* @see IMount
*/
-public interface IWritableMount extends IMount {
+public interface IWritableMount extends IMount
+{
/**
* Creates a directory at a given path inside the virtual file system.
*
* @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms".
* @throws IOException If the directory already exists or could not be created.
*/
- void makeDirectory(@Nonnull String path) throws IOException;
+ void makeDirectory( @Nonnull String path ) throws IOException;
/**
* Deletes a directory at a given path inside the virtual file system.
@@ -45,29 +44,29 @@ public interface IWritableMount extends IMount {
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms".
* @throws IOException If the file does not exist or could not be deleted.
*/
- void delete(@Nonnull String path) throws IOException;
+ void delete( @Nonnull String path ) throws IOException;
/**
* Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
*
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to seek to arbitrary
- * positions when using binary mode.
+ * positions when using binary mode.
* @throws IOException If the file could not be opened for writing.
*/
@Nonnull
- WritableByteChannel openForWrite(@Nonnull String path) throws IOException;
+ WritableByteChannel openForWrite( @Nonnull String path ) throws IOException;
/**
* Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
*
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to seek to arbitrary
- * positions when using binary mode.
+ * positions when using binary mode.
* @throws IOException If the file could not be opened for writing.
*/
@Nonnull
- WritableByteChannel openForAppend(@Nonnull String path) throws IOException;
+ WritableByteChannel openForAppend( @Nonnull String path ) throws IOException;
/**
* Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail
@@ -84,7 +83,8 @@ public interface IWritableMount extends IMount {
* @return The capacity of this mount, in bytes.
*/
@Nonnull
- default OptionalLong getCapacity() {
+ default OptionalLong getCapacity()
+ {
return OptionalLong.empty();
}
}
diff --git a/src/main/java/dan200/computercraft/api/lua/IArguments.java b/src/main/java/dan200/computercraft/api/lua/IArguments.java
index 4d2e36e15..2d4d73983 100644
--- a/src/main/java/dan200/computercraft/api/lua/IArguments.java
+++ b/src/main/java/dan200/computercraft/api/lua/IArguments.java
@@ -6,19 +6,19 @@
package dan200.computercraft.api.lua;
-import static dan200.computercraft.api.lua.LuaValues.checkFinite;
-
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Optional;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import static dan200.computercraft.api.lua.LuaValues.checkFinite;
/**
* The arguments passed to a function.
*/
-public interface IArguments {
+public interface IArguments
+{
/**
* Drop a number of arguments. The returned arguments instance will access arguments at position {@code i + count}, rather than {@code i}. However,
* errors will still use the given argument index.
@@ -26,12 +26,14 @@ public interface IArguments {
* @param count The number of arguments to drop.
* @return The new {@link IArguments} instance.
*/
- IArguments drop(int count);
+ IArguments drop( int count );
- default Object[] getAll() {
+ default Object[] getAll()
+ {
Object[] result = new Object[this.count()];
- for (int i = 0; i < result.length; i++) {
- result[i] = this.get(i);
+ for( int i = 0; i < result.length; i++ )
+ {
+ result[i] = this.get( i );
}
return result;
}
@@ -58,7 +60,7 @@ public interface IArguments {
* @return The argument's value, or {@code null} if not present.
*/
@Nullable
- Object get(int index);
+ Object get( int index );
/**
* Get an argument as an integer.
@@ -67,8 +69,9 @@ public interface IArguments {
* @return The argument's value.
* @throws LuaException If the value is not an integer.
*/
- default int getInt(int index) throws LuaException {
- return (int) this.getLong(index);
+ default int getInt( int index ) throws LuaException
+ {
+ return (int) this.getLong( index );
}
/**
@@ -78,13 +81,15 @@ public interface IArguments {
* @return The argument's value.
* @throws LuaException If the value is not a long.
*/
- default long getLong(int index) throws LuaException {
- Object value = this.get(index);
- if (!(value instanceof Number)) {
- throw LuaValues.badArgumentOf(index, "number", value);
+ default long getLong( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( !(value instanceof Number) )
+ {
+ throw LuaValues.badArgumentOf( index, "number", value );
}
- return LuaValues.checkFiniteNum(index, (Number) value)
- .longValue();
+ return LuaValues.checkFiniteNum( index, (Number) value )
+ .longValue();
}
/**
@@ -94,8 +99,9 @@ public interface IArguments {
* @return The argument's value.
* @throws LuaException If the value is not finite.
*/
- default double getFiniteDouble(int index) throws LuaException {
- return checkFinite(index, this.getDouble(index));
+ default double getFiniteDouble( int index ) throws LuaException
+ {
+ return checkFinite( index, this.getDouble( index ) );
}
/**
@@ -106,10 +112,12 @@ public interface IArguments {
* @throws LuaException If the value is not a number.
* @see #getFiniteDouble(int) if you require this to be finite (i.e. not infinite or NaN).
*/
- default double getDouble(int index) throws LuaException {
- Object value = this.get(index);
- if (!(value instanceof Number)) {
- throw LuaValues.badArgumentOf(index, "number", value);
+ default double getDouble( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( !(value instanceof Number) )
+ {
+ throw LuaValues.badArgumentOf( index, "number", value );
}
return ((Number) value).doubleValue();
}
@@ -121,10 +129,12 @@ public interface IArguments {
* @return The argument's value.
* @throws LuaException If the value is not a boolean.
*/
- default boolean getBoolean(int index) throws LuaException {
- Object value = this.get(index);
- if (!(value instanceof Boolean)) {
- throw LuaValues.badArgumentOf(index, "boolean", value);
+ default boolean getBoolean( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( !(value instanceof Boolean) )
+ {
+ throw LuaValues.badArgumentOf( index, "boolean", value );
}
return (Boolean) value;
}
@@ -137,8 +147,9 @@ public interface IArguments {
* @throws LuaException If the value is not a string.
*/
@Nonnull
- default ByteBuffer getBytes(int index) throws LuaException {
- return LuaValues.encode(this.getString(index));
+ default ByteBuffer getBytes( int index ) throws LuaException
+ {
+ return LuaValues.encode( this.getString( index ) );
}
/**
@@ -149,10 +160,12 @@ public interface IArguments {
* @throws LuaException If the value is not a string.
*/
@Nonnull
- default String getString(int index) throws LuaException {
- Object value = this.get(index);
- if (!(value instanceof String)) {
- throw LuaValues.badArgumentOf(index, "string", value);
+ default String getString( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( !(value instanceof String) )
+ {
+ throw LuaValues.badArgumentOf( index, "string", value );
}
return (String) value;
}
@@ -162,13 +175,14 @@ public interface IArguments {
*
* @param index The argument number.
* @param klass The type of enum to parse.
- * @param The type of enum to parse.
+ * @param The type of enum to parse.
* @return The argument's value.
* @throws LuaException If the value is not a string or not a valid option for this enum.
*/
@Nonnull
- default > T getEnum(int index, Class klass) throws LuaException {
- return LuaValues.checkEnum(index, klass, this.getString(index));
+ default > T getEnum( int index, Class klass ) throws LuaException
+ {
+ return LuaValues.checkEnum( index, klass, this.getString( index ) );
}
/**
@@ -179,10 +193,12 @@ public interface IArguments {
* @throws LuaException If the value is not a table.
*/
@Nonnull
- default Map, ?> getTable(int index) throws LuaException {
- Object value = this.get(index);
- if (!(value instanceof Map)) {
- throw LuaValues.badArgumentOf(index, "table", value);
+ default Map, ?> getTable( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( !(value instanceof Map) )
+ {
+ throw LuaValues.badArgumentOf( index, "table", value );
}
return (Map, ?>) value;
}
@@ -194,8 +210,9 @@ public interface IArguments {
* @return The argument's value, or {@link Optional#empty()} if not present. This is a read only buffer.
* @throws LuaException If the value is not a string.
*/
- default Optional optBytes(int index) throws LuaException {
- return this.optString(index).map(LuaValues::encode);
+ default Optional optBytes( int index ) throws LuaException
+ {
+ return this.optString( index ).map( LuaValues::encode );
}
/**
@@ -205,15 +222,18 @@ public interface IArguments {
* @return The argument's value, or {@link Optional#empty()} if not present.
* @throws LuaException If the value is not a string.
*/
- default Optional optString(int index) throws LuaException {
- Object value = this.get(index);
- if (value == null) {
+ default Optional optString( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( value == null )
+ {
return Optional.empty();
}
- if (!(value instanceof String)) {
- throw LuaValues.badArgumentOf(index, "string", value);
+ if( !(value instanceof String) )
+ {
+ throw LuaValues.badArgumentOf( index, "string", value );
}
- return Optional.of((String) value);
+ return Optional.of( (String) value );
}
/**
@@ -221,26 +241,28 @@ public interface IArguments {
*
* @param index The argument number.
* @param klass The type of enum to parse.
- * @param The type of enum to parse.
+ * @param The type of enum to parse.
* @return The argument's value.
* @throws LuaException If the value is not a string or not a valid option for this enum.
*/
@Nonnull
- default > Optional optEnum(int index, Class klass) throws LuaException {
- Optional str = this.optString(index);
- return str.isPresent() ? Optional.of(LuaValues.checkEnum(index, klass, str.get())) : Optional.empty();
+ default > Optional optEnum( int index, Class klass ) throws LuaException
+ {
+ Optional str = this.optString( index );
+ return str.isPresent() ? Optional.of( LuaValues.checkEnum( index, klass, str.get() ) ) : Optional.empty();
}
/**
* Get an argument as a double.
*
* @param index The argument number.
- * @param def The default value, if this argument is not given.
+ * @param def The default value, if this argument is not given.
* @return The argument's value, or {@code def} if none was provided.
* @throws LuaException If the value is not a number.
*/
- default double optDouble(int index, double def) throws LuaException {
- return this.optDouble(index).orElse(def);
+ default double optDouble( int index, double def ) throws LuaException
+ {
+ return this.optDouble( index ).orElse( def );
}
/**
@@ -251,27 +273,31 @@ public interface IArguments {
* @throws LuaException If the value is not a number.
*/
@Nonnull
- default Optional optDouble(int index) throws LuaException {
- Object value = this.get(index);
- if (value == null) {
+ default Optional optDouble( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( value == null )
+ {
return Optional.empty();
}
- if (!(value instanceof Number)) {
- throw LuaValues.badArgumentOf(index, "number", value);
+ if( !(value instanceof Number) )
+ {
+ throw LuaValues.badArgumentOf( index, "number", value );
}
- return Optional.of(((Number) value).doubleValue());
+ return Optional.of( ((Number) value).doubleValue() );
}
/**
* Get an argument as an int.
*
* @param index The argument number.
- * @param def The default value, if this argument is not given.
+ * @param def The default value, if this argument is not given.
* @return The argument's value, or {@code def} if none was provided.
* @throws LuaException If the value is not a number.
*/
- default int optInt(int index, int def) throws LuaException {
- return this.optInt(index).orElse(def);
+ default int optInt( int index, int def ) throws LuaException
+ {
+ return this.optInt( index ).orElse( def );
}
/**
@@ -282,8 +308,9 @@ public interface IArguments {
* @throws LuaException If the value is not a number.
*/
@Nonnull
- default Optional optInt(int index) throws LuaException {
- return this.optLong(index).map(Long::intValue);
+ default Optional optInt( int index ) throws LuaException
+ {
+ return this.optLong( index ).map( Long::intValue );
}
/**
@@ -293,40 +320,45 @@ public interface IArguments {
* @return The argument's value, or {@link Optional#empty()} if not present.
* @throws LuaException If the value is not a number.
*/
- default Optional optLong(int index) throws LuaException {
- Object value = this.get(index);
- if (value == null) {
+ default Optional optLong( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( value == null )
+ {
return Optional.empty();
}
- if (!(value instanceof Number)) {
- throw LuaValues.badArgumentOf(index, "number", value);
+ if( !(value instanceof Number) )
+ {
+ throw LuaValues.badArgumentOf( index, "number", value );
}
- return Optional.of(LuaValues.checkFiniteNum(index, (Number) value)
- .longValue());
+ return Optional.of( LuaValues.checkFiniteNum( index, (Number) value )
+ .longValue() );
}
/**
* Get an argument as a long.
*
* @param index The argument number.
- * @param def The default value, if this argument is not given.
+ * @param def The default value, if this argument is not given.
* @return The argument's value, or {@code def} if none was provided.
* @throws LuaException If the value is not a number.
*/
- default long optLong(int index, long def) throws LuaException {
- return this.optLong(index).orElse(def);
+ default long optLong( int index, long def ) throws LuaException
+ {
+ return this.optLong( index ).orElse( def );
}
/**
* Get an argument as a finite number (not infinite or NaN).
*
* @param index The argument number.
- * @param def The default value, if this argument is not given.
+ * @param def The default value, if this argument is not given.
* @return The argument's value, or {@code def} if none was provided.
* @throws LuaException If the value is not finite.
*/
- default double optFiniteDouble(int index, double def) throws LuaException {
- return this.optFiniteDouble(index).orElse(def);
+ default double optFiniteDouble( int index, double def ) throws LuaException
+ {
+ return this.optFiniteDouble( index ).orElse( def );
}
/**
@@ -336,10 +368,12 @@ public interface IArguments {
* @return The argument's value, or {@link Optional#empty()} if not present.
* @throws LuaException If the value is not finite.
*/
- default Optional optFiniteDouble(int index) throws LuaException {
- Optional value = this.optDouble(index);
- if (value.isPresent()) {
- LuaValues.checkFiniteNum(index, value.get());
+ default Optional optFiniteDouble( int index ) throws LuaException
+ {
+ Optional value = this.optDouble( index );
+ if( value.isPresent() )
+ {
+ LuaValues.checkFiniteNum( index, value.get() );
}
return value;
}
@@ -348,12 +382,13 @@ public interface IArguments {
* Get an argument as a boolean.
*
* @param index The argument number.
- * @param def The default value, if this argument is not given.
+ * @param def The default value, if this argument is not given.
* @return The argument's value, or {@code def} if none was provided.
* @throws LuaException If the value is not a boolean.
*/
- default boolean optBoolean(int index, boolean def) throws LuaException {
- return this.optBoolean(index).orElse(def);
+ default boolean optBoolean( int index, boolean def ) throws LuaException
+ {
+ return this.optBoolean( index ).orElse( def );
}
/**
@@ -363,39 +398,44 @@ public interface IArguments {
* @return The argument's value, or {@link Optional#empty()} if not present.
* @throws LuaException If the value is not a boolean.
*/
- default Optional optBoolean(int index) throws LuaException {
- Object value = this.get(index);
- if (value == null) {
+ default Optional optBoolean( int index ) throws LuaException
+ {
+ Object value = this.get( index );
+ if( value == null )
+ {
return Optional.empty();
}
- if (!(value instanceof Boolean)) {
- throw LuaValues.badArgumentOf(index, "boolean", value);
+ if( !(value instanceof Boolean) )
+ {
+ throw LuaValues.badArgumentOf( index, "boolean", value );
}
- return Optional.of((Boolean) value);
+ return Optional.of( (Boolean) value );
}
/**
* Get an argument as a string.
*
* @param index The argument number.
- * @param def The default value, if this argument is not given.
+ * @param def The default value, if this argument is not given.
* @return The argument's value, or {@code def} if none was provided.
* @throws LuaException If the value is not a string.
*/
- default String optString(int index, String def) throws LuaException {
- return this.optString(index).orElse(def);
+ default String optString( int index, String def ) throws LuaException
+ {
+ return this.optString( index ).orElse( def );
}
/**
* Get an argument as a table.
*
* @param index The argument number.
- * @param def The default value, if this argument is not given.
+ * @param def The default value, if this argument is not given.
* @return The argument's value, or {@code def} if none was provided.
* @throws LuaException If the value is not a table.
*/
- default Map, ?> optTable(int index, Map