1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-16 14:54:54 +00:00

General improvements to the documentation

- Add documentation for all undocumented methods and enums.
 - Use @code, @link and @see where appropriate.
 - Fix spelling in a couple of cases.
This commit is contained in:
SquidDev 2017-05-05 14:56:15 +01:00
parent 09215daa03
commit 7b07921a73
22 changed files with 742 additions and 296 deletions

View File

@ -8,13 +8,16 @@ package dan200.computercraft.api;
import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount; import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.api.media.IMediaProvider; import dan200.computercraft.api.media.IMediaProvider;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider; import dan200.computercraft.api.peripheral.IPeripheralProvider;
import dan200.computercraft.api.permissions.ITurtlePermissionProvider; import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.ITurtleUpgrade;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -52,12 +55,16 @@ public final class ComputerCraftAPI
} }
/** /**
* Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.<br> * Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.
* Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.<br> *
* @param world The world for which the save dir should be created. This should be the serverside world object. * Use in conjunction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
*
* @param world The world for which the save dir should be created. This should be the server side world object.
* @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk" * @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk"
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.<br> * @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing. *
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now
* available for writing.
* @see #createSaveDirMount(World, String, long) * @see #createSaveDirMount(World, String, long)
*/ */
public static int createUniqueNumberedSaveDir( World world, String parentSubPath ) public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
@ -75,19 +82,21 @@ public final class ComputerCraftAPI
} }
/** /**
* Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.<br> * Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.
* Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the *
* users save directory onto a computers file system.<br> * Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the
* @param world The world for which the save dir can be found. This should be the serverside world object. * users save directory onto a computers file system.
* @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".<br> *
* @param world The world for which the save dir can be found. This should be the server side world object.
* @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
* Use createUniqueNumberedSaveDir() to create a new numbered folder to use. * Use createUniqueNumberedSaveDir() to create a new numbered folder to use.
* @param capacity The ammount of data that can be stored in the directory before it fills up, in bytes. * @param capacity The amount of data that can be stored in the directory before it fills up, in bytes.
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
* to mount this on a Computers' file system. * to mount this on a Computers' file system.
* @see #createUniqueNumberedSaveDir(World, String) * @see #createUniqueNumberedSaveDir(World, String)
* @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount) * @see IComputerAccess#mount(String, IMount)
* @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount) * @see IComputerAccess#mountWritable(String, IWritableMount)
* @see dan200.computercraft.api.filesystem.IMount * @see IMount
* @see IWritableMount * @see IWritableMount
*/ */
public static IWritableMount createSaveDirMount( World world, String subPath, long capacity ) public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
@ -105,17 +114,22 @@ public final class ComputerCraftAPI
} }
/** /**
* Creates a file system mount to a resource folder, and returns it.<br> * Creates a file system mount to a resource folder, and returns it.
* Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder onto a computers file system.<br> *
* The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain resources with the same domain and path.<br> * Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder
* onto a computer's file system.
*
* The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain
* resources with the same domain and path.
*
* @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class * @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class
* @param domain The domain under which to look for resources. eg: "mymod" * @param domain The domain under which to look for resources. eg: "mymod"
* @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles" * @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles"
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() * @return The mount, or {@code null} if it could be created for some reason. Use IComputerAccess.mount() or
* to mount this on a Computers' file system. * IComputerAccess.mountWritable() to mount this on a Computers' file system.
* @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount) * @see IComputerAccess#mount(String, IMount)
* @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, IWritableMount) * @see IComputerAccess#mountWritable(String, IWritableMount)
* @see dan200.computercraft.api.filesystem.IMount * @see IMount
*/ */
public static IMount createResourceMount( Class modClass, String domain, String subPath ) public static IMount createResourceMount( Class modClass, String domain, String subPath )
{ {
@ -132,7 +146,8 @@ public final class ComputerCraftAPI
} }
/** /**
* Registers a peripheral handler to convert blocks into IPeripheral implementations. * Registers a peripheral handler to convert blocks into {@link IPeripheral} implementations.
*
* @see dan200.computercraft.api.peripheral.IPeripheral * @see dan200.computercraft.api.peripheral.IPeripheral
* @see dan200.computercraft.api.peripheral.IPeripheralProvider * @see dan200.computercraft.api.peripheral.IPeripheralProvider
*/ */
@ -153,6 +168,7 @@ public final class ComputerCraftAPI
* Registers a new turtle turtle for use in ComputerCraft. After calling this, * Registers a new turtle turtle for use in ComputerCraft. After calling this,
* users should be able to craft Turtles with your new turtle. It is recommended to call * users should be able to craft Turtles with your new turtle. It is recommended to call
* this during the load() method of your mod. * this during the load() method of your mod.
*
* @see dan200.computercraft.api.turtle.ITurtleUpgrade * @see dan200.computercraft.api.turtle.ITurtleUpgrade
*/ */
public static void registerTurtleUpgrade( ITurtleUpgrade upgrade ) public static void registerTurtleUpgrade( ITurtleUpgrade upgrade )
@ -173,6 +189,7 @@ public final class ComputerCraftAPI
/** /**
* Registers a bundled redstone handler to provide bundled redstone output for blocks * Registers a bundled redstone handler to provide bundled redstone output for blocks
*
* @see dan200.computercraft.api.redstone.IBundledRedstoneProvider * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider
*/ */
public static void registerBundledRedstoneProvider( IBundledRedstoneProvider handler ) public static void registerBundledRedstoneProvider( IBundledRedstoneProvider handler )
@ -190,9 +207,10 @@ public final class ComputerCraftAPI
/** /**
* If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output. * If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output.
* @see dan200.computercraft.api.redstone.IBundledRedstoneProvider *
* @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. * @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned.
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned. * If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
* @see dan200.computercraft.api.redstone.IBundledRedstoneProvider
*/ */
public static int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ) public static int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
{ {
@ -209,7 +227,8 @@ public final class ComputerCraftAPI
} }
/** /**
* Registers a media handler to provide IMedia implementations for Items * Registers a media handler to provide {@link IMedia} implementations for Items
*
* @see dan200.computercraft.api.media.IMediaProvider * @see dan200.computercraft.api.media.IMediaProvider
*/ */
public static void registerMediaProvider( IMediaProvider handler ) public static void registerMediaProvider( IMediaProvider handler )
@ -227,6 +246,7 @@ public final class ComputerCraftAPI
/** /**
* Registers a permission handler to restrict where turtles can move or build * Registers a permission handler to restrict where turtles can move or build
*
* @see dan200.computercraft.api.permissions.ITurtlePermissionProvider * @see dan200.computercraft.api.permissions.ITurtlePermissionProvider
*/ */
public static void registerPermissionProvider( ITurtlePermissionProvider handler ) public static void registerPermissionProvider( ITurtlePermissionProvider handler )

View File

