dan200.computer.api
Interface IComputerAccess


public interface IComputerAccess

The interface passed to peripherals by computers or turtles, providing methods that they can call. This should not be implemented by your classes. Do not interact with computers except via this interface.


Method Summary
 int createNewSaveDir(java.lang.String subPath)
          Creates a new numbered directory in a subPath of the users game save, and return that number.
 java.lang.String getAttachmentName()
          Get a string, unique to the computer, by which the computer refers to this peripheral.
 int getID()
          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.
 java.lang.String mountFixedDir(java.lang.String desiredLocation, java.lang.String path, boolean readOnly, long spaceLimit)
          Mounts a directory into the computers file system, from a real directory in the Minecraft install folder.
For example: mountFixedDir( "stuff", "mods/mymod/lua/stuff", true ), will mount the "lua/stuff" folder from your mod's directory into the computers filesystem at the location "stuff", with readonly permission, giving the computer access to those files.
When a directory is mounted, it will appear in the computers file system, and the user will be able to use file operation to read from and write to the directory (unless readOnly, then only writes will be allowed).
mountFixedDir can also be used to mount files, for example: mountFixedDir( "rom/apis/myapi", "mods/mymod/lua/myapi.lua", true ) can be used to have the peripheral install an API onto the computer it attaches to.
 java.lang.String mountSaveDir(java.lang.String desiredLocation, java.lang.String subPath, int id, boolean readOnly, long spaceLimit)
          Mounts a directory into the computers file system, from a real directory a subPath of the users game save, with a numerical name.
 void queueEvent(java.lang.String event, java.lang.Object[] arguments)
          Causes an event to be raised on this computer, which the computer can respond to by calling os.pullEvent().
 void unmount(java.lang.String location)
          Unmounts a directory previously mounted onto the computers file system by mountSaveDir or mountFixedDir.
When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to access it.
 

Method Detail

createNewSaveDir

int createNewSaveDir(java.lang.String subPath)
Creates a new numbered directory in a subPath of the users game save, and return that number. To be used with mountSaveDir.
For example: n = createNewSaveDir( "computer/cdrom" ), will create a new numbered folder in the "computer/cdrom" subdirectory of the users save file, and return that number. mountSaveDir( "computer/rom", n ) could then be used to mount that folder onto the computers directory structure, and the value n could be saved out and used again in future to give the peripheral persistant storage.

Parameters:
subPath - A relative file path from the users world save, where the directory should be located.
Returns:
The numeric represenation of the name of the folder created. Will be positive.
See Also:
mountSaveDir(String, String, int, boolean, long)

mountSaveDir

java.lang.String mountSaveDir(java.lang.String desiredLocation,
                              java.lang.String subPath,
                              int id,
                              boolean readOnly,
                              long spaceLimit)
Mounts a directory into the computers file system, from a real directory a subPath of the users game save, with a numerical name. To be used with createNewSaveDir.
For example: n = createNewSaveDir( "computer/cdrom" ), will create a new numbered folder in the "computer/cdrom" subdirectory of the users save file, and return that number. mountSaveDir( "computer/rom", n ) could then be used to mount that folder onto the computers directory structure, and the value n can be saved out by the peripheral and used again, to give the peripheral persistant storage.
When a directory is mounted, it will appear in the computers file system, and the user will be able to use file operation to read from and write to the directory (unless readOnly, then only writes will be allowed).

Parameters:
desiredLocation - The desired location in the computers file system where you would like the directory to appear. If this location already exists, a number will be appended until a free name is found, and the actual location will be returned. eg: "cdrom" can become "cdrom2" if two peripherals attempt to mount "cdrom", or a "cdrom" folder already exists.
subPath - The real relative file path from the users world save, where the directory to mount can be located.
id - The numerical name of the folder to mount from the subPath: ex: mountSaveDir( "cdrom", "computer/cdrom", 7 ) will mount the directory "computer/cdrom/7". Use createNewSaveDir to obtain a unique directory id.
readOnly - Whether the computer will be disallowed from making changes to the mounted directory and modifing or creating files therin.
spaceLimit - The size limit of the mount, in bytes. Specify 0 to have unlimited capacity.
Returns:
The location in the computers file system where the directory was mounted. This may differ from "desiredLocation", so the return value should be kept track of so the folder can be unmounted later.
See Also:
createNewSaveDir(String), mountFixedDir(String, String, boolean, long), unmount(String)

mountFixedDir

java.lang.String mountFixedDir(java.lang.String desiredLocation,
                               java.lang.String path,
                               boolean readOnly,
                               long spaceLimit)
Mounts a directory into the computers file system, from a real directory in the Minecraft install folder.
For example: mountFixedDir( "stuff", "mods/mymod/lua/stuff", true ), will mount the "lua/stuff" folder from your mod's directory into the computers filesystem at the location "stuff", with readonly permission, giving the computer access to those files.
When a directory is mounted, it will appear in the computers file system, and the user will be able to use file operation to read from and write to the directory (unless readOnly, then only writes will be allowed).
mountFixedDir can also be used to mount files, for example: mountFixedDir( "rom/apis/myapi", "mods/mymod/lua/myapi.lua", true ) can be used to have the peripheral install an API onto the computer it attaches to.

Parameters:
desiredLocation - The desired location in the computers file system where you would like the directory to appear. If this location already exists, a number will be appended until a free name is found, and the actual location will be returned. eg: "cdrom" can become "cdrom2" if two peripherals attempt to mount "cdrom", or a "cdrom" folder already exists.
subPath - The real relative file path from the minecraft install root, where the directory to mount can be located.
readOnly - Whether the computer will be disallowed from making changes to the mounted directory and modifing or creating files therin.
spaceLimit - The size limit of the mount, in bytes. Specify 0 to have unlimited capacity.
Returns:
The location in the computers file system where the directory was mounted. This may differ from "desiredLocation", so the return value should be kept track of so the folder can be unmounted later.
See Also:
mountSaveDir(String, String, int, boolean, long), unmount(String)

unmount

void unmount(java.lang.String location)
Unmounts a directory previously mounted onto the computers file system by mountSaveDir or mountFixedDir.
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 mountFixedDir or mountSaveDir are automatically unmounted when the peripheral is attached if they have not been explicitly unmounted.

Parameters:
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 mountFixedDir() or mountSaveDir(), as indicated by their return value.
See Also:
mountSaveDir(String, String, int, boolean, long), mountFixedDir(String, String, boolean, long)

getID

int getID()
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.

Returns:
The identifier.

queueEvent

void queueEvent(java.lang.String event,
                java.lang.Object[] arguments)
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 computer when things happen in the world or to this peripheral.

Parameters:
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 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 "button_pressed".
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 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.
See Also:
IPeripheral.callMethod(dan200.computer.api.IComputerAccess, int, java.lang.Object[])

getAttachmentName

java.lang.String getAttachmentName()
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 peripherals attached remotely it will be different. It is good practice to supply this string when raising events to the computer, so that the computer knows from which peripheral the event came.

Returns:
A string unique to the computer, but not globally.