mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-11-03 23:22:59 +00:00 
			
		
		
		
	Compare commits
	
		
			10 Commits
		
	
	
		
			v1.14.4-1.
			...
			v1.12.2-1.
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					0ae70fed13 | ||
| 
						 | 
					121802a683 | ||
| 
						 | 
					08cf55e55f | ||
| 
						 | 
					3c8c0d78ef | ||
| 
						 | 
					c4d18aa9ca | ||
| 
						 | 
					a8fadabaf1 | ||
| 
						 | 
					38f9a015ca | ||
| 
						 | 
					c311cdc6f5 | ||
| 
						 | 
					a93e0f3284 | ||
| 
						 | 
					14b3065ba4 | 
@@ -68,7 +68,7 @@ configurations {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
    checkstyle "com.puppycrawl.tools:checkstyle:8.21"
 | 
			
		||||
    checkstyle "com.puppycrawl.tools:checkstyle:8.25"
 | 
			
		||||
 | 
			
		||||
    deobfProvided "mezz.jei:jei_1.12.2:4.15.0.269:api"
 | 
			
		||||
    deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
 | 
			
		||||
@@ -331,6 +331,7 @@ task checkRelease {
 | 
			
		||||
        if (!ok) throw new IllegalStateException("Could not check release")
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
check.dependsOn checkRelease
 | 
			
		||||
 | 
			
		||||
curseforge {
 | 
			
		||||
    apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
 | 
			
		||||
@@ -402,7 +403,9 @@ githubRelease {
 | 
			
		||||
    token project.hasProperty('githubApiKey') ? project.githubApiKey : ''
 | 
			
		||||
    owner 'SquidDev-CC'
 | 
			
		||||
    repo 'CC-Tweaked'
 | 
			
		||||
    targetCommitish { Grgit.open(dir: '.').branch.current().name }
 | 
			
		||||
    try {
 | 
			
		||||
        targetCommitish = Grgit.open(dir: '.').branch.current().name
 | 
			
		||||
    } catch(Exception ignored) { }
 | 
			
		||||
 | 
			
		||||
    tagName "v${mc_version}-${mod_version}"
 | 
			
		||||
    releaseName "[${mc_version}] ${mod_version}"
 | 
			
		||||
 
 | 
			
		||||
@@ -14,9 +14,7 @@
 | 
			
		||||
        <!-- Annotations -->
 | 
			
		||||
        <module name="AnnotationLocation" />
 | 
			
		||||
        <module name="AnnotationUseStyle" />
 | 
			
		||||
        <module name="MissingDeprecated">
 | 
			
		||||
            <property name="skipNoJavadoc" value="true" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="MissingDeprecated" />
 | 
			
		||||
        <module name="MissingOverride" />
 | 
			
		||||
 | 
			
		||||
        <!-- Blocks -->
 | 
			
		||||
@@ -57,6 +55,9 @@
 | 
			
		||||
        <module name="SimplifyBooleanReturn" />
 | 
			
		||||
        <module name="StringLiteralEquality" />
 | 
			
		||||
        <module name="UnnecessaryParentheses" />
 | 
			
		||||
        <module name="UnnecessarySemicolonAfterTypeMemberDeclaration" />
 | 
			
		||||
        <module name="UnnecessarySemicolonInTryWithResources" />
 | 
			
		||||
        <module name="UnnecessarySemicolonInEnumeration" />
 | 
			
		||||
 | 
			
		||||
        <!-- Imports -->
 | 
			
		||||
        <module name="CustomImportOrder" />
 | 
			
		||||
@@ -65,10 +66,16 @@
 | 
			
		||||
        <module name="UnusedImports" />
 | 
			
		||||
 | 
			
		||||
        <!-- Javadoc -->
 | 
			
		||||
        <!-- TODO: Missing* checks for the dan200.computercraft.api package? -->
 | 
			
		||||
        <module name="AtclauseOrder" />
 | 
			
		||||
        <!-- TODO: Cleanup our documentation before enabling JavadocMethod, JavadocStyle, JavadocType and SummaryJavadoc. -->
 | 
			
		||||
        <module name="InvalidJavadocPosition" />
 | 
			
		||||
        <module name="JavadocBlockTagLocation" />
 | 
			
		||||
        <module name="JavadocMethod"/>
 | 
			
		||||
        <module name="JavadocType"/>
 | 
			
		||||
        <module name="JavadocStyle" />
 | 
			
		||||
        <module name="NonEmptyAtclauseDescription" />
 | 
			
		||||
        <module name="SingleLineJavadoc" />
 | 
			
		||||
        <module name="SummaryJavadocCheck"/>
 | 
			
		||||
 | 
			
		||||
        <!-- Misc -->
 | 
			
		||||
        <module name="ArrayTypeStyle" />
 | 
			
		||||
@@ -155,5 +162,8 @@
 | 
			
		||||
 | 
			
		||||
    <module name="FileTabCharacter" />
 | 
			
		||||
    <module name="NewlineAtEndOfFile" />
 | 
			
		||||
    <module name="RegexpSingleline">
 | 
			
		||||
        <property name="format" value="\s+$"/>
 | 
			
		||||
        <property name="message" value="Trailing whitespace"/>
 | 
			
		||||
    </module>
 | 
			
		||||
</module>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,4 +6,7 @@
 | 
			
		||||
    <!-- All the config options and method fields. -->
 | 
			
		||||
    <suppress checks="StaticVariableName" files=".*[\\/]ComputerCraft.java" />
 | 
			
		||||
    <suppress checks="StaticVariableName" files=".*[\\/]ComputerCraftAPI.java" />
 | 
			
		||||
 | 
			
		||||
    <!-- Do not check for missing package Javadoc. -->
 | 
			
		||||
    <suppress checks="JavadocStyle" files=".*[\\/]package-info.java" />
 | 
			
		||||
</suppressions>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
# Mod properties
 | 
			
		||||
mod_version=1.85.0
 | 
			
		||||
mod_version=1.85.2
 | 
			
		||||
 | 
			
		||||
# Minecraft properties
 | 
			
		||||
mc_version=1.12.2
 | 
			
		||||
 
 | 
			
		||||
@@ -32,8 +32,9 @@ import java.lang.reflect.Method;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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.
 | 
			
		||||
 *
 | 
			
		||||
 * 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
 | 
			
		||||
{
 | 
			
		||||
@@ -269,7 +270,7 @@ public final class ComputerCraftAPI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers a media provider to provide {@link IMedia} implementations for Items
 | 
			
		||||
     * Registers a media provider to provide {@link IMedia} implementations for Items.
 | 
			
		||||
     *
 | 
			
		||||
     * @param provider The media provider to register.
 | 
			
		||||
     * @see IMediaProvider
 | 
			
		||||
@@ -370,7 +371,7 @@ public final class ComputerCraftAPI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a new wired node for a given wired element
 | 
			
		||||
     * Construct a new wired node for a given wired element.
 | 
			
		||||
     *
 | 
			
		||||
     * @param element The element to construct it for
 | 
			
		||||
     * @return The element's node
 | 
			
		||||
@@ -398,7 +399,7 @@ public final class ComputerCraftAPI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the wired network element for a block in world
 | 
			
		||||
     * 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
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a read only part of a virtual filesystem that can be mounted onto a computer using
 | 
			
		||||
 * {@link IComputerAccess#mount(String, IMount)}
 | 
			
		||||
 * {@link IComputerAccess#mount(String, IMount)}.
 | 
			
		||||
 *
 | 
			
		||||
 * Ready made implementations of this interface can be created using
 | 
			
		||||
 * {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
 | 
			
		||||
@@ -60,7 +60,7 @@ public interface IMount
 | 
			
		||||
    void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the size of a file with a given path, in bytes
 | 
			
		||||
     * Returns the size of a file with a given path, in bytes.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
 | 
			
		||||
     * @return The size of the file, in bytes.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										335
									
								
								src/main/java/dan200/computercraft/api/lua/ArgumentHelper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										335
									
								
								src/main/java/dan200/computercraft/api/lua/ArgumentHelper.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,335 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. 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.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Provides methods for extracting values and validating Lua arguments, such as those provided to
 | 
			
		||||
 * {@link ILuaObject#callMethod(ILuaContext, int, Object[])} or
 | 
			
		||||
 * {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}.
 | 
			
		||||
 *
 | 
			
		||||
 * This provides two sets of functions: the {@code get*} methods, which require an argument to be valid, and
 | 
			
		||||
 * {@code opt*}, which accept a default value and return that if the argument was not present or was {@code null}.
 | 
			
		||||
 * If the argument is of the wrong type, a suitable error message will be thrown, with a similar format to Lua's own
 | 
			
		||||
 * error messages.
 | 
			
		||||
 *
 | 
			
		||||
 * <h2>Example usage:</h2>
 | 
			
		||||
 * <pre>
 | 
			
		||||
 * {@code
 | 
			
		||||
 * int slot = getInt( args, 0 );
 | 
			
		||||
 * int amount = optInt( args, 1, 64 );
 | 
			
		||||
 * }
 | 
			
		||||
 * </pre>
 | 
			
		||||
 */
 | 
			
		||||
public final class ArgumentHelper
 | 
			
		||||
{
 | 
			
		||||
    private ArgumentHelper()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string representation of the given value's type.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value whose type we are trying to compute.
 | 
			
		||||
     * @return A string representation of the given value's type, in a similar format to that provided by Lua's
 | 
			
		||||
     * {@code type} function.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getType( @Nullable Object value )
 | 
			
		||||
    {
 | 
			
		||||
        if( value == null ) return "nil";
 | 
			
		||||
        if( value instanceof String ) return "string";
 | 
			
		||||
        if( value instanceof Boolean ) return "boolean";
 | 
			
		||||
        if( value instanceof Number ) return "number";
 | 
			
		||||
        if( value instanceof Map ) return "table";
 | 
			
		||||
        return "userdata";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a "bad argument" exception, from an expected type and the actual value provided.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index    The argument number, starting from 0.
 | 
			
		||||
     * @param expected The expected type for this argument.
 | 
			
		||||
     * @param actual   The actual value provided for this argument.
 | 
			
		||||
     * @return The constructed exception, which should be thrown immediately.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static LuaException badArgumentOf( int index, @Nonnull String expected, @Nullable Object actual )
 | 
			
		||||
    {
 | 
			
		||||
        return badArgument( index, expected, getType( actual ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a "bad argument" exception, from an expected and actual type.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index    The argument number, starting from 0.
 | 
			
		||||
     * @param expected The expected type for this argument.
 | 
			
		||||
     * @param actual   The provided type for this argument.
 | 
			
		||||
     * @return The constructed exception, which should be thrown immediately.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
 | 
			
		||||
    {
 | 
			
		||||
        return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a double.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     * @see #getFiniteDouble(Object[], int) if you require this to be finite (i.e. not infinite or NaN).
 | 
			
		||||
     */
 | 
			
		||||
    public static double getDouble( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "number", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
 | 
			
		||||
        return ((Number) value).doubleValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as an integer.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not an integer.
 | 
			
		||||
     */
 | 
			
		||||
    public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return (int) getLong( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a long.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a long.
 | 
			
		||||
     */
 | 
			
		||||
    public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "number", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
 | 
			
		||||
        return checkFinite( index, (Number) value ).longValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a finite number (not infinite or NaN).
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not finite.
 | 
			
		||||
     */
 | 
			
		||||
    public static double getFiniteDouble( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return checkFinite( index, getDouble( args, index ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a boolean.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a boolean.
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof Boolean) ) throw badArgumentOf( index, "boolean", value );
 | 
			
		||||
        return (Boolean) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a string.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a string.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getString( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "string", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof String) ) throw badArgumentOf( index, "string", value );
 | 
			
		||||
        return (String) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a table.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a table.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static Map<?, ?> getTable( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "table", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof Map) ) throw badArgumentOf( index, "table", value );
 | 
			
		||||
        return (Map<?, ?>) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a double.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    public static double optDouble( @Nonnull Object[] args, int index, double def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
 | 
			
		||||
        return ((Number) value).doubleValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as an int.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return (int) optLong( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a long.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
 | 
			
		||||
        return checkFinite( index, (Number) value ).longValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a finite number (not infinite or NaN).
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    public static double optFiniteDouble( @Nonnull Object[] args, int index, double def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return checkFinite( index, optDouble( args, index, def ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a boolean.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof Boolean) ) throw badArgumentOf( index, "boolean", value );
 | 
			
		||||
        return (Boolean) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a string.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof String) ) throw badArgumentOf( index, "string", value );
 | 
			
		||||
        return (String) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a table.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    public static Map<?, ?> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof Map) ) throw badArgumentOf( index, "table", value );
 | 
			
		||||
        return (Map<?, ?>) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Number checkFinite( int index, Number value ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        checkFinite( index, value.doubleValue() );
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static double checkFinite( int index, double value ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( !Double.isFinite( value ) ) throw badArgument( index, "number", getNumericType( value ) );
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a more detailed representation of this number's type. If this is finite, it will just return "number",
 | 
			
		||||
     * otherwise it returns whether it is infinite or NaN.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value to extract the type for.
 | 
			
		||||
     * @return This value's numeric type.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getNumericType( double value )
 | 
			
		||||
    {
 | 
			
		||||
        if( Double.isNaN( value ) ) return "nan";
 | 
			
		||||
        if( value == Double.POSITIVE_INFINITY ) return "inf";
 | 
			
		||||
        if( value == Double.NEGATIVE_INFINITY ) return "-inf";
 | 
			
		||||
        return "number";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -26,7 +26,7 @@ public interface IComputerSystem extends IComputerAccess
 | 
			
		||||
    IFileSystem getFileSystem();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the label for this computer
 | 
			
		||||
     * Get the label for this computer.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This computer's label, or {@code null} if it is not set.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.peripheral;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.lua.ArgumentHelper;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
import dan200.computercraft.api.lua.LuaException;
 | 
			
		||||
 | 
			
		||||
@@ -58,9 +59,11 @@ public interface IPeripheral
 | 
			
		||||
     *                  Lua values of type "table" will be represented by Object type Map.<br>
 | 
			
		||||
     *                  Lua values of any other type will be represented by a null object.<br>
 | 
			
		||||
     *                  This array will be empty if no arguments are passed.
 | 
			
		||||
     *
 | 
			
		||||
     *                  It is recommended you use {@link ArgumentHelper} in order to validate and process arguments.
 | 
			
		||||
     * @return An array of objects, representing values you wish to return to the lua program. Integers, Doubles, Floats,
 | 
			
		||||
     * Strings, Booleans, Maps and ILuaObject and null be converted to their corresponding lua type. All other types
 | 
			
		||||
     * will be converted to nil.
 | 
			
		||||
     * Strings, Booleans, Maps, ILuaObject and null be converted to their corresponding lua type. All other types will
 | 
			
		||||
     * be converted to nil.
 | 
			
		||||
     *
 | 
			
		||||
     * You may return null to indicate no values should be returned.
 | 
			
		||||
     * @throws LuaException         If you throw any exception from this function, a lua error will be raised with the
 | 
			
		||||
@@ -70,6 +73,7 @@ public interface IPeripheral
 | 
			
		||||
     *                              InterruptedException will be thrown. This exception must not be caught or
 | 
			
		||||
     *                              intercepted, or the computer will leak memory and end up in a broken state.
 | 
			
		||||
     * @see #getMethodNames
 | 
			
		||||
     * @see ArgumentHelper
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException;
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Wrapper class for pocket computers
 | 
			
		||||
 * Wrapper class for pocket computers.
 | 
			
		||||
 */
 | 
			
		||||
public interface IPocketAccess
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -12,12 +12,12 @@ package dan200.computercraft.api.turtle;
 | 
			
		||||
public enum TurtleSide
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle)
 | 
			
		||||
     * The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle).
 | 
			
		||||
     */
 | 
			
		||||
    Left,
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The turtle's right side (where the modem usually is on a Wireless Mining Turtle)
 | 
			
		||||
     * The turtle's right side (where the modem usually is on a Wireless Mining Turtle).
 | 
			
		||||
     */
 | 
			
		||||
    Right,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,12 +18,12 @@ import net.minecraft.util.EnumFacing;
 | 
			
		||||
public enum TurtleVerb
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}
 | 
			
		||||
     * The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}.
 | 
			
		||||
     */
 | 
			
		||||
    Dig,
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}
 | 
			
		||||
     * The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}.
 | 
			
		||||
     */
 | 
			
		||||
    Attack,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,7 @@ public enum TurtleAction
 | 
			
		||||
    EQUIP,
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Inspect a block in world
 | 
			
		||||
     * Inspect a block in world.
 | 
			
		||||
     *
 | 
			
		||||
     * @see TurtleBlockEvent.Inspect
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -112,7 +112,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Get the upgrade doing the digging
 | 
			
		||||
         * Get the upgrade doing the digging.
 | 
			
		||||
         *
 | 
			
		||||
         * @return The upgrade doing the digging.
 | 
			
		||||
         */
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the inventory being interacted with
 | 
			
		||||
     * Get the inventory being interacted with.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ import net.minecraft.util.math.MathHelper;
 | 
			
		||||
public abstract class ItemMapLikeRenderer
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The main rendering method for the item
 | 
			
		||||
     * The main rendering method for the item.
 | 
			
		||||
     *
 | 
			
		||||
     * @param stack The stack to render
 | 
			
		||||
     * @see ItemRenderer#renderMapFirstPerson(ItemStack)
 | 
			
		||||
@@ -87,7 +87,7 @@ public abstract class ItemMapLikeRenderer
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Render an item in the middle of the screen
 | 
			
		||||
     * Render an item in the middle of the screen.
 | 
			
		||||
     *
 | 
			
		||||
     * @param pitch         The pitch of the player
 | 
			
		||||
     * @param equipProgress The equip progress of this item
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@ import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*;
 | 
			
		||||
import static dan200.computercraft.client.gui.GuiComputer.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Emulates map rendering for pocket computers
 | 
			
		||||
 * Emulates map rendering for pocket computers.
 | 
			
		||||
 */
 | 
			
		||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
 | 
			
		||||
public final class ItemPocketRenderer extends ItemMapLikeRenderer
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAG
 | 
			
		||||
import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENGTH;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Emulates map and item-frame rendering for printouts
 | 
			
		||||
 * Emulates map and item-frame rendering for printouts.
 | 
			
		||||
 */
 | 
			
		||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
 | 
			
		||||
public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
 | 
			
		||||
 
 | 
			
		||||
@@ -28,32 +28,32 @@ public final class PrintoutRenderer
 | 
			
		||||
    private static final double BG_SIZE = 256.0;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Width of a page
 | 
			
		||||
     * Width of a page.
 | 
			
		||||
     */
 | 
			
		||||
    public static final int X_SIZE = 172;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Height of a page
 | 
			
		||||
     * Height of a page.
 | 
			
		||||
     */
 | 
			
		||||
    public static final int Y_SIZE = 209;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Padding between the left and right of a page and the text
 | 
			
		||||
     * Padding between the left and right of a page and the text.
 | 
			
		||||
     */
 | 
			
		||||
    public static final int X_TEXT_MARGIN = 13;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Padding between the top and bottom of a page and the text
 | 
			
		||||
     * Padding between the top and bottom of a page and the text.
 | 
			
		||||
     */
 | 
			
		||||
    public static final int Y_TEXT_MARGIN = 11;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Width of the extra page texture
 | 
			
		||||
     * Width of the extra page texture.
 | 
			
		||||
     */
 | 
			
		||||
    private static final int X_FOLD_SIZE = 12;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Size of the leather cover
 | 
			
		||||
     * Size of the leather cover.
 | 
			
		||||
     */
 | 
			
		||||
    public static final int COVER_SIZE = 12;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -97,6 +97,8 @@ public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set up the state for rendering block-breaking progress.
 | 
			
		||||
     *
 | 
			
		||||
     * @see RenderGlobal#preRenderDamagedBlocks()
 | 
			
		||||
     */
 | 
			
		||||
    private void preRenderDamagedBlocks()
 | 
			
		||||
@@ -115,6 +117,8 @@ public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Tear down the state for rendering block-breaking progress.
 | 
			
		||||
     *
 | 
			
		||||
     * @see RenderGlobal#postRenderDamagedBlocks()
 | 
			
		||||
     */
 | 
			
		||||
    private void postRenderDamagedBlocks()
 | 
			
		||||
 
 | 
			
		||||
@@ -154,7 +154,7 @@ public class AddressPredicate
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine whether the given address matches a series of patterns
 | 
			
		||||
     * Determine whether the given address matches a series of patterns.
 | 
			
		||||
     *
 | 
			
		||||
     * @param address The address to check.
 | 
			
		||||
     * @return Whether it matches any of these patterns.
 | 
			
		||||
 
 | 
			
		||||
@@ -13,256 +13,106 @@ import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Various helpers for arguments
 | 
			
		||||
 * A stub for any mods which depended on this version of the argument helper.
 | 
			
		||||
 *
 | 
			
		||||
 * @deprecated Use {@link dan200.computercraft.api.lua.ArgumentHelper}.
 | 
			
		||||
 */
 | 
			
		||||
@Deprecated
 | 
			
		||||
public final class ArgumentHelper
 | 
			
		||||
{
 | 
			
		||||
    private ArgumentHelper()
 | 
			
		||||
    {
 | 
			
		||||
        throw new IllegalStateException( "Cannot instantiate singleton " + getClass().getName() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getType( @Nullable Object type )
 | 
			
		||||
    {
 | 
			
		||||
        if( type == null ) return "nil";
 | 
			
		||||
        if( type instanceof String ) return "string";
 | 
			
		||||
        if( type instanceof Boolean ) return "boolean";
 | 
			
		||||
        if( type instanceof Number ) return "number";
 | 
			
		||||
        if( type instanceof Map ) return "table";
 | 
			
		||||
 | 
			
		||||
        Class<?> klass = type.getClass();
 | 
			
		||||
        if( klass.isArray() )
 | 
			
		||||
        {
 | 
			
		||||
            StringBuilder name = new StringBuilder();
 | 
			
		||||
            while( klass.isArray() )
 | 
			
		||||
            {
 | 
			
		||||
                name.append( "[]" );
 | 
			
		||||
                klass = klass.getComponentType();
 | 
			
		||||
            }
 | 
			
		||||
            name.insert( 0, klass.getName() );
 | 
			
		||||
            return name.toString();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return klass.getName();
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.getType( type );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static LuaException badArgument( int index, @Nonnull String expected, @Nullable Object actual )
 | 
			
		||||
    {
 | 
			
		||||
        return badArgument( index, expected, getType( actual ) );
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.badArgumentOf( index, expected, actual );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
 | 
			
		||||
    {
 | 
			
		||||
        return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.badArgument( index, expected, actual );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getNumber( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "number", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( value instanceof Number )
 | 
			
		||||
        {
 | 
			
		||||
            return ((Number) value).doubleValue();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "number", value );
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.getDouble( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return (int) getLong( args, index );
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.getInt( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "number", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( value instanceof Number )
 | 
			
		||||
        {
 | 
			
		||||
            return checkReal( index, (Number) value ).longValue();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "number", value );
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.getLong( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getReal( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return checkReal( index, getNumber( args, index ) );
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.getFiniteDouble( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( value instanceof Boolean )
 | 
			
		||||
        {
 | 
			
		||||
            return (Boolean) value;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "boolean", value );
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.getBoolean( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getString( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "string", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( value instanceof String )
 | 
			
		||||
        {
 | 
			
		||||
            return (String) value;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "string", value );
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.getString( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings( "unchecked" )
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @SuppressWarnings( "unchecked" )
 | 
			
		||||
    public static Map<Object, Object> getTable( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "table", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( value instanceof Map )
 | 
			
		||||
        {
 | 
			
		||||
            return (Map<Object, Object>) value;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "table", value );
 | 
			
		||||
        }
 | 
			
		||||
        return (Map<Object, Object>) dan200.computercraft.api.lua.ArgumentHelper.getTable( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double optNumber( @Nonnull Object[] args, int index, double def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return def;
 | 
			
		||||
        }
 | 
			
		||||
        else if( value instanceof Number )
 | 
			
		||||
        {
 | 
			
		||||
            return ((Number) value).doubleValue();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "number", value );
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.optDouble( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return (int) optLong( args, index, def );
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.optInt( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return def;
 | 
			
		||||
        }
 | 
			
		||||
        else if( value instanceof Number )
 | 
			
		||||
        {
 | 
			
		||||
            return checkReal( index, (Number) value ).longValue();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "number", value );
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.optLong( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double optReal( @Nonnull Object[] args, int index, double def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return checkReal( index, optNumber( args, index, def ) );
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.optFiniteDouble( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return def;
 | 
			
		||||
        }
 | 
			
		||||
        else if( value instanceof Boolean )
 | 
			
		||||
        {
 | 
			
		||||
            return (Boolean) value;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "boolean", value );
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.optBoolean( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return def;
 | 
			
		||||
        }
 | 
			
		||||
        else if( value instanceof String )
 | 
			
		||||
        {
 | 
			
		||||
            return (String) value;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "string", value );
 | 
			
		||||
        }
 | 
			
		||||
        return dan200.computercraft.api.lua.ArgumentHelper.optString( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings( "unchecked" )
 | 
			
		||||
    public static Map<Object, Object> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return def;
 | 
			
		||||
        }
 | 
			
		||||
        else if( value instanceof Map )
 | 
			
		||||
        {
 | 
			
		||||
            return (Map<Object, Object>) value;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "table", value );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Number checkReal( int index, Number value ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        checkReal( index, value.doubleValue() );
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static double checkReal( int index, double value ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( Double.isNaN( value ) )
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "number", "nan" );
 | 
			
		||||
        }
 | 
			
		||||
        else if( value == Double.POSITIVE_INFINITY )
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "number", "inf" );
 | 
			
		||||
        }
 | 
			
		||||
        else if( value == Double.NEGATIVE_INFINITY )
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "number", "-inf" );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return value;
 | 
			
		||||
        }
 | 
			
		||||
        return (Map<Object, Object>) dan200.computercraft.api.lua.ArgumentHelper.optTable( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
 | 
			
		||||
 | 
			
		||||
public class FSAPI implements ILuaAPI
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ import java.util.Collections;
 | 
			
		||||
import java.util.Locale;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.*;
 | 
			
		||||
import static dan200.computercraft.core.apis.TableHelper.*;
 | 
			
		||||
 | 
			
		||||
public class HTTPAPI implements ILuaAPI
 | 
			
		||||
@@ -89,7 +89,7 @@ public class HTTPAPI implements ILuaAPI
 | 
			
		||||
            case 0: // request
 | 
			
		||||
            {
 | 
			
		||||
                String address, postString, requestMethod;
 | 
			
		||||
                Map<Object, Object> headerTable;
 | 
			
		||||
                Map<?, ?> headerTable;
 | 
			
		||||
                boolean binary, redirect;
 | 
			
		||||
 | 
			
		||||
                if( args.length >= 1 && args[0] instanceof Map )
 | 
			
		||||
@@ -172,7 +172,7 @@ public class HTTPAPI implements ILuaAPI
 | 
			
		||||
            case 2: // websocket
 | 
			
		||||
            {
 | 
			
		||||
                String address = getString( args, 0 );
 | 
			
		||||
                Map<Object, Object> headerTbl = optTable( args, 1, Collections.emptyMap() );
 | 
			
		||||
                Map<?, ?> headerTbl = optTable( args, 1, Collections.emptyMap() );
 | 
			
		||||
 | 
			
		||||
                if( !ComputerCraft.http_websocket_enable )
 | 
			
		||||
                {
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ import java.time.ZonedDateTime;
 | 
			
		||||
import java.time.format.DateTimeFormatterBuilder;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.*;
 | 
			
		||||
 | 
			
		||||
public class OSAPI implements ILuaAPI
 | 
			
		||||
{
 | 
			
		||||
@@ -229,7 +229,7 @@ public class OSAPI implements ILuaAPI
 | 
			
		||||
            case 1:
 | 
			
		||||
            {
 | 
			
		||||
                // startTimer
 | 
			
		||||
                double timer = getReal( args, 0 );
 | 
			
		||||
                double timer = getFiniteDouble( args, 0 );
 | 
			
		||||
                synchronized( m_timers )
 | 
			
		||||
                {
 | 
			
		||||
                    m_timers.put( m_nextTimerToken, new Timer( (int) Math.round( timer / 0.05 ) ) );
 | 
			
		||||
@@ -239,7 +239,7 @@ public class OSAPI implements ILuaAPI
 | 
			
		||||
            case 2:
 | 
			
		||||
            {
 | 
			
		||||
                // setAlarm
 | 
			
		||||
                double time = getReal( args, 0 );
 | 
			
		||||
                double time = getFiniteDouble( args, 0 );
 | 
			
		||||
                if( time < 0.0 || time >= 24.0 )
 | 
			
		||||
                {
 | 
			
		||||
                    throw new LuaException( "Number out of range" );
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ import java.util.Collections;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
 | 
			
		||||
 | 
			
		||||
public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChangeListener
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.*;
 | 
			
		||||
 | 
			
		||||
public class RedstoneAPI implements ILuaAPI
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -6,14 +6,17 @@
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.core.apis;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.lua.ArgumentHelper;
 | 
			
		||||
import dan200.computercraft.api.lua.LuaException;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getNumericType;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Various helpers for tables
 | 
			
		||||
 * Various helpers for tables.
 | 
			
		||||
 */
 | 
			
		||||
public final class TableHelper
 | 
			
		||||
{
 | 
			
		||||
@@ -200,21 +203,7 @@ public final class TableHelper
 | 
			
		||||
 | 
			
		||||
    private static double checkReal( @Nonnull String key, double value ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( Double.isNaN( value ) )
 | 
			
		||||
        {
 | 
			
		||||
            throw badKey( key, "number", "nan" );
 | 
			
		||||
        }
 | 
			
		||||
        else if( value == Double.POSITIVE_INFINITY )
 | 
			
		||||
        {
 | 
			
		||||
            throw badKey( key, "number", "inf" );
 | 
			
		||||
        }
 | 
			
		||||
        else if( value == Double.NEGATIVE_INFINITY )
 | 
			
		||||
        {
 | 
			
		||||
            throw badKey( key, "number", "-inf" );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return value;
 | 
			
		||||
        }
 | 
			
		||||
        if( !Double.isFinite( value ) ) throw badKey( key, "number", getNumericType( value ) );
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ import org.apache.commons.lang3.ArrayUtils;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.*;
 | 
			
		||||
 | 
			
		||||
public class TermAPI implements ILuaAPI
 | 
			
		||||
{
 | 
			
		||||
@@ -242,9 +242,9 @@ public class TermAPI implements ILuaAPI
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    double r = getReal( args, 1 );
 | 
			
		||||
                    double g = getReal( args, 2 );
 | 
			
		||||
                    double b = getReal( args, 3 );
 | 
			
		||||
                    double r = getFiniteDouble( args, 1 );
 | 
			
		||||
                    double g = getFiniteDouble( args, 2 );
 | 
			
		||||
                    double b = getFiniteDouble( args, 3 );
 | 
			
		||||
                    setColour( m_terminal, colour, r, g, b );
 | 
			
		||||
                }
 | 
			
		||||
                return null;
 | 
			
		||||
 
 | 
			
		||||
@@ -21,8 +21,8 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getInt;
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optBoolean;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getInt;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optBoolean;
 | 
			
		||||
 | 
			
		||||
public class BinaryReadableHandle extends HandleGeneric
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -7,9 +7,9 @@
 | 
			
		||||
package dan200.computercraft.core.apis.handles;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ObjectArrays;
 | 
			
		||||
import dan200.computercraft.api.lua.ArgumentHelper;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
import dan200.computercraft.api.lua.LuaException;
 | 
			
		||||
import dan200.computercraft.core.apis.ArgumentHelper;
 | 
			
		||||
import dan200.computercraft.shared.util.StringUtil;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -73,7 +73,7 @@ public class BinaryWritableHandle extends HandleGeneric
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        throw ArgumentHelper.badArgument( 0, "string or number", args.length > 0 ? args[0] : null );
 | 
			
		||||
                        throw ArgumentHelper.badArgumentOf( 0, "string or number", args.length > 0 ? args[0] : null );
 | 
			
		||||
                    }
 | 
			
		||||
                    return null;
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
@@ -20,8 +20,8 @@ import java.nio.charset.CharsetDecoder;
 | 
			
		||||
import java.nio.charset.CodingErrorAction;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optBoolean;
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optInt;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optBoolean;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optInt;
 | 
			
		||||
 | 
			
		||||
public class EncodedReadableHandle extends HandleGeneric
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -16,8 +16,8 @@ import java.io.IOException;
 | 
			
		||||
import java.nio.channels.Channel;
 | 
			
		||||
import java.nio.channels.SeekableByteChannel;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optLong;
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optLong;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optString;
 | 
			
		||||
 | 
			
		||||
public abstract class HandleGeneric implements ILuaObject
 | 
			
		||||
{
 | 
			
		||||
@@ -47,7 +47,7 @@ public abstract class HandleGeneric implements ILuaObject
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Shared implementation for various file handle types
 | 
			
		||||
     * Shared implementation for various file handle types.
 | 
			
		||||
     *
 | 
			
		||||
     * @param channel The channel to seek in
 | 
			
		||||
     * @param args    The Lua arguments to process, like Lua's {@code file:seek}.
 | 
			
		||||
 
 | 
			
		||||
@@ -99,7 +99,7 @@ public final class NetworkUtils
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks a host is allowed
 | 
			
		||||
     * Checks a host is allowed.
 | 
			
		||||
     *
 | 
			
		||||
     * @param host The domain to check against
 | 
			
		||||
     * @throws HTTPRequestException If the host is not permitted.
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,8 @@ import java.util.function.Consumer;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A holder for one or more resources, with a lifetime.
 | 
			
		||||
 *
 | 
			
		||||
 * @param <T> The type of this resource. Should be the class extending from {@link Resource}.
 | 
			
		||||
 */
 | 
			
		||||
public abstract class Resource<T extends Resource<T>> implements Closeable
 | 
			
		||||
{
 | 
			
		||||
@@ -42,8 +44,9 @@ public abstract class Resource<T extends Resource<T>> implements Closeable
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks if this has been cancelled. If so, it'll clean up any
 | 
			
		||||
     * existing resources and cancel any pending futures.
 | 
			
		||||
     * Checks if this has been cancelled. If so, it'll clean up any existing resources and cancel any pending futures.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Whether this resource has been closed.
 | 
			
		||||
     */
 | 
			
		||||
    public final boolean checkClosed()
 | 
			
		||||
    {
 | 
			
		||||
@@ -80,6 +83,7 @@ public abstract class Resource<T extends Resource<T>> implements Closeable
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a {@link WeakReference} which will close {@code this} when collected.
 | 
			
		||||
     *
 | 
			
		||||
     * @param <R>    The object we are wrapping in a reference.
 | 
			
		||||
     * @param object The object to reference to
 | 
			
		||||
     * @return The weak reference.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,8 @@ import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A collection of {@link Resource}s, with an upper bound on capacity.
 | 
			
		||||
 *
 | 
			
		||||
 * @param <T> The type of the resource this group manages.
 | 
			
		||||
 */
 | 
			
		||||
public class ResourceGroup<T extends Resource<T>>
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,8 @@ import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A {@link ResourceGroup} which will queue items when the group at capacity.
 | 
			
		||||
 *
 | 
			
		||||
 * @param <T> The type of the resource this queue manages.
 | 
			
		||||
 */
 | 
			
		||||
public class ResourceQueue<T extends Resource<T>> extends ResourceGroup<T>
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit;
 | 
			
		||||
import java.util.concurrent.atomic.AtomicInteger;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents one or more
 | 
			
		||||
 * Represents an in-progress HTTP request.
 | 
			
		||||
 */
 | 
			
		||||
public class HttpRequest extends Resource<HttpRequest>
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -226,7 +226,11 @@ public final class HttpRequestHandler extends SimpleChannelInboundHandler<HttpOb
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine the redirect from this response
 | 
			
		||||
     * Determine the redirect from this response.
 | 
			
		||||
     *
 | 
			
		||||
     * @param status  The status of the HTTP response.
 | 
			
		||||
     * @param headers The headers of the HTTP response.
 | 
			
		||||
     * @return The URI to redirect to, or {@code null} if no redirect should occur.
 | 
			
		||||
     */
 | 
			
		||||
    private URI getRedirect( HttpResponseStatus status, HttpHeaders headers )
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ import javax.annotation.Nullable;
 | 
			
		||||
import java.io.Closeable;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optBoolean;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optBoolean;
 | 
			
		||||
import static dan200.computercraft.core.apis.http.websocket.Websocket.CLOSE_EVENT;
 | 
			
		||||
import static dan200.computercraft.core.apis.http.websocket.Websocket.MESSAGE_EVENT;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -268,7 +268,7 @@ final class ComputerExecutor
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Queue an event if the computer is on
 | 
			
		||||
     * Queue an event if the computer is on.
 | 
			
		||||
     *
 | 
			
		||||
     * @param event The event's name
 | 
			
		||||
     * @param args  The event's arguments
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,7 @@ import static dan200.computercraft.core.computer.TimeoutState.TIMEOUT;
 | 
			
		||||
public final class ComputerThread
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * How often the computer thread monitor should run, in milliseconds
 | 
			
		||||
     * How often the computer thread monitor should run, in milliseconds.
 | 
			
		||||
     *
 | 
			
		||||
     * @see Monitor
 | 
			
		||||
     */
 | 
			
		||||
@@ -83,7 +83,7 @@ public final class ComputerThread
 | 
			
		||||
    private static final Object threadLock = new Object();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Whether the computer thread system is currently running
 | 
			
		||||
     * Whether the computer thread system is currently running.
 | 
			
		||||
     */
 | 
			
		||||
    private static volatile boolean running = false;
 | 
			
		||||
 | 
			
		||||
@@ -105,7 +105,7 @@ public final class ComputerThread
 | 
			
		||||
    private static final Condition hasWork = computerLock.newCondition();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Active queues to execute
 | 
			
		||||
     * Active queues to execute.
 | 
			
		||||
     */
 | 
			
		||||
    private static final TreeSet<ComputerExecutor> computerQueue = new TreeSet<>( ( a, b ) -> {
 | 
			
		||||
        if( a == b ) return 0; // Should never happen, but let's be consistent here
 | 
			
		||||
@@ -126,7 +126,7 @@ public final class ComputerThread
 | 
			
		||||
    private ComputerThread() {}
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Start the computer thread
 | 
			
		||||
     * Start the computer thread.
 | 
			
		||||
     */
 | 
			
		||||
    static void start()
 | 
			
		||||
    {
 | 
			
		||||
@@ -194,7 +194,7 @@ public final class ComputerThread
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark a computer as having work, enqueuing it on the thread
 | 
			
		||||
     * Mark a computer as having work, enqueuing it on the thread.
 | 
			
		||||
     *
 | 
			
		||||
     * You must be holding {@link ComputerExecutor}'s {@code queueLock} when calling this method - it should only
 | 
			
		||||
     * be called from {@code enqueue}.
 | 
			
		||||
@@ -244,6 +244,8 @@ public final class ComputerThread
 | 
			
		||||
     * {@link #minimumVirtualRuntime} based on the current tasks.
 | 
			
		||||
     *
 | 
			
		||||
     * This is called before queueing tasks, to ensure that {@link #minimumVirtualRuntime} is up-to-date.
 | 
			
		||||
     *
 | 
			
		||||
     * @param current The machine which we updating runtimes from.
 | 
			
		||||
     */
 | 
			
		||||
    private static void updateRuntimes( @Nullable ComputerExecutor current )
 | 
			
		||||
    {
 | 
			
		||||
@@ -321,7 +323,7 @@ public final class ComputerThread
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The scaled period for a single task
 | 
			
		||||
     * The scaled period for a single task.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The scaled period for the task
 | 
			
		||||
     * @see #DEFAULT_LATENCY
 | 
			
		||||
@@ -336,7 +338,7 @@ public final class ComputerThread
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the thread has computers queued up
 | 
			
		||||
     * Determine if the thread has computers queued up.
 | 
			
		||||
     *
 | 
			
		||||
     * @return If we have work queued up.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -36,12 +36,12 @@ import java.util.concurrent.TimeUnit;
 | 
			
		||||
public final class TimeoutState
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The total time a task is allowed to run before aborting in nanoseconds
 | 
			
		||||
     * The total time a task is allowed to run before aborting in nanoseconds.
 | 
			
		||||
     */
 | 
			
		||||
    static final long TIMEOUT = TimeUnit.MILLISECONDS.toNanos( 7000 );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The time the task is allowed to run after each abort in nanoseconds
 | 
			
		||||
     * The time the task is allowed to run after each abort in nanoseconds.
 | 
			
		||||
     */
 | 
			
		||||
    static final long ABORT_TIMEOUT = TimeUnit.MILLISECONDS.toNanos( 1500 );
 | 
			
		||||
 | 
			
		||||
@@ -111,6 +111,8 @@ public final class TimeoutState
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * If the machine should be passively aborted.
 | 
			
		||||
     *
 | 
			
		||||
     * @return {@code true} if we should throw a timeout error.
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isSoftAborted()
 | 
			
		||||
    {
 | 
			
		||||
@@ -118,7 +120,9 @@ public final class TimeoutState
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * If the machine should be forcibly aborted.
 | 
			
		||||
     * Determine if the machine should be forcibly aborted.
 | 
			
		||||
     *
 | 
			
		||||
     * @return {@code true} if the machine should be forcibly shut down.
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isHardAborted()
 | 
			
		||||
    {
 | 
			
		||||
@@ -146,7 +150,7 @@ public final class TimeoutState
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Pauses the cumulative time, to be resumed by {@link #startTimer()}
 | 
			
		||||
     * Pauses the cumulative time, to be resumed by {@link #startTimer()}.
 | 
			
		||||
     *
 | 
			
		||||
     * @see #nanoCumulative()
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ public final class MachineResult
 | 
			
		||||
    public static final MachineResult TIMEOUT = new MachineResult( true, false, TimeoutState.ABORT_MESSAGE );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * An error with no user-friendly error message
 | 
			
		||||
     * An error with no user-friendly error message.
 | 
			
		||||
     */
 | 
			
		||||
    public static final MachineResult GENERIC_ERROR = new MachineResult( true, false, null );
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -314,6 +314,9 @@ public class Terminal
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine whether this terminal has changed.
 | 
			
		||||
     *
 | 
			
		||||
     * @return If this terminal is dirty.
 | 
			
		||||
     * @deprecated All {@code *Changed()} methods are deprecated: one should pass in a callback
 | 
			
		||||
     * instead.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A command which delegates to a series of sub commands
 | 
			
		||||
 * A command which delegates to a series of sub commands.
 | 
			
		||||
 */
 | 
			
		||||
public class CommandRoot implements ISubCommand
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ import java.util.List;
 | 
			
		||||
public interface ISubCommand
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the name of this command
 | 
			
		||||
     * Get the name of this command.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The name of this command
 | 
			
		||||
     * @see ICommand#getName()
 | 
			
		||||
@@ -40,7 +40,7 @@ public interface ISubCommand
 | 
			
		||||
    String getFullName();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the usage of this command
 | 
			
		||||
     * Get the usage of this command.
 | 
			
		||||
     *
 | 
			
		||||
     * @param context The context this command is executed in
 | 
			
		||||
     * @return The usage of this command
 | 
			
		||||
@@ -62,16 +62,17 @@ public interface ISubCommand
 | 
			
		||||
    boolean checkPermission( @Nonnull CommandContext context );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Execute this command
 | 
			
		||||
     * Execute this command.
 | 
			
		||||
     *
 | 
			
		||||
     * @param context   The current command context.
 | 
			
		||||
     * @param arguments The arguments passed  @throws CommandException When an error occurs
 | 
			
		||||
     * @param arguments The arguments passed
 | 
			
		||||
     * @throws CommandException When an error occurs
 | 
			
		||||
     * @see ICommand#execute(MinecraftServer, ICommandSender, String[])
 | 
			
		||||
     */
 | 
			
		||||
    void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a list of possible completions
 | 
			
		||||
     * Get a list of possible completions.
 | 
			
		||||
     *
 | 
			
		||||
     * @param context   The current command context.
 | 
			
		||||
     * @param arguments The arguments passed. You should complete the last one.
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ import net.minecraft.util.text.event.ClickEvent;
 | 
			
		||||
import net.minecraft.util.text.event.HoverEvent;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Various helpers for building chat messages
 | 
			
		||||
 * Various helpers for building chat messages.
 | 
			
		||||
 */
 | 
			
		||||
public final class ChatHelpers
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -107,7 +107,7 @@ public class TableBuilder
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Trim this table to a given height
 | 
			
		||||
     * Trim this table to a given height.
 | 
			
		||||
     *
 | 
			
		||||
     * @param height The desired height.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ public interface TableFormatter
 | 
			
		||||
    ITextComponent HEADER = coloured( "=", TextFormatting.GRAY );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get additional padding for the component
 | 
			
		||||
     * Get additional padding for the component.
 | 
			
		||||
     *
 | 
			
		||||
     * @param component The component to pad
 | 
			
		||||
     * @param width     The desired width for the component
 | 
			
		||||
@@ -32,7 +32,7 @@ public interface TableFormatter
 | 
			
		||||
    ITextComponent getPadding( ITextComponent component, int width );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the minimum padding between each column
 | 
			
		||||
     * Get the minimum padding between each column.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The minimum padding.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -30,8 +30,8 @@ import java.util.Collections;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getInt;
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getInt;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
 | 
			
		||||
 | 
			
		||||
public class CommandAPI implements ILuaAPI
 | 
			
		||||
{
 | 
			
		||||
@@ -204,7 +204,7 @@ public class CommandAPI implements ILuaAPI
 | 
			
		||||
                    );
 | 
			
		||||
                    if( !world.isValid( min ) || !world.isValid( max ) )
 | 
			
		||||
                    {
 | 
			
		||||
                        throw new LuaException( "Co-ordinates out or range" );
 | 
			
		||||
                        throw new LuaException( "Co-ordinates out of range" );
 | 
			
		||||
                    }
 | 
			
		||||
                    if( (max.getX() - min.getX() + 1) * (max.getY() - min.getY() + 1) * (max.getZ() - min.getZ() + 1) > 4096 )
 | 
			
		||||
                    {
 | 
			
		||||
@@ -243,7 +243,7 @@ public class CommandAPI implements ILuaAPI
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        throw new LuaException( "co-ordinates out or range" );
 | 
			
		||||
                        throw new LuaException( "Co-ordinates out of range" );
 | 
			
		||||
                    }
 | 
			
		||||
                } );
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -280,7 +280,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the redstone input for an adjacent block
 | 
			
		||||
     * Gets the redstone input for an adjacent block.
 | 
			
		||||
     *
 | 
			
		||||
     * @param world The world we exist in
 | 
			
		||||
     * @param pos   The position of the neighbour
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
package dan200.computercraft.shared.computer.core;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Receives some input and forwards it to a computer
 | 
			
		||||
 * Receives some input and forwards it to a computer.
 | 
			
		||||
 *
 | 
			
		||||
 * @see InputState
 | 
			
		||||
 * @see IComputer
 | 
			
		||||
 
 | 
			
		||||
@@ -108,7 +108,7 @@ public class JEIComputerCraft implements IModPlugin
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Distinguishes turtles by upgrades and family
 | 
			
		||||
     * Distinguishes turtles by upgrades and family.
 | 
			
		||||
     */
 | 
			
		||||
    private static final ISubtypeInterpreter turtleSubtype = stack -> {
 | 
			
		||||
        Item item = stack.getItem();
 | 
			
		||||
@@ -132,7 +132,7 @@ public class JEIComputerCraft implements IModPlugin
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Distinguishes pocket computers by upgrade and family
 | 
			
		||||
     * Distinguishes pocket computers by upgrade and family.
 | 
			
		||||
     */
 | 
			
		||||
    private static final ISubtypeInterpreter pocketSubtype = stack -> {
 | 
			
		||||
        Item item = stack.getItem();
 | 
			
		||||
@@ -152,7 +152,7 @@ public class JEIComputerCraft implements IModPlugin
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Distinguishes disks by colour
 | 
			
		||||
     * Distinguishes disks by colour.
 | 
			
		||||
     */
 | 
			
		||||
    private static final ISubtypeInterpreter diskSubtype = stack -> {
 | 
			
		||||
        Item item = stack.getItem();
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ import net.minecraft.util.SoundEvent;
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An implementation of IMedia for ItemRecord's
 | 
			
		||||
 * An implementation of IMedia for ItemRecords.
 | 
			
		||||
 */
 | 
			
		||||
public final class RecordMedia implements IMedia
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -72,6 +72,7 @@ public final class NetworkHandler
 | 
			
		||||
     * /**
 | 
			
		||||
     * Register packet, and a thread-unsafe handler for it.
 | 
			
		||||
     *
 | 
			
		||||
     * @param <T>     The type of the packet to send.
 | 
			
		||||
     * @param id      The identifier for this packet type
 | 
			
		||||
     * @param side    The side to register this packet handler under
 | 
			
		||||
     * @param factory The factory for this type of packet.
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ import net.minecraft.tileentity.TileEntityCommandBlock;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
 | 
			
		||||
 | 
			
		||||
public class CommandBlockPeripheral implements IPeripheral
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ import net.minecraft.item.ItemStack;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optString;
 | 
			
		||||
 | 
			
		||||
class DiskDrivePeripheral implements IPeripheral
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getInt;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getInt;
 | 
			
		||||
 | 
			
		||||
public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPacketReceiver
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,11 @@
 | 
			
		||||
package dan200.computercraft.shared.peripheral.modem;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This only exists for backwards compatibility
 | 
			
		||||
 * This only exists for backwards compatibility.
 | 
			
		||||
 *
 | 
			
		||||
 * @deprecated Use {@link dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeripheral} instead.
 | 
			
		||||
 */
 | 
			
		||||
@Deprecated
 | 
			
		||||
public abstract class WirelessModemPeripheral extends dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeripheral
 | 
			
		||||
{
 | 
			
		||||
    @Deprecated
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ import java.util.Collections;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a local peripheral exposed on the wired network
 | 
			
		||||
 * Represents a local peripheral exposed on the wired network.
 | 
			
		||||
 *
 | 
			
		||||
 * This is responsible for getting the peripheral in world, tracking id and type and determining whether
 | 
			
		||||
 * it has changed.
 | 
			
		||||
@@ -39,7 +39,7 @@ public final class WiredModemLocalPeripheral
 | 
			
		||||
    private IPeripheral peripheral;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Attach a new peripheral from the world
 | 
			
		||||
     * Attach a new peripheral from the world.
 | 
			
		||||
     *
 | 
			
		||||
     * @param world     The world to search in
 | 
			
		||||
     * @param origin    The position to search from
 | 
			
		||||
@@ -76,7 +76,7 @@ public final class WiredModemLocalPeripheral
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Detach the current peripheral
 | 
			
		||||
     * Detach the current peripheral.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Whether the peripheral changed
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ import java.util.Map;
 | 
			
		||||
import java.util.concurrent.ConcurrentHashMap;
 | 
			
		||||
import java.util.concurrent.ConcurrentMap;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
 | 
			
		||||
 | 
			
		||||
public abstract class WiredModemPeripheral extends ModemPeripheral implements IWiredSender
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ import org.apache.commons.lang3.ArrayUtils;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.*;
 | 
			
		||||
 | 
			
		||||
public class MonitorPeripheral implements IPeripheral
 | 
			
		||||
{
 | 
			
		||||
@@ -123,7 +123,7 @@ public class MonitorPeripheral implements IPeripheral
 | 
			
		||||
            case 8:
 | 
			
		||||
            {
 | 
			
		||||
                // setTextScale
 | 
			
		||||
                int scale = (int) (getReal( args, 0 ) * 2.0);
 | 
			
		||||
                int scale = (int) (getFiniteDouble( args, 0 ) * 2.0);
 | 
			
		||||
                if( scale < 1 || scale > 10 )
 | 
			
		||||
                {
 | 
			
		||||
                    throw new LuaException( "Expected number in range 0.5-5" );
 | 
			
		||||
@@ -184,9 +184,9 @@ public class MonitorPeripheral implements IPeripheral
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    double r = getReal( args, 1 );
 | 
			
		||||
                    double g = getReal( args, 2 );
 | 
			
		||||
                    double b = getReal( args, 3 );
 | 
			
		||||
                    double r = getFiniteDouble( args, 1 );
 | 
			
		||||
                    double g = getFiniteDouble( args, 2 );
 | 
			
		||||
                    double b = getFiniteDouble( args, 3 );
 | 
			
		||||
                    TermAPI.setColour( terminal, colour, r, g, b );
 | 
			
		||||
                }
 | 
			
		||||
                return null;
 | 
			
		||||
 
 | 
			
		||||
@@ -15,8 +15,8 @@ import dan200.computercraft.shared.util.StringUtil;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getInt;
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getInt;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optString;
 | 
			
		||||
 | 
			
		||||
public class PrinterPeripheral implements IPeripheral
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -23,8 +23,8 @@ import net.minecraft.world.World;
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.concurrent.atomic.AtomicInteger;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optReal;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optFiniteDouble;
 | 
			
		||||
 | 
			
		||||
public abstract class SpeakerPeripheral implements IPeripheral
 | 
			
		||||
{
 | 
			
		||||
@@ -84,8 +84,8 @@ public abstract class SpeakerPeripheral implements IPeripheral
 | 
			
		||||
            case 0: // playSound
 | 
			
		||||
            {
 | 
			
		||||
                String name = getString( args, 0 );
 | 
			
		||||
                float volume = (float) optReal( args, 1, 1.0 );
 | 
			
		||||
                float pitch = (float) optReal( args, 2, 1.0 );
 | 
			
		||||
                float volume = (float) optFiniteDouble( args, 1, 1.0 );
 | 
			
		||||
                float pitch = (float) optFiniteDouble( args, 2, 1.0 );
 | 
			
		||||
 | 
			
		||||
                return new Object[] { playSound( context, name, volume, pitch, false ) };
 | 
			
		||||
            }
 | 
			
		||||
@@ -102,8 +102,8 @@ public abstract class SpeakerPeripheral implements IPeripheral
 | 
			
		||||
    private synchronized Object[] playNote( Object[] arguments, ILuaContext context ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        String name = getString( arguments, 0 );
 | 
			
		||||
        float volume = (float) optReal( arguments, 1, 1.0 );
 | 
			
		||||
        float pitch = (float) optReal( arguments, 2, 1.0 );
 | 
			
		||||
        float volume = (float) optFiniteDouble( arguments, 1, 1.0 );
 | 
			
		||||
        float pitch = (float) optFiniteDouble( arguments, 2, 1.0 );
 | 
			
		||||
 | 
			
		||||
        String noteName = "block.note." + name;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ import javax.annotation.Nullable;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.*;
 | 
			
		||||
 | 
			
		||||
public class TurtleAPI implements ILuaAPI
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,7 @@ public class BlockTurtle extends BlockComputerBase
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public EnumBlockRenderType getRenderType( IBlockState state )
 | 
			
		||||
    {
 | 
			
		||||
        return EnumBlockRenderType.INVISIBLE;
 | 
			
		||||
        return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,7 @@ public class TurtlePlayer extends FakePlayer
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a TurtlePlayer which exists in the world
 | 
			
		||||
     * Construct a TurtlePlayer which exists in the world.
 | 
			
		||||
     *
 | 
			
		||||
     * @param world The world the player exists in
 | 
			
		||||
     * @deprecated This is required by {@link Entity}.
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ import dan200.computercraft.shared.turtle.core.TurtleCraftCommand;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.optInt;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.optInt;
 | 
			
		||||
 | 
			
		||||
public class CraftingTablePeripheral implements IPeripheral
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,8 @@
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.shared.util;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.util.text.TextComponentTranslation;
 | 
			
		||||
 | 
			
		||||
public final class StringUtil
 | 
			
		||||
{
 | 
			
		||||
    private StringUtil() {}
 | 
			
		||||
@@ -33,7 +35,12 @@ public final class StringUtil
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Translates a Stat name
 | 
			
		||||
     * Translates a string.
 | 
			
		||||
     *
 | 
			
		||||
     * Try to avoid using this where possible - it is generally preferred to use {@link TextComponentTranslation}.
 | 
			
		||||
     *
 | 
			
		||||
     * @param key The key to translate.
 | 
			
		||||
     * @return The translated string.
 | 
			
		||||
     */
 | 
			
		||||
    @SuppressWarnings( "deprecation" )
 | 
			
		||||
    public static String translate( String key )
 | 
			
		||||
@@ -42,12 +49,18 @@ public final class StringUtil
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Translates a Stat name with format args
 | 
			
		||||
     * Translates and formats a string.
 | 
			
		||||
     *
 | 
			
		||||
     * Try to avoid using this where possible - it is generally preferred to use {@link TextComponentTranslation}.
 | 
			
		||||
     *
 | 
			
		||||
     * @param key  The key to translate.
 | 
			
		||||
     * @param args The arguments to supply to {@link String#format(String, Object...)}.
 | 
			
		||||
     * @return The translated and formatted string.
 | 
			
		||||
     */
 | 
			
		||||
    @SuppressWarnings( "deprecation" )
 | 
			
		||||
    public static String translateFormatted( String key, Object... format )
 | 
			
		||||
    public static String translateFormatted( String key, Object... args )
 | 
			
		||||
    {
 | 
			
		||||
        return net.minecraft.util.text.translation.I18n.translateToLocalFormatted( key, format );
 | 
			
		||||
        return net.minecraft.util.text.translation.I18n.translateToLocalFormatted( key, args );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static byte[] encodeString( String string )
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ import dan200.computercraft.ComputerCraft;
 | 
			
		||||
import java.util.concurrent.ThreadFactory;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Provides some utilities to create thread groups
 | 
			
		||||
 * Provides some utilities to create thread groups.
 | 
			
		||||
 */
 | 
			
		||||
public final class ThreadUtils
 | 
			
		||||
{
 | 
			
		||||
@@ -33,7 +33,7 @@ public final class ThreadUtils
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a group under ComputerCraft's shared group
 | 
			
		||||
     * Construct a group under ComputerCraft's shared group.
 | 
			
		||||
     *
 | 
			
		||||
     * @param name The group's name. This will be prefixed with "ComputerCraft-".
 | 
			
		||||
     * @return The constructed thread group.
 | 
			
		||||
 
 | 
			
		||||
@@ -291,7 +291,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
        sLine = ""
 | 
			
		||||
    end
 | 
			
		||||
    local nHistoryPos
 | 
			
		||||
    local nPos = #sLine
 | 
			
		||||
    local nPos, nScroll = #sLine, 0
 | 
			
		||||
    if _sReplaceChar then
 | 
			
		||||
        _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
 | 
			
		||||
    end
 | 
			
		||||
@@ -321,16 +321,20 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
    local sx = term.getCursorPos()
 | 
			
		||||
 | 
			
		||||
    local function redraw( _bClear )
 | 
			
		||||
        local nScroll = 0
 | 
			
		||||
        if sx + nPos >= w then
 | 
			
		||||
            nScroll = (sx + nPos) - w
 | 
			
		||||
        local cursor_pos = nPos - nScroll
 | 
			
		||||
        if sx + cursor_pos >= w then
 | 
			
		||||
            -- We've moved beyond the RHS, ensure we're on the edge.
 | 
			
		||||
            nScroll = sx + nPos - w
 | 
			
		||||
        elseif cursor_pos < 0 then
 | 
			
		||||
            -- We've moved beyond the LHS, ensure we're on the edge.
 | 
			
		||||
            nScroll = nPos
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        local cx,cy = term.getCursorPos()
 | 
			
		||||
        local _, cy = term.getCursorPos()
 | 
			
		||||
        term.setCursorPos( sx, cy )
 | 
			
		||||
        local sReplace = (_bClear and " ") or _sReplaceChar
 | 
			
		||||
        if sReplace then
 | 
			
		||||
            term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) )
 | 
			
		||||
            term.write( string.rep( sReplace, math.max( #sLine - nScroll, 0 ) ) )
 | 
			
		||||
        else
 | 
			
		||||
            term.write( string.sub( sLine, nScroll + 1 ) )
 | 
			
		||||
        end
 | 
			
		||||
@@ -345,7 +349,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
                term.setBackgroundColor( colors.gray )
 | 
			
		||||
            end
 | 
			
		||||
            if sReplace then
 | 
			
		||||
                term.write( string.rep( sReplace, string.len( sCompletion ) ) )
 | 
			
		||||
                term.write( string.rep( sReplace, #sCompletion ) )
 | 
			
		||||
            else
 | 
			
		||||
                term.write( sCompletion )
 | 
			
		||||
            end
 | 
			
		||||
@@ -373,7 +377,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
            -- Find the common prefix of all the other suggestions which start with the same letter as the current one
 | 
			
		||||
            local sCompletion = tCompletions[ nCompletion ]
 | 
			
		||||
            sLine = sLine .. sCompletion
 | 
			
		||||
            nPos = string.len( sLine )
 | 
			
		||||
            nPos = #sLine
 | 
			
		||||
 | 
			
		||||
            -- Redraw
 | 
			
		||||
            recomplete()
 | 
			
		||||
@@ -381,7 +385,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    while true do
 | 
			
		||||
        local sEvent, param = os.pullEvent()
 | 
			
		||||
        local sEvent, param, param1, param2 = os.pullEvent()
 | 
			
		||||
        if sEvent == "char" then
 | 
			
		||||
            -- Typed key
 | 
			
		||||
            clear()
 | 
			
		||||
@@ -394,7 +398,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
            -- Pasted text
 | 
			
		||||
            clear()
 | 
			
		||||
            sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
 | 
			
		||||
            nPos = nPos + string.len( param )
 | 
			
		||||
            nPos = nPos + #param
 | 
			
		||||
            recomplete()
 | 
			
		||||
            redraw()
 | 
			
		||||
 | 
			
		||||
@@ -419,7 +423,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
 | 
			
		||||
            elseif param == keys.right then
 | 
			
		||||
                -- Right
 | 
			
		||||
                if nPos < string.len(sLine) then
 | 
			
		||||
                if nPos < #sLine then
 | 
			
		||||
                    -- Move right
 | 
			
		||||
                    clear()
 | 
			
		||||
                    nPos = nPos + 1
 | 
			
		||||
@@ -470,10 +474,10 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
                    end
 | 
			
		||||
                    if nHistoryPos then
 | 
			
		||||
                        sLine = _tHistory[nHistoryPos]
 | 
			
		||||
                        nPos = string.len( sLine )
 | 
			
		||||
                        nPos, nScroll = #sLine, 0
 | 
			
		||||
                    else
 | 
			
		||||
                        sLine = ""
 | 
			
		||||
                        nPos = 0
 | 
			
		||||
                        nPos, nScroll = 0, 0
 | 
			
		||||
                    end
 | 
			
		||||
                    uncomplete()
 | 
			
		||||
                    redraw()
 | 
			
		||||
@@ -486,6 +490,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
                    clear()
 | 
			
		||||
                    sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
 | 
			
		||||
                    nPos = nPos - 1
 | 
			
		||||
                    if nScroll > 0 then nScroll = nScroll - 1 end
 | 
			
		||||
                    recomplete()
 | 
			
		||||
                    redraw()
 | 
			
		||||
                end
 | 
			
		||||
@@ -501,7 +506,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
 | 
			
		||||
            elseif param == keys.delete then
 | 
			
		||||
                -- Delete
 | 
			
		||||
                if nPos < string.len(sLine) then
 | 
			
		||||
                if nPos < #sLine then
 | 
			
		||||
                    clear()
 | 
			
		||||
                    sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )
 | 
			
		||||
                    recomplete()
 | 
			
		||||
@@ -510,9 +515,9 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
 | 
			
		||||
            elseif param == keys["end"] then
 | 
			
		||||
                -- End
 | 
			
		||||
                if nPos < string.len(sLine ) then
 | 
			
		||||
                if nPos < #sLine then
 | 
			
		||||
                    clear()
 | 
			
		||||
                    nPos = string.len(sLine)
 | 
			
		||||
                    nPos = #sLine
 | 
			
		||||
                    recomplete()
 | 
			
		||||
                    redraw()
 | 
			
		||||
                end
 | 
			
		||||
@@ -523,6 +528,14 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
 | 
			
		||||
 | 
			
		||||
            end
 | 
			
		||||
 | 
			
		||||
        elseif sEvent == "mouse_click" or sEvent == "mouse_drag" and param == 1 then
 | 
			
		||||
            local _, cy = term.getCursorPos()
 | 
			
		||||
            if param1 >= sx and param1 <= w and param2 == cy then
 | 
			
		||||
                -- Ensure we don't scroll beyond the current line
 | 
			
		||||
                nPos = math.min(math.max(nScroll + param1 - sx, 0), #sLine)
 | 
			
		||||
                redraw()
 | 
			
		||||
            end
 | 
			
		||||
 | 
			
		||||
        elseif sEvent == "term_resize" then
 | 
			
		||||
            -- Terminal resized
 | 
			
		||||
            w = term.getSize()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,14 @@
 | 
			
		||||
# New features in CC: Tweaked 1.85.2
 | 
			
		||||
 | 
			
		||||
* Fix crashes when using the mouse with advanced computers.
 | 
			
		||||
 | 
			
		||||
# New features in CC: Tweaked 1.85.1
 | 
			
		||||
 | 
			
		||||
* Add basic mouse support to `read`
 | 
			
		||||
 | 
			
		||||
And several bug fixes:
 | 
			
		||||
* Fix turtles not having breaking particles.
 | 
			
		||||
 | 
			
		||||
# New features in CC: Tweaked 1.85.0
 | 
			
		||||
 | 
			
		||||
* Window.reposition now allows changing the redirect buffer
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,5 @@
 | 
			
		||||
New features in CC: Tweaked 1.85.0
 | 
			
		||||
New features in CC: Tweaked 1.85.2
 | 
			
		||||
 | 
			
		||||
* Window.reposition now allows changing the redirect buffer
 | 
			
		||||
* Add cc.completion and cc.shell.completion modules
 | 
			
		||||
* command.exec also returns the number of affected objects, when exposed by the game.
 | 
			
		||||
 | 
			
		||||
And several bug fixes:
 | 
			
		||||
* Change how turtle mining drops are handled, improving compatibility with some mods.
 | 
			
		||||
* Fix several GUI desyncs after a turtle moves.
 | 
			
		||||
* Fix crashes when using the mouse with advanced computers.
 | 
			
		||||
 | 
			
		||||
Type "help changelog" to see the full version history.
 | 
			
		||||
 
 | 
			
		||||
@@ -37,8 +37,8 @@ import java.util.concurrent.locks.Condition;
 | 
			
		||||
import java.util.concurrent.locks.ReentrantLock;
 | 
			
		||||
import java.util.stream.Stream;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getTable;
 | 
			
		||||
import static dan200.computercraft.core.apis.ArgumentHelper.getType;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getTable;
 | 
			
		||||
import static dan200.computercraft.api.lua.ArgumentHelper.getType;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Loads tests from {@code test-rom/spec} and executes them.
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ import java.net.URISyntaxException;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A very basic environment
 | 
			
		||||
 * A very basic environment.
 | 
			
		||||
 */
 | 
			
		||||
public class BasicEnvironment implements IComputerEnvironment
 | 
			
		||||
{
 | 
			
		||||
@@ -93,7 +93,6 @@ public class BasicEnvironment implements IComputerEnvironment
 | 
			
		||||
        return ComputerCraft.class.getClassLoader().getResourceAsStream( "assets/" + domain + "/" + subPath );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public static IMount createMount( Class<?> klass, String path, String fallback )
 | 
			
		||||
    {
 | 
			
		||||
        File file = getContainingFile( klass );
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ import dan200.computercraft.api.filesystem.IWritableMount;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaAPI;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
import dan200.computercraft.api.lua.LuaException;
 | 
			
		||||
import dan200.computercraft.core.apis.ArgumentHelper;
 | 
			
		||||
import dan200.computercraft.api.lua.ArgumentHelper;
 | 
			
		||||
import dan200.computercraft.core.filesystem.MemoryMount;
 | 
			
		||||
import dan200.computercraft.core.terminal.Terminal;
 | 
			
		||||
import org.apache.logging.log4j.LogManager;
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,10 @@ public class FileSystemTest
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Ensures writing a file truncates it.
 | 
			
		||||
     *
 | 
			
		||||
     * @throws FileSystemException When the file system cannot be constructed.
 | 
			
		||||
     * @throws LuaException When Lua functions fail.
 | 
			
		||||
     * @throws IOException When reading and writing from strings
 | 
			
		||||
     */
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testWriteTruncates() throws FileSystemException, LuaException, IOException
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ import java.io.*;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Mounts in memory
 | 
			
		||||
 * In-memory file mounts.
 | 
			
		||||
 */
 | 
			
		||||
public class MemoryMount implements IWritableMount
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user