@ -6,52 +6,66 @@
package dan200.computercraft.api.filesystem; package dan200.computercraft.api.filesystem;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IComputerAccess;
import net.minecraft.world.World;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
/** /**
* Represents a read only part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount(). * Represents a read only part of a virtual filesystem that can be mounted onto a computer using
* Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount() or ComputerCraftAPI.createResourceMount(), or you're free to implement it yourselves! * {@link IComputerAccess#mount(String, IMount)}
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) *
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) * Ready made implementations of this interface can be created using
* @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, IMount) * {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
* {@link ComputerCraftAPI#createResourceMount(Class, String, String)}, or you're free to implement it yourselves!
*
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
* @see IComputerAccess#mount(String, IMount)
* @see IWritableMount * @see IWritableMount
*/ */
public interface IMount public interface IMount
{ {
/** /**
* Returns whether a file with a given path exists or not. * Returns whether a file with a given path exists or not.
*
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return true if the file exists, false otherwise * @return If the file exists.
*/ */
public boolean exists( String path ) throws IOException; public boolean exists( String path ) throws IOException;
/** /**
* Returns whether a file with a given path is a directory or not. * Returns whether a file with a given path is a directory or not.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms" *
* @return true if the file exists and is a directory, false otherwise * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
* @return If the file exists and is a directory
*/ */
public boolean isDirectory( String path ) throws IOException; public boolean isDirectory( String path ) throws IOException;
/** /**
* Returns the file names of all the files in a directory. * Returns the file names of all the files in a directory.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms" *
* @param contents A list of strings. Add all the file names to this list * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
* @param contents A list of strings. Add all the file names to this list.
*/ */
public void list( String path, List<String> contents ) throws IOException; public void list( String path, 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 * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return The size of the file, in bytes.
*/ */
public long getSize( String path ) throws IOException; public long getSize( String path ) throws IOException;
/** /**
* Opens a file with a given path, and returns an inputstream representing it's contents. * Opens a file with a given path, and returns an {@link InputStream} representing its contents.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" *
* @return a stream representing the contents of the file * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return A stream representing the contents of the file.
*/ */
public InputStream openForRead( String path ) throws IOException; public InputStream openForRead( String path ) throws IOException;
} }

View File

@ -6,47 +6,62 @@
package dan200.computercraft.api.filesystem; package dan200.computercraft.api.filesystem;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IComputerAccess;
import net.minecraft.world.World;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
/** /**
* Represents a part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount() or IComputerAccess.mountWritable(), that can also be written to. * Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}
* Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount(), or you're free to implement it yourselves! * or {@link IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) *
* @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IMount) * Ready made implementations of this interface can be created using
* @see dan200.computercraft.api.filesystem.IMount * {@link ComputerCraftAPI#createSaveDirMount(World, String, long)}, or you're free to implement it yourselves!
*
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
* @see IComputerAccess#mount(String, IMount)
* @see IComputerAccess#mountWritable(String, IWritableMount)
* @see IMount
*/ */
public interface IWritableMount extends IMount public interface IWritableMount extends IMount
{ {
/** /**
* Creates a directory at a given path inside the virtual file system. * Creates a directory at a given path inside the virtual file system.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms" *
* @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms".
*/ */
public void makeDirectory( String path ) throws IOException; public void makeDirectory( String path ) throws IOException;
/** /**
* Deletes a directory at a given path inside the virtual file system. * Deletes a directory at a given path inside the virtual file system.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms" *
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms".
*/ */
public void delete( String path ) throws IOException; public void delete( String path ) throws IOException;
/** /**
* Opens a file with a given path, and returns an outputstream for writing to it. * Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" *
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return a stream for writing to * @return a stream for writing to
*/ */
public OutputStream openForWrite( String path ) throws IOException; public OutputStream openForWrite( String path ) throws IOException;
/** /**
* Opens a file with a given path, and returns an outputstream for appending to it. * Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" *
* @return a stream for writing to * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return A stream for writing to.
*/ */
public OutputStream openForAppend( String path ) throws IOException; public OutputStream openForAppend( String path ) throws IOException;
/** /**
* Get the ammount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail once it reaches zero. * Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the
* @return The ammount of free space, in bytes. * mount, and write operations should fail once it reaches zero.
*
* @return The amount of free space, in bytes.
*/ */
public long getRemainingSpace() throws IOException; public long getRemainingSpace() throws IOException;
} }

View File

@ -7,52 +7,84 @@
package dan200.computercraft.api.lua; package dan200.computercraft.api.lua;
/** /**
* An interface passed to peripherals and ILuaObjects' by computers or turtles, providing methods * An interface passed to peripherals and {@link ILuaObject}s by computers or turtles, providing methods
* that allow the peripheral call to wait for events before returning, just like in lua. * that allow the peripheral call to wait for events before returning, just like in lua. This is very useful if you need
* This is very useful if you need to signal work to be performed on the main thread, and don't want to return * to signal work to be performed on the main thread, and don't want to return until the work has been completed.
* until the work has been completed.
*/ */
public interface ILuaContext public interface ILuaContext
{ {
/** /**
* Wait for an event to occur on the computercraft, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua. * Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly
* @param filter A specific event to wait for, or null to wait for any event * equivalent to {@code os.pullEvent()} in lua.
* @return An object array containing the name of the event that occurred, and any event parameters *
* @throws Exception If the user presses CTRL+T to terminate the current program while pullEvent() is waiting for an event, a "Terminated" exception will be thrown here. * @param filter A specific event to wait for, or null to wait for any event.
* Do not attempt to common this exception, unless you wish to prevent termination, which is not recommended. * @return An object array containing the name of the event that occurred, and any event parameters.
* @throws InterruptedException If the user shuts down or reboots the computercraft while pullEvent() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. * @throws LuaException If the user presses CTRL+T to terminate the current program while pullEvent() is
* waiting for an event, a "Terminated" exception will be thrown here.
*
* Do not attempt to catch this exception. You should use {@link #pullEventRaw(String)}
* should you wish to disable termination.
* @throws InterruptedException If the user shuts down or reboots the computer while pullEvent() is waiting for an
* event, 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.
*/ */
public Object[] pullEvent( String filter ) throws LuaException, InterruptedException; public Object[] pullEvent( String filter ) throws LuaException, InterruptedException;
/** /**
* The same as pullEvent(), except "terminated" events are ignored. Only use this if you want to prevent program termination, which is not recommended. This method is exactly equivalent to os.pullEventRaw() in lua. * The same as {@link #pullEvent(String)}, except "terminated" events are ignored. Only use this if you want to
* @param filter A specific event to wait for, or null to wait for any event * prevent program termination, which is not recommended. This method is exactly equivalent to
* @return An object array containing the name of the event that occurred, and any event parameters * {@code os.pullEventRaw()} in lua.
* @throws InterruptedException If the user shuts down or reboots the computercraft while pullEventRaw() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. *
* @param filter A specific event to wait for, or null to wait for any event.
* @return An object array containing the name of the event that occurred, and any event parameters.
* @throws InterruptedException If the user shuts down or reboots the computer while pullEventRaw() is waiting for
* an event, 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 #pullEvent(String) * @see #pullEvent(String)
*/ */
public Object[] pullEventRaw( String filter ) throws InterruptedException; public Object[] pullEventRaw( String filter ) throws InterruptedException;
/** /**
* Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events. * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to
* {@code coroutine.yield()} in lua. Use {@code pullEvent()} if you wish to wait for events.
*
* @param arguments An object array containing the arguments to pass to coroutine.yield() * @param arguments An object array containing the arguments to pass to coroutine.yield()
* @return An object array containing the return values from coroutine.yield() * @return An object array containing the return values from coroutine.yield()
* @throws InterruptedException If the user shuts down or reboots the computercraft the coroutine is suspended, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. * @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended,
* 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 #pullEvent(String) * @see #pullEvent(String)
*/ */
public Object[] yield( Object[] arguments ) throws InterruptedException; public Object[] yield( Object[] arguments ) throws InterruptedException;
/** /**
* TODO: Document me * Queue a task to be executed on the main server thread at the beginning of next tick, waiting for it to complete.
* @param task * This should be used when you need to interact with the world in a thread-safe manner.
* @return *
* Note that the return values of your task are handled as events, meaning more complex objects such as maps or
* {@link ILuaObject} will not preserve their identities.
*
* @param task The task to execute on the main thread.
* @return The objects returned by {@code task}.
* @throws LuaException If the task could not be queued, or if the task threw an exception.
* @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended,
* 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.
*/ */
public Object[] executeMainThreadTask( ILuaTask task ) throws LuaException, InterruptedException; public Object[] executeMainThreadTask( ILuaTask task ) throws LuaException, InterruptedException;
/** /**
* TODO: Document me * Queue a task to be executed on the main server thread at the beginning of next tick, but do not wait for it to
* @param task * complete. This should be used when you need to interact with the world in a thread-safe manner but do not care
* @return * about the result or you wish to run asynchronously.
*
* When the task has finished, it will enqueue a {@code task_completed} event, which takes the task id, a success
* value and the return values, or an error message if it failed. If you need to wait on this event, it may be
* better to use {@link #executeMainThreadTask(ILuaTask)}.
*
* @param task The task to execute on the main thread.
* @return The "id" of the task. This will be the first argument to the {@code task_completed} event.
* @throws LuaException If the task could not be queued.
*/ */
public long issueMainThreadTask( ILuaTask task ) throws LuaException; public long issueMainThreadTask( ILuaTask task ) throws LuaException;
} }

View File

@ -6,21 +6,35 @@
package dan200.computercraft.api.lua; package dan200.computercraft.api.lua;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
/** /**
* An interface for representing custom objects returned by IPeripheral.callMethod() calls. * An interface for representing custom objects returned by {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}
* calls.
*
* Return objects implementing this interface to expose objects with methods to lua. * Return objects implementing this interface to expose objects with methods to lua.
*/ */
public interface ILuaObject public interface ILuaObject
{ {
/** /**
* Get the names of the methods that this object implements. This works the same as IPeripheral.getMethodNames(). See that method for detailed documentation. * Get the names of the methods that this object implements. This works the same as {@link IPeripheral#getMethodNames()}.
* @see dan200.computercraft.api.peripheral.IPeripheral#getMethodNames() * See that method for detailed documentation.
*
* @see IPeripheral#getMethodNames()
*/ */
public String[] getMethodNames(); public String[] getMethodNames();
/** /**
* Called when a user calls one of the methods that this object implements. This works the same as IPeripheral.callMethod(). See that method for detailed documentation. * Called when a user calls one of the methods that this object implements. This works the same as
* @see dan200.computercraft.api.peripheral.IPeripheral#callMethod(dan200.computercraft.api.peripheral.IComputerAccess, ILuaContext, int, Object[]) * {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}}. See that method for detailed
* documentation.
*
* @throws LuaException If the task could not be queued, or if the task threw an exception.
* @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended,
* 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.w
* @see IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])
*/ */
public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException; public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
} }

View File

@ -6,7 +6,24 @@
package dan200.computercraft.api.lua; package dan200.computercraft.api.lua;
/**
* A task which can be executed via {@link ILuaContext#executeMainThreadTask(ILuaTask)} or
* {@link ILuaContext#issueMainThreadTask(ILuaTask)}. This will be run on the main thread, at the beginning of the
* next tick.
*
* @see ILuaContext#executeMainThreadTask(ILuaTask)
* @see ILuaContext#issueMainThreadTask(ILuaTask)
*/
public interface ILuaTask public interface ILuaTask
{ {
/**
* Execute this task.
*
* @return The arguments to add to the {@code task_completed} event. These will be returned by
* {@link ILuaContext#executeMainThreadTask(ILuaTask)}.
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the
* same message as your exception. Use this to throw appropriate errors if the wrong
* arguments are supplied to your method.
*/
public Object[] execute() throws LuaException; public Object[] execute() throws LuaException;
} }

View File

@ -7,10 +7,11 @@
package dan200.computercraft.api.lua; package dan200.computercraft.api.lua;
/** /**
* An exception representing an error in Lua, like that raised by the error() function * An exception representing an error in Lua, like that raised by the {@code error()} function.
*/ */
public class LuaException extends Exception public class LuaException extends Exception
{ {
private static final long serialVersionUID = -6136063076818512651L;
private final int m_level; private final int m_level;
public LuaException() public LuaException()
@ -29,6 +30,12 @@ public class LuaException extends Exception
m_level = level; m_level = level;
} }
/**
* The level this error is raised at. Level 1 is the function's caller, level 2 is that function's caller, and so
* on.
*
* @return The level to raise the error at.
*/
public int getLevel() public int getLevel()
{ {
return m_level; return m_level;

View File

@ -18,14 +18,16 @@ import net.minecraft.world.World;
public interface IMedia public interface IMedia
{ {
/** /**
* Get a string representing the label of this item. Will be called vi disk.getLabel() in lua. * Get a string representing the label of this item. Will be called via {@code disk.getLabel()} in lua.
* @param stack The itemstack to inspect *
* @return The label. ie: "Dan's Programs" * @param stack The itemstack to inspect.
* @return The label. ie: "Dan's Programs".
*/ */
public String getLabel( ItemStack stack ); public String getLabel( ItemStack stack );
/** /**
* Set a string representing the label of this item. Will be called vi disk.setLabel() in lua. * Set a string representing the label of this item. Will be called vi {@code disk.setLabel()} in lua.
*
* @param stack The itemstack to modify. * @param stack The itemstack to modify.
* @param label The string to set the label to. * @param label The string to set the label to.
* @return true if the label was updated, false if the label may not be modified. * @return true if the label was updated, false if the label may not be modified.
@ -33,7 +35,9 @@ public interface IMedia
public boolean setLabel( ItemStack stack, String label ); public boolean setLabel( ItemStack stack, String label );
/** /**
* If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: "Jonathon Coulton - Still Alive" * If this disk represents an item with audio (like a record), get the readable name of the audio track. ie:
* "Jonathon Coulton - Still Alive"
*
* @param stack The itemstack to inspect. * @param stack The itemstack to inspect.
* @return The name, or null if this item does not represent an item with audio. * @return The name, or null if this item does not represent an item with audio.
*/ */
@ -41,16 +45,20 @@ public interface IMedia
/** /**
* If this disk represents an item with audio (like a record), get the resource name of the audio track to play. * If this disk represents an item with audio (like a record), get the resource name of the audio track to play.
*
* @param stack The itemstack to inspect. * @param stack The itemstack to inspect.
* @return The name, or null if this item does not represent an item with audio. * @return The name, or null if this item does not represent an item with audio.
*/ */
public SoundEvent getAudio( ItemStack stack ); public SoundEvent getAudio( ItemStack stack );
/** /**
* If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of the computercraft while the media is in the disk drive. * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will
* be mounted onto the filesystem of the computer while the media is in the disk drive.
*
* @param stack The itemstack to inspect. * @param stack The itemstack to inspect.
* @param world The world in which the item and disk drive reside. * @param world The world in which the item and disk drive reside.
* @return The mount, or null if this item does not represent an item with data. If the IMount returned also implements IWritableMount, it will mounted using mountWritable() * @return The mount, or null if this item does not represent an item with data. If the mount returned also
* implements {@link dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
* @see dan200.computercraft.api.filesystem.IMount * @see dan200.computercraft.api.filesystem.IMount
* @see dan200.computercraft.api.filesystem.IWritableMount * @see dan200.computercraft.api.filesystem.IWritableMount
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long) * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)

View File

@ -9,15 +9,17 @@ package dan200.computercraft.api.media;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
/** /**
* This interface is used to provide IMedia implementations for ItemStack * This interface is used to provide {@link IMedia} implementations for {@link ItemStack}.
*
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider)
*/ */
public interface IMediaProvider public interface IMediaProvider
{ {
/** /**
* Produce an IMedia implementation from an ItemStack. * Produce an IMedia implementation from an ItemStack.
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) *
* @return an IMedia implementation, or null if the item is not something you wish to handle * @return an IMedia implementation, or null if the item is not something you wish to handle
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider)
*/ */
public IMedia getMedia( ItemStack stack ); public IMedia getMedia( ItemStack stack );
} }

View File

@ -6,8 +6,10 @@
package dan200.computercraft.api.peripheral; package dan200.computercraft.api.peripheral;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount; import dan200.computercraft.api.filesystem.IWritableMount;
import net.minecraft.world.World;
/** /**
* The interface passed to peripherals by computers or turtles, providing methods * The interface passed to peripherals by computers or turtles, providing methods
@ -17,30 +19,50 @@ import dan200.computercraft.api.filesystem.IWritableMount;
public interface IComputerAccess public interface IComputerAccess
{ {
/** /**
* Mount a mount onto the computers' file system in a read only mode.<br> * Mount a mount onto the computer's file system in a read only mode.
* @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted. *
* @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount(), ComputerCraftAPI.createResourceMount() or by creating your own objects that implement the IMount interface. * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
* @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. * @param mount The mount object to mount on the computer.
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) * @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) * file in the desired location. Store this value if you wish to unmount the mount later.
* @see #mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount) * @throws RuntimeException If the peripheral has been detached.
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
* @see #mount(String, IMount, String)
* @see #mountWritable(String, IWritableMount)
* @see #unmount(String) * @see #unmount(String)
* @see dan200.computercraft.api.filesystem.IMount * @see IMount
*/ */
public String mount( String desiredLocation, IMount mount ); public String mount( String desiredLocation, IMount mount );
/** /**
* TODO: Document me * Mount a mount onto the computer's file system in a read only mode.
*
* @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
* @param mount The mount object to mount on the computer.
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
* file in the desired location. Store this value if you wish to unmount the mount later.
* @throws RuntimeException If the peripheral has been detached.
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
* @see #mount(String, IMount)
* @see #mountWritable(String, IWritableMount)
* @see #unmount(String)
* @see IMount
*/ */
public String mount( String desiredLocation, IMount mount, String driveName ); public String mount( String desiredLocation, IMount mount, String driveName );
/** /**
* Mount a mount onto the computers' file system in a writable mode.<br> * Mount a mount onto the computer's file system in a writable mode.
* @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted. *
* @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount() or by creating your own objects that implement the IWritableMount interface. * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
* @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. * @param mount The mount object to mount on the computer.
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) * @return The location on the computer's file system where you the mount mounted, or null if there was already a
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) * file in the desired location. Store this value if you wish to unmount the mount later.
* @throws RuntimeException If the peripheral has been detached.
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
* @see #mount(String, IMount) * @see #mount(String, IMount)
* @see #unmount(String) * @see #unmount(String)
* @see IMount * @see IMount
@ -48,55 +70,81 @@ public interface IComputerAccess
public String mountWritable( String desiredLocation, IWritableMount mount ); public String mountWritable( String desiredLocation, IWritableMount mount );
/** /**
* TODO: Document me * Mount a mount onto the computer's file system in a writable mode.
*
* @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
* @param mount The mount object to mount on the computer.
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
* file in the desired location. Store this value if you wish to unmount the mount later.
* @throws RuntimeException If the peripheral has been detached.
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
* @see #mount(String, IMount)
* @see #unmount(String)
* @see IMount
*/ */
public String mountWritable( String desiredLocation, IWritableMount mount, String driveName ); public String mountWritable( String desiredLocation, IWritableMount mount, String driveName );
/** /**
* Unmounts a directory previously mounted onto the computers file system by mount() or mountWritable().<br> * Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, IMount)}
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to * or {@link #mountWritable(String, IWritableMount)}.
* access it. All directories mounted by a mount or mountWritable are automatically unmounted when the peripheral *
* is attached if they have not been explicitly unmounted. * When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be
* able to access it. All directories mounted by a mount or mountWritable are automatically unmounted when the
* peripheral is attached if they have not been explicitly unmounted.
*
* Note that you cannot unmount another peripheral's mounts.
*
* @param location The desired location in the computers file system of the directory to unmount. * @param location The desired location in the computers file system of the directory to unmount.
* This must be the location of a directory previously mounted by mount() or mountWritable(), as * This must be the location of a directory previously mounted by {@link #mount(String, IMount)} or
* indicated by their return value. * {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
* @throws RuntimeException If the peripheral has been detached.
* @throws RuntimeException If the mount does not exist, or was mounted by another peripheral.
* @see #mount(String, IMount) * @see #mount(String, IMount)
* @see #mountWritable(String, IWritableMount) * @see #mountWritable(String, IWritableMount)
*/ */
public void unmount( String location ); public void unmount( String location );
/** /**
* Returns the numerical ID of this computercraft.<br> * Returns the numerical ID of this computer.
* This is the same number obtained by calling os.getComputerID() or running the "id" program from lua, *
* and is guarunteed unique. This number will be positive. * This is the same number obtained by calling {@code os.getComputerID()} or running the "id" program from lua,
* and is guaranteed unique. This number will be positive.
*
* @return The identifier. * @return The identifier.
*/ */
public int getID(); public int getID();
/** /**
* Causes an event to be raised on this computercraft, which the computercraft can respond to by calling * Causes an event to be raised on this computer, which the computer can respond to by calling
* os.pullEvent(). This can be used to notify the computercraft when things happen in the world or to * {@code os.pullEvent()}. This can be used to notify the computer when things happen in the world or to
* this peripheral. * this peripheral.
*
* @param event A string identifying the type of event that has occurred, this will be * @param event A string identifying the type of event that has occurred, this will be
* returned as the first value from os.pullEvent(). It is recommended that you * returned as the first value from {@code os.pullEvent()}. It is recommended that you
* you choose a name that is unique, and recognisable as originating from your * you choose a name that is unique, and recognisable as originating from your
* peripheral. eg: If your peripheral type is "button", a suitable event would be * peripheral. eg: If your peripheral type is "button", a suitable event would be
* "button_pressed". * "button_pressed".
* @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will * @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will
* be supplied as extra return values to os.pullEvent(). Objects in the array will be converted * be supplied as extra return values to os.pullEvent(). Objects in the array will be converted
* to lua data types in the same fashion as the return values of IPeripheral.callMethod().<br> * to lua data types in the same fashion as the return values of IPeripheral.callMethod().
* You may supply null to indicate that no arguments are to be supplied. *
* You may supply {@code null} to indicate that no arguments are to be supplied.
* @throws RuntimeException If the peripheral has been detached.
* @see dan200.computercraft.api.peripheral.IPeripheral#callMethod * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod
*/ */
public void queueEvent( String event, Object[] arguments ); public void queueEvent( String event, Object[] arguments );
/** /**
* Get a string, unique to the computercraft, by which the computercraft refers to this peripheral. * Get a string, unique to the computer, by which the computer refers to this peripheral.
* For directly attached peripherals this will be "left","right","front","back",etc, but * For directly attached peripherals this will be "left","right","front","back",etc, but
* for peripherals attached remotely it will be different. It is good practice to supply * for peripherals attached remotely it will be different. It is good practice to supply
* this string when raising events to the computercraft, so that the computercraft knows from * this string when raising events to the computer, so that the computer knows from
* which peripheral the event came. * which peripheral the event came.
* @return A string unique to the computercraft, but not globally. *
* @return A string unique to the computer, but not globally.
* @throws RuntimeException If the peripheral has been detached.
*/ */
public String getAttachmentName(); public String getAttachmentName();
} }

View File

@ -10,13 +10,14 @@ import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaException;
/** /**
* The interface that defines a peripheral. See IPeripheralProvider for how to associate blocks with peripherals. * The interface that defines a peripheral. See {@link IPeripheralProvider} for how to associate blocks with peripherals.
*/ */
public interface IPeripheral public interface IPeripheral
{ {
/** /**
* Should return a string that uniquely identifies this type of peripheral. * Should return a string that uniquely identifies this type of peripheral.
* This can be queried from lua by calling peripheral.getType() * This can be queried from lua by calling {@code peripheral.getType()}
*
* @return A string identifying the type of peripheral. * @return A string identifying the type of peripheral.
*/ */
public String getType(); public String getType();
@ -25,74 +26,92 @@ public interface IPeripheral
* Should return an array of strings that identify the methods that this * Should return an array of strings that identify the methods that this
* peripheral exposes to Lua. This will be called once before each attachment, * peripheral exposes to Lua. This will be called once before each attachment,
* and should not change when called multiple times. * and should not change when called multiple times.
*
* @return An array of strings representing method names. * @return An array of strings representing method names.
* @see #callMethod * @see #callMethod
*/ */
public String[] getMethodNames(); public String[] getMethodNames();
/** /**
* This is called when a lua program on an attached computercraft calls peripheral.call() with * This is called when a lua program on an attached computer calls {@code peripheral.call()} with
* one of the methods exposed by getMethodNames().<br> * one of the methods exposed by {@link #getMethodNames()}.
* <br> *
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
* when interacting with minecraft objects. * when interacting with Minecraft objects.
* @param computer The interface to the computercraft that is making the call. Remember that multiple *
* @param computer The interface to the computer that is making the call. Remember that multiple
* computers can be attached to a peripheral at once. * computers can be attached to a peripheral at once.
* @param context The context of the currently running lua thread. This can be used to wait for events * @param context The context of the currently running lua thread. This can be used to wait for events
* or otherwise yield. * or otherwise yield.
* @param method An integer identifying which of the methods from getMethodNames() the computercraft * @param method An integer identifying which of the methods from getMethodNames() the computercraft
* wishes to call. The integer indicates the index into the getMethodNames() table * wishes to call. The integer indicates the index into the getMethodNames() table
* that corresponds to the string passed into peripheral.call() * that corresponds to the string passed into peripheral.call()
* @param arguments An array of objects, representing the arguments passed into peripheral.call().<br> * @param arguments An array of objects, representing the arguments passed into {@code peripheral.call()}.<br>
* Lua values of type "string" will be represented by Object type String.<br> * Lua values of type "string" will be represented by Object type String.<br>
* Lua values of type "number" will be represented by Object type Double.<br> * Lua values of type "number" will be represented by Object type Double.<br>
* Lua values of type "boolean" will be represented by Object type Boolean.<br> * Lua values of type "boolean" will be represented by Object type Boolean.<br>
* 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> * Lua values of any other type will be represented by a null object.<br>
* This array will be empty if no arguments are passed. * This array will be empty if no arguments are passed.
* @return An array of objects, representing values you wish to return to the lua program.<br> * @return An array of objects, representing values you wish to return to the lua program. Integers, Doubles, Floats,
* Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br> * Strings, Booleans, Maps and ILuaObject and null be converted to their corresponding lua type. All other types
* All other types will be converted to nil.<br> * will be converted to nil.
*
* You may return null to indicate no values should be returned. * You may return null to indicate no values should be returned.
* @throws Exception If you throw any exception from this function, a lua error will be raised with the * @throws LuaException If you throw any exception from this function, a lua error will be raised with the
* same message as your exception. Use this to throw appropriate errors if the wrong * same message as your exception. Use this to throw appropriate errors if the wrong
* arguments are supplied to your method. * arguments are supplied to your method.
* @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended,
* 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 #getMethodNames
*/ */
public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException; public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
/** /**
* Is called when canAttachToSide has returned true, and a computercraft is attaching to the peripheral. * Is called when canAttachToSide has returned true, and a computer is attaching to the peripheral.
* This will occur when a peripheral is placed next to an active computercraft, when a computercraft is turned on next to a peripheral, *
* or when a turtle travels into a square next to a peripheral. * This will occur when a peripheral is placed next to an active computer, when a computer is turned on next to a
* Between calls to attach() and detach(), the attached computercraft can make method calls on the peripheral using peripheral.call(). * peripheral, or when a turtle travels into a square next to a peripheral.
* This method can be used to keep track of which computers are attached to the peripheral, or to take action when attachment *
* occurs.<br> * Between calls to attach() and detach(), the attached computer can make method calls on the peripheral using
* <br> * {@code peripheral.call()}. This method can be used to keep track of which computers are attached to the
* peripheral, or to take action when attachment occurs.
*
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
* when interacting with minecraft objects. * when interacting with Minecraft objects.
* @param computer The interface to the computercraft that is being attached. Remember that multiple *
* @param computer The interface to the computer that is being attached. Remember that multiple
* computers can be attached to a peripheral at once. * computers can be attached to a peripheral at once.
* @see #detach * @see #detach
*/ */
public void attach( IComputerAccess computer ); public void attach( IComputerAccess computer );
/** /**
* Is called when a computercraft is detaching from the peripheral. * Is called when a computer is detaching from the peripheral.
* This will occur when a computercraft shuts down, when the peripheral is removed while attached to computers, *
* or when a turtle moves away from a square attached to a peripheral. * This will occur when a computer shuts down, when the peripheral is removed while attached to computers,
* This method can be used to keep track of which computers are attached to the peripheral, or to take action when detachment * or when a turtle moves away from a square attached to a peripheral. This method can be used to keep track of
* occurs.<br> * which computers are attached to the peripheral, or to take action when detachment
* <br> * occurs.
*
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
* when interacting with minecraft objects. * when interacting with Minecraft objects.
* @param computer The interface to the computercraft that is being detached. Remember that multiple *
* @param computer The interface to the computer that is being detached. Remember that multiple
* computers can be attached to a peripheral at once. * computers can be attached to a peripheral at once.
* @see #detach * @see #detach
*/ */
public void detach( IComputerAccess computer ); public void detach( IComputerAccess computer );
/** /**
* TODO: Document me * Determine whether this peripheral is equivalent to another one.
*
* The minimal example should at least check whether they are the same object. However, you may wish to check if
* they point to the same block or tile entity.
*
* @param other The peripheral to compare against. This may be {@code null}.
* @return Whether these peripherals are equivalent.
*/ */
public boolean equals( IPeripheral other ); public boolean equals( IPeripheral other );
} }

View File

@ -6,20 +6,22 @@
package dan200.computercraft.api.peripheral; package dan200.computercraft.api.peripheral;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
* This interface is used to create peripheral implementations for blocks * This interface is used to create peripheral implementations for blocks.
*
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
*/ */
public interface IPeripheralProvider public interface IPeripheralProvider
{ {
/** /**
* Produce an peripheral implementation from a block location. * Produce an peripheral implementation from a block location.
*
* @return A peripheral, or {@code null} if there is not a peripheral here you'd like to handle.
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
* @return a peripheral, or null if there is not a peripheral here you'd like to handle.
*/ */
public IPeripheral getPeripheral( World world, BlockPos pos, EnumFacing side ); public IPeripheral getPeripheral( World world, BlockPos pos, EnumFacing side );
} }

View File

@ -10,11 +10,31 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
* This interface is used to restrict where turtles can move or build * This interface is used to restrict where turtles can move or build.
*
* Turtles will call these methods before attempting to perform an action, allowing them to be cancelled.
*
* @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider) * @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider)
*/ */
public interface ITurtlePermissionProvider public interface ITurtlePermissionProvider
{ {
/**
* Determine whether a block can be entered by a turtle.
*
* @param world The world the block exists in
* @param pos The location of the block.
* @return Whether the turtle can move into this block.
*/
public boolean isBlockEnterable( World world, BlockPos pos ); public boolean isBlockEnterable( World world, BlockPos pos );
/**
* Determine whether a block can be modified by a turtle.
*
* This includes breaking and placing blocks.
*
* @param world The world the block exists in
* @param pos The location of the block.
* @return Whether the turtle can modify this block.
*/
public boolean isBlockEditable( World world, BlockPos pos ); public boolean isBlockEditable( World world, BlockPos pos );
} }

View File

@ -6,20 +6,23 @@
package dan200.computercraft.api.redstone; package dan200.computercraft.api.redstone;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
* This interface is used to provide bundled redstone output for blocks * This interface is used to provide bundled redstone output for blocks.
*
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
*/ */
public interface IBundledRedstoneProvider public interface IBundledRedstoneProvider
{ {
/** /**
* Produce an bundled redstone output from a block location. * Produce an bundled redstone output from a block location.
*
* @return A number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to
* handle this block.
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
* @return a number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to handle this block
*/ */
public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ); public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side );
} }

View File

@ -11,114 +11,179 @@ import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
* The interface passed to turtle by turtles, providing methods that they can call. * The interface passed to turtle by turtles, providing methods that they can call.
* This should not be implemented by your classes. Do not interact with turtles except via this interface and ITurtleUpgrade. *
* This should not be implemented by your classes. Do not interact with turtles except via this interface and
* {@link ITurtleUpgrade}.
*/ */
public interface ITurtleAccess public interface ITurtleAccess
{ {
/** /**
* Returns the world in which the turtle resides. * Returns the world in which the turtle resides.
*
* @return the world in which the turtle resides. * @return the world in which the turtle resides.
*/ */
public World getWorld(); public World getWorld();
/** /**
* Returns a vector containing the integer co-ordinates at which the turtle resides. * Returns a vector containing the integer co-ordinates at which the turtle resides.
*
* @return a vector containing the integer co-ordinates at which the turtle resides. * @return a vector containing the integer co-ordinates at which the turtle resides.
*/ */
public BlockPos getPosition(); public BlockPos getPosition();
/** /**
* TODO: Document me * Attempt to move this turtle to a new position.
*
* This will preserve the turtle's internal state, such as it's inventory, computer and upgrades. It should
* be used before playing a movement animation using {@link #playAnimation(TurtleAnimation)}.
*
* @param world The new world to move it to
* @param pos The new position to move it to.
* @return Whether the movement was successful. It may fail if the block was not loaded or the block placement
* was cancelled. Note this will not check
* {@link dan200.computercraft.api.permissions.ITurtlePermissionProvider#isBlockEnterable(World, BlockPos)}.
* @throws UnsupportedOperationException When attempting to teleport on the client side.
*/ */
public boolean teleportTo( World world, BlockPos pos ); public boolean teleportTo( World world, BlockPos pos );
/** /**
* Returns a vector containing the floating point co-ordinates at which the turtle is rendered. * Returns a vector containing the floating point co-ordinates at which the turtle is rendered.
* This will shift when the turtle is moving. * This will shift when the turtle is moving.
* @param f The subframe fraction *
* @return a vector containing the floating point co-ordinates at which the turtle resides. * @param f The subframe fraction.
* @return A vector containing the floating point co-ordinates at which the turtle resides.
* @see #getVisualYaw(float)
*/ */
public Vec3d getVisualPosition( float f ); public Vec3d getVisualPosition( float f );
/** /**
* TODO: Document me * Returns the yaw the turtle is facing when it is rendered.
*
* @param f The subframe fraction.
* @return The yaw the turtle is facing.
* @see #getVisualPosition(float)
*/ */
public float getVisualYaw( float f ); public float getVisualYaw( float f );
/** /**
* Returns the world direction the turtle is currently facing. * Returns the world direction the turtle is currently facing.
* @return the world direction the turtle is currently facing. *
* @return The world direction the turtle is currently facing.
* @see #setDirection(EnumFacing)
*/ */
public EnumFacing getDirection(); public EnumFacing getDirection();
/** /**
* TODO: Document me * Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to
* call {@link #playAnimation(TurtleAnimation)} to do so.
*
* @param dir The new direction to set. This should be on either the x or z axis (so north, south, east or west).
* @see #getDirection()
*/ */
public void setDirection( EnumFacing dir ); public void setDirection( EnumFacing dir );
/** /**
* TODO: Document me * Get the currently selected slot in the turtle's inventory.
*
* @return An integer representing the current slot.
* @see #getInventory()
* @see #setSelectedSlot(int)
*/ */
public int getSelectedSlot(); public int getSelectedSlot();
/** /**
* TODO: Document me * Set the currently selected slot in the turtle's inventory.
*
* @param slot The slot to set. This must be greater or equal to 0 and less than the inventory size. Otherwise no
* action will be taken.
* @throws UnsupportedOperationException When attempting to change the slot on the client side.
* @see #getInventory()
* @see #getSelectedSlot()
*/ */
public void setSelectedSlot( int slot ); public void setSelectedSlot( int slot );
/** /**
* Sets the colour of the turtle, as if the player had dyed it with a dye item. * Sets the colour of the turtle, as if the player had dyed it with a dye item.
* @param dyeColour 0-15 to dye the turtle one of the 16 standard minecraft colours, or -1 to remove the dye from the turtle. *
* @param dyeColour 0-15 to dye the turtle one of the 16 standard Minecraft colours, or -1 to remove the dye from the turtle.
* @see #getDyeColour()
*/ */
public void setDyeColour( int dyeColour ); public void setDyeColour( int dyeColour );
/** /**
* Gets the colour the turtle has been dyed. * Gets the colour the turtle has been dyed.
* @return 0-15 if the turtle has been dyed one of the 16 standard minecraft colours, -1 if the turtle is clean. *
* @return 0-15 if the turtle has been dyed one of the 16 standard Minecraft colours, -1 if the turtle is clean.
* @see #getDyeColour()
*/ */
public int getDyeColour(); public int getDyeColour();
/** /**
* TODO: Document me * Get the inventory of this turtle
*
* @return This turtle's inventory
*/ */
public IInventory getInventory(); public IInventory getInventory();
/** /**
* TODO: Document me * Determine whether this turtle will require fuel when performing actions.
*
* @return Whether this turtle needs fuel.
* @see #getFuelLevel()
* @see #setFuelLevel(int)
*/ */
public boolean isFuelNeeded(); public boolean isFuelNeeded();
/** /**
* TODO: Document me * Get the current fuel level of this turtle.
*
* @return The turtle's current fuel level.
* @see #isFuelNeeded()
* @see #setFuelLevel(int)
*/ */
public int getFuelLevel(); public int getFuelLevel();
/** /**
* TODO: Document me * Set the fuel level to a new value. It is generally preferred to use {@link #consumeFuel(int)}} or {@link #addFuel(int)}
* instead.
*
* @param fuel The new amount of fuel. This must be between 0 and the fuel limit.
* @see #getFuelLevel()
* @see #getFuelLimit()
* @see #addFuel(int)
* @see #consumeFuel(int)
*/ */
public void setFuelLevel( int fuel ); public void setFuelLevel( int fuel );
/** /**
* TODO: Document me * Get the maximum amount of fuel a turtle can hold.
*
* @return The turtle's fuel limit.
*/ */
public int getFuelLimit(); public int getFuelLimit();
/** /**
* Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle. * Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle.
* @return Whether the turtle was able to consume the ammount of fuel specified. Will return false if you supply a number *
* greater than the current fuel level of the turtle. * @param fuel The amount of fuel to consume.
* @return Whether the turtle was able to consume the amount of fuel specified. Will return false if you supply a number
* greater than the current fuel level of the turtle. No fuel will be consumed if {@code false} is returned.
* @throws UnsupportedOperationException When attempting to consume fuel on the client side.
*/ */
public boolean consumeFuel( int fuel ); public boolean consumeFuel( int fuel );
/** /**
* TODO: Document me * Increase the turtle's fuel level by the given amount.
*
* @param fuel The amount to refuel with.
* @throws UnsupportedOperationException When attempting to refuel on the client side.
*/ */
public void addFuel( int fuel ); public void addFuel( int fuel );
@ -128,42 +193,67 @@ public interface ITurtleAccess
* with the turtles standard movement and tool commands. An issued command will return an unique integer, which will * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will
* be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the
* lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality.
*
* @param command an object which will execute the custom command when its point in the queue is reached * @param command an object which will execute the custom command when its point in the queue is reached
* @return the objects the command returned when executed. you should probably return these to the player * @return the objects the command returned when executed. you should probably return these to the player
* unchanged if called from a peripheral method. * unchanged if called from a peripheral method.
* @throws UnsupportedOperationException When attempting to execute a command on the client side.
* @see ITurtleCommand * @see ITurtleCommand
*/ */
public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException; public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
/** /**
* TODO: Document me * Start playing a specific animation. This will prevent other turtle commands from executing until
* it is finished.
*
* @param animation The animation to play.
* @throws UnsupportedOperationException When attempting to execute play an animation on the client side.
* @see TurtleAnimation
*/ */
public void playAnimation( TurtleAnimation animation ); public void playAnimation( TurtleAnimation animation );
/** /**
* Returns the turtle on the specified side of the turtle, if there is one. * Returns the turtle on the specified side of the turtle, if there is one.
* @return the turtle on the specified side of the turtle, if there is one. *
* @return The upgrade on the specified side of the turtle, if there is one.
* @see #setUpgrade(TurtleSide, ITurtleUpgrade)
*/ */
public ITurtleUpgrade getUpgrade( TurtleSide side ); public ITurtleUpgrade getUpgrade( TurtleSide side );
/** /**
* TODO: Document me * Set the upgrade for a given side, resetting peripherals and clearing upgrade specific data.
*
* @param side The side to set the upgrade on.
* @param upgrade The upgrade to set, may be {@code null} to clear.
* @see #getUpgrade(TurtleSide)
*/ */
public void setUpgrade( TurtleSide side, ITurtleUpgrade upgrade ); public void setUpgrade( TurtleSide side, ITurtleUpgrade upgrade );
/** /**
* Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one. * Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one.
* @return the peripheral created by the upgrade on the specified side of the turtle, if there is one. *
* @return The peripheral created by the upgrade on the specified side of the turtle, {@code null} if none exists.
*/ */
public IPeripheral getPeripheral( TurtleSide side ); public IPeripheral getPeripheral( TurtleSide side );
/** /**
* TODO: Document me * Get an upgrade-specific NBT compound, which can be used to store arbitrary data.
*
* This will be persisted across turtle restarts and chunk loads, as well as being synced to the client. You must
* call {@link #updateUpgradeNBTData(TurtleSide)} after modifying it.
*
* @param side The side to get the upgrade data for.
* @return The upgrade-specific data.
* @see #updateUpgradeNBTData(TurtleSide)
*/ */
public NBTTagCompound getUpgradeNBTData( TurtleSide side ); public NBTTagCompound getUpgradeNBTData( TurtleSide side );
/** /**
* TODO: Document me * Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the
* client and persisted.
*
* @param side The side to mark dirty.
* @see #updateUpgradeNBTData(TurtleSide)
*/ */
public void updateUpgradeNBTData( TurtleSide side ); public void updateUpgradeNBTData( TurtleSide side );
} }

View File

@ -6,20 +6,27 @@
package dan200.computercraft.api.turtle; package dan200.computercraft.api.turtle;
import dan200.computercraft.api.lua.ILuaContext;
/** /**
* An interface for objects executing custom turtle commands, used with ITurtleAccess.issueCommand * An interface for objects executing custom turtle commands, used with {@link ITurtleAccess#executeCommand(ILuaContext, ITurtleCommand)}.
* @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand) *
* @see ITurtleAccess#executeCommand(ILuaContext, ITurtleCommand)
*/ */
public interface ITurtleCommand public interface ITurtleCommand
{ {
/** /**
* Will be called by the turtle on the main thread when it is time to execute the custom command. * Will be called by the turtle on the main thread when it is time to execute the custom command.
*
* The handler should either perform the work of the command, and return success, or return * The handler should either perform the work of the command, and return success, or return
* failure with an error message to indicate the command cannot be executed at this time. * failure with an error message to indicate the command cannot be executed at this time.
* @param turtle access to the turtle for whom the command was issued *
* @return TurtleCommandResult.success() or TurtleCommandResult.failure( errorMessage ) * @param turtle Access to the turtle for whom the command was issued.
* @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand) * @return A result, indicating whether this action succeeded or not.
* @see dan200.computercraft.api.turtle.TurtleCommandResult * @see ITurtleAccess#executeCommand(ILuaContext, ITurtleCommand)
* @see TurtleCommandResult#success()
* @see TurtleCommandResult#failure(String)
* @see TurtleCommandResult
*/ */
public TurtleCommandResult execute( ITurtleAccess turtle ); public TurtleCommandResult execute( ITurtleAccess turtle );
} }

View File

@ -6,8 +6,10 @@
package dan200.computercraft.api.turtle; package dan200.computercraft.api.turtle;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -21,7 +23,8 @@ import javax.vecmath.Matrix4f;
/** /**
* The primary interface for defining an update for Turtles. A turtle update * The primary interface for defining an update for Turtles. A turtle update
* can either be a new tool, or a new peripheral. * can either be a new tool, or a new peripheral.
* @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) *
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
*/ */
public interface ITurtleUpgrade public interface ITurtleUpgrade
{ {
@ -29,7 +32,8 @@ public interface ITurtleUpgrade
* Gets a unique identifier representing this type of turtle upgrade. eg: "computercraft:wireless_modem" or "my_mod:my_upgrade". * Gets a unique identifier representing this type of turtle upgrade. eg: "computercraft:wireless_modem" or "my_mod:my_upgrade".
* You should use a unique resource domain to ensure this upgrade is uniquely identified. * You should use a unique resource domain to ensure this upgrade is uniquely identified.
* The turtle will fail registration if an already used ID is specified. * The turtle will fail registration if an already used ID is specified.
* @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) *
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
*/ */
public ResourceLocation getUpgradeID(); public ResourceLocation getUpgradeID();
@ -38,18 +42,21 @@ public interface ITurtleUpgrade
* for backwards compatibility with pre-1.76 worlds. If your upgrade was * for backwards compatibility with pre-1.76 worlds. If your upgrade was
* not released for older ComputerCraft versions, you can return -1 here. * not released for older ComputerCraft versions, you can return -1 here.
* The turtle will fail registration if an already used positive ID is specified. * The turtle will fail registration if an already used positive ID is specified.
* @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) *
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
*/ */
public int getLegacyUpgradeID(); public int getLegacyUpgradeID();
/** /**
* Return a String to describe this type of turtle in turtle item names. * Return an unlocalised string to describe this type of turtle in turtle item names.
*
* Examples of built-in adjectives are "Wireless", "Mining" and "Crafty". * Examples of built-in adjectives are "Wireless", "Mining" and "Crafty".
*/ */
public String getUnlocalisedAdjective(); public String getUnlocalisedAdjective();
/** /**
* Return whether this turtle adds a tool or a peripheral to the turtle. * Return whether this turtle adds a tool or a peripheral to the turtle.
*
* @see TurtleUpgradeType for the differences between the two. * @see TurtleUpgradeType for the differences between the two.
*/ */
public TurtleUpgradeType getType(); public TurtleUpgradeType getType();
@ -57,19 +64,20 @@ public interface ITurtleUpgrade
/** /**
* Return an item stack representing the type of item that a turtle must be crafted * Return an item stack representing the type of item that a turtle must be crafted
* with to create a turtle which holds this upgrade. This item stack is also used * with to create a turtle which holds this upgrade. This item stack is also used
* to determine the upgrade given by turtle.equip() * to determine the upgrade given by {@code turtle.equip()}
*/ */
public ItemStack getCraftingItem(); public ItemStack getCraftingItem();
/** /**
* Will only be called for peripheral upgrades. Creates a peripheral for a turtle * Will only be called for peripheral upgrades. Creates a peripheral for a turtle being placed using this upgrade.
* being placed using this upgrade. The peripheral created will be stored *
* for the lifetime of the upgrade, will have update() called once-per-tick, and will be * The peripheral created will be stored for the lifetime of the upgrade and will be passed as an argument to
* attached, detached and have methods called in the same manner as a Computer peripheral. * {@link #update(ITurtleAccess, TurtleSide)}. It will be attached, detached and have methods called in the same
* manner as a Computer peripheral.
* *
* @param turtle Access to the turtle that the peripheral is being created for. * @param turtle Access to the turtle that the peripheral is being created for.
* @param side Which side of the turtle (left or right) that the upgrade resides on. * @param side Which side of the turtle (left or right) that the upgrade resides on.
* @return The newly created peripheral. You may return null if this upgrade is a Tool * @return The newly created peripheral. You may return {@code null} if this upgrade is a Tool
* and this method is not expected to be called. * and this method is not expected to be called.
*/ */
public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ); public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side );
@ -77,30 +85,38 @@ public interface ITurtleUpgrade
/** /**
* Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called * Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
* by the turtle, and the tool is required to do some work. * by the turtle, and the tool is required to do some work.
*
* @param turtle Access to the turtle that the tool resides on. * @param turtle Access to the turtle that the tool resides on.
* @param side Which side of the turtle (left or right) the tool resides on. * @param side Which side of the turtle (left or right) the tool resides on.
* @param verb Which action (dig or attack) the turtle is being called on to perform. * @param verb Which action (dig or attack) the turtle is being called on to perform.
* @param direction Which world direction the action should be performed in, relative to the turtles * @param direction Which world direction the action should be performed in, relative to the turtles
* position. This will either be up, down, or the direction the turtle is facing, depending on * position. This will either be up, down, or the direction the turtle is facing, depending on
* whether dig, digUp or digDown was called. * whether dig, digUp or digDown was called.
* @return Whether the turtle was able to perform the action, and hence whether the turtle.dig() * @return Whether the turtle was able to perform the action, and hence whether the {@code turtle.dig()}
* or turtle.attack() lua method should return true. If true is returned, the tool will perform * or {@code turtle.attack()} lua method should return true. If true is returned, the tool will perform
* a swinging animation. You may return null if this turtle is a Peripheral * a swinging animation. You may return {@code null} if this turtle is a Peripheral and this method is not expected
* and this method is not expected to be called. * to be called.
*/ */
public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, EnumFacing direction ); public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, EnumFacing direction );
/** /**
* Called to obtain the model to be used when rendering a turtle peripheral. * Called to obtain the model to be used when rendering a turtle peripheral.
*
* This can be obtained from {@link net.minecraft.client.renderer.ItemModelMesher#getItemModel(ItemStack)},
* {@link net.minecraft.client.renderer.block.model.ModelManager#getModel(ModelResourceLocation)} or any other
* source.
*
* @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models! * @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models!
* @param side Which side of the turtle (left or right) the upgrade resides on. * @param side Which side of the turtle (left or right) the upgrade resides on.
* @return The model that you wish to be used to render your upgrade, and a transformation to apply to it. Returning a transformation of null has the same effect as the identify matrix. * @return The model that you wish to be used to render your upgrade, and a transformation to apply to it. Returning
* a transformation of {@code null} has the same effect as the identify matrix.
*/ */
@SideOnly( Side.CLIENT ) @SideOnly(Side.CLIENT)
public Pair<IBakedModel, Matrix4f> getModel( ITurtleAccess turtle, TurtleSide side ); public Pair<IBakedModel, Matrix4f> getModel( ITurtleAccess turtle, TurtleSide side );
/** /**
* Called once per tick for each turtle which has the upgrade equipped. * Called once per tick for each turtle which has the upgrade equipped.
*
* @param turtle Access to the turtle that the upgrade resides on. * @param turtle Access to the turtle that the upgrade resides on.
* @param side Which side of the turtle (left or right) the upgrade resides on. * @param side Which side of the turtle (left or right) the upgrade resides on.
*/ */

View File

@ -6,17 +6,82 @@
package dan200.computercraft.api.turtle; package dan200.computercraft.api.turtle;
/**
* An animation a turtle will play between executing commands.
*
* Each animation takes 8 ticks to complete unless otherwise specified.
*
* @see ITurtleAccess#playAnimation(TurtleAnimation)
*/
public enum TurtleAnimation public enum TurtleAnimation
{ {
/**
* An animation which does nothing. This takes no time to complete.
*
* @see #Wait
* @see #ShortWait
*/
None, None,
/**
* Make the turtle move forward. Note that the animation starts from the block <em>behind</em> it, and
* moves into this one.
*/
MoveForward, MoveForward,
/**
* Make the turtle move backwards. Note that the animation starts from the block <em>in front</em> it, and
* moves into this one.
*/
MoveBack, MoveBack,
/**
* Make the turtle move backwards. Note that the animation starts from the block <em>above</em> it, and
* moves into this one.
*/
MoveUp, MoveUp,
/**
* Make the turtle move backwards. Note that the animation starts from the block <em>below</em> it, and
* moves into this one.
*/
MoveDown, MoveDown,
/**
* Turn the turtle to the left. Note that the animation starts with the turtle facing <em>right</em>, and
* the turtle turns to face in the current direction.
*/
TurnLeft, TurnLeft,
/**
* Turn the turtle to the left. Note that the animation starts with the turtle facing <em>right</em>, and
* the turtle turns to face in the current direction.
*/
TurnRight, TurnRight,
/**
* Swing the tool on the left.
*/
SwingLeftTool, SwingLeftTool,
/**
* Swing the tool on the right.
*/
SwingRightTool, SwingRightTool,
/**
* Wait until the animation has finished, performing no movement.
*
* @see #ShortWait
* @see #None
*/
Wait, Wait,
/**
* Wait until the animation has finished, performing no movement. This takes 4 ticks to complete.
*
* @see #Wait
* @see #None
*/
ShortWait, ShortWait,
} }

View File

@ -6,16 +6,35 @@
package dan200.computercraft.api.turtle; package dan200.computercraft.api.turtle;
import net.minecraft.util.EnumFacing;
/**
* Used to indicate the result of executing a turtle command.
*
* @see ITurtleCommand#execute(ITurtleAccess)
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)
*/
public final class TurtleCommandResult public final class TurtleCommandResult
{ {
private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null, null ); private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null, null );
private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null, null ); private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null, null );
/**
* Create a successful command result with no result.
*
* @return A successful command result with no values.
*/
public static TurtleCommandResult success() public static TurtleCommandResult success()
{ {
return success( null ); return success( null );
} }
/**
* Create a successful command result with the given result values.
*
* @param results The results of executing this command.
* @return A successful command result with the given values.
*/
public static TurtleCommandResult success( Object[] results ) public static TurtleCommandResult success( Object[] results )
{ {
if( results == null || results.length == 0 ) if( results == null || results.length == 0 )
@ -28,11 +47,22 @@ public final class TurtleCommandResult
} }
} }
/**
* Create a failed command result with no error message.
*
* @return A failed command result with no message.
*/
public static TurtleCommandResult failure() public static TurtleCommandResult failure()
{ {
return failure( null ); return failure( null );
} }
/**
* Create a failed command result with an error message.
*
* @param errorMessage The error message to provide.
* @return A failed command result with a message.
*/
public static TurtleCommandResult failure( String errorMessage ) public static TurtleCommandResult failure( String errorMessage )
{ {
if( errorMessage == null ) if( errorMessage == null )
@ -56,16 +86,31 @@ public final class TurtleCommandResult
m_results = results; m_results = results;
} }
/**
* Determine whether the command executed successfully.
*
* @return If the command was successful.
*/
public boolean isSuccess() public boolean isSuccess()
{ {
return m_success; return m_success;
} }
/**
* Get the error message of this command result.
*
* @return The command's error message, or {@code null} if it was a success.
*/
public String getErrorMessage() public String getErrorMessage()
{ {
return m_errorMessage; return m_errorMessage;
} }
/**
* Get the resulting values of this command result.
*
* @return The command's result, or {@code null} if it was a failure.
*/
public Object[] getResults() public Object[] getResults()
{ {
return m_results; return m_results;

View File

@ -12,12 +12,12 @@ package dan200.computercraft.api.turtle;
public enum TurtleSide public enum TurtleSide
{ {
/** /**
* The turtles 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, Left,
/** /**
* The turtles 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, Right,
} }

View File

@ -7,21 +7,21 @@
package dan200.computercraft.api.turtle; package dan200.computercraft.api.turtle;
/** /**
* An enum representing the two different types of turtle that an ITurtleUpgrade * An enum representing the different types of turtle that an {@link ITurtleUpgrade} implementation can add to a turtle.
* implementation can add to a turtle. *
* @see ITurtleUpgrade * @see ITurtleUpgrade#getType()
*/ */
public enum TurtleUpgradeType public enum TurtleUpgradeType
{ {
/** /**
* A tool is rendered as an item on the side of the turtle, and responds to the turtle.dig() * A tool is rendered as an item on the side of the turtle, and responds to the {@code turtle.dig()}
* and turtle.attack() methods (Such as pickaxe or sword on Mining and Melee turtles). * and {@code turtle.attack()} methods (Such as pickaxe or sword on Mining and Melee turtles).
*/ */
Tool, Tool,
/** /**
* A peripheral adds a special peripheral which is attached to the side of the turtle, * A peripheral adds a special peripheral which is attached to the side of the turtle,
* and can be interacted with the peripheral API (Such as the modem on Wireless Turtles). * and can be interacted with the {@code peripheral} API (Such as the modem on Wireless Turtles).
*/ */
Peripheral, Peripheral,
@ -30,8 +30,7 @@ public enum TurtleUpgradeType
* your upgrade to also provide methods. For example, a pickaxe could provide methods * your upgrade to also provide methods. For example, a pickaxe could provide methods
* determining whether it can break the given block or not. * determining whether it can break the given block or not.
*/ */
Both, Both,;
;
public boolean isTool() public boolean isTool()
{ {

View File

@ -6,21 +6,24 @@
package dan200.computercraft.api.turtle; package dan200.computercraft.api.turtle;
import net.minecraft.util.EnumFacing;
/** /**
* An enum representing the two different actions that an ITurtleUpgrade of type * An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by
* Tool may be called on to perform by a turtle. * a turtle.
* @see ITurtleUpgrade *
* @see ITurtleUpgrade#useTool * @see ITurtleUpgrade#getType()
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)
*/ */
public enum TurtleVerb public enum TurtleVerb
{ {
/** /**
* The turtle called turtle.dig(), turtle.digUp() or turtle.digDown() * The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}
*/ */
Dig, Dig,
/** /**
* The turtle called turtle.attack(), turtle.attackUp() or turtle.attackDown() * The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}
*/ */
Attack, Attack,
} }