Interface IComputerAccess
- All Known Subinterfaces:
IComputerSystem
-
Method Summary
Modifier and TypeMethodDescriptionGet a string, unique to the computer, by which the computer refers to this peripheral.@Nullable IPeripheral
getAvailablePeripheral
(String name) Get a reachable peripheral with the given attachment name.Get a set of peripherals that this computer access can "see", along with their attachment name.int
getID()
Returns the numerical ID of this computer.Get aWorkMonitor
for tasks your peripheral might execute on the main (server) thread.default @Nullable String
Mount a mount onto the computer's file system in a read only mode.@Nullable String
Mount a mount onto the computer's file system in a read only mode.default @Nullable String
mountWritable
(String desiredLocation, WritableMount mount) Mount a mount onto the computer's file system in a writable mode.@Nullable String
mountWritable
(String desiredLocation, WritableMount mount, String driveName) Mount a mount onto the computer's file system in a writable mode.void
queueEvent
(String event, @Nullable Object... arguments) Causes an event to be raised on this computer, which the computer can respond to by callingos.pullEvent()
.void
Unmounts a directory previously mounted onto the computers file system bymount(String, Mount)
ormountWritable(String, WritableMount)
.
-
Method Details
-
mount
Mount a mount onto the computer's file system in a read only mode.- Parameters:
desiredLocation
- The location on the computer's file system where you would like the mount to be mounted.mount
- The mount object to mount on the computer.- Returns:
- 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:
NotAttachedException
- If the peripheral has been detached.- See Also:
-
mount
Mount a mount onto the computer's file system in a read only mode.- Parameters:
desiredLocation
- The location on the computer's file system where you would like the mount to be mounted.mount
- The mount object to mount on the computer.driveName
- A custom name to give for this mount location, as returned byfs.getDrive()
.- Returns:
- 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:
NotAttachedException
- If the peripheral has been detached.- See Also:
-
mountWritable
Mount a mount onto the computer's file system in a writable mode.- Parameters:
desiredLocation
- The location on the computer's file system where you would like the mount to be mounted.mount
- The mount object to mount on the computer.- Returns:
- 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:
NotAttachedException
- If the peripheral has been detached.- See Also:
-
mountWritable
Mount a mount onto the computer's file system in a writable mode.- Parameters:
desiredLocation
- The location on the computer's file system where you would like the mount to be mounted.mount
- The mount object to mount on the computer.driveName
- A custom name to give for this mount location, as returned byfs.getDrive()
.- Returns:
- 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:
NotAttachedException
- If the peripheral has been detached.- See Also:
-
unmount
Unmounts a directory previously mounted onto the computers file system bymount(String, Mount)
ormountWritable(String, WritableMount)
.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.
- 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 bymount(String, Mount)
ormountWritable(String, WritableMount)
, as indicated by their return value.- Throws:
NotAttachedException
- If the peripheral has been detached.IllegalStateException
- If the mount does not exist, or was mounted by another peripheral.- See Also:
-
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 guaranteed unique. This number will be positive.- Returns:
- The identifier.
-
queueEvent
Causes an event to be raised on this computer, which the computer can respond to by callingos.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 fromos.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.- Throws:
NotAttachedException
- If the peripheral has been detached.- See Also:
-
getAttachmentName
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.
- Throws:
NotAttachedException
- If the peripheral has been detached.
-
getAvailablePeripherals
Map<String,IPeripheral> getAvailablePeripherals()Get a set of peripherals that this computer access can "see", along with their attachment name.This may include other peripherals on the wired network or peripherals on other sides of the computer.
- Returns:
- All reachable peripherals
- Throws:
NotAttachedException
- If the peripheral has been detached.- See Also:
-
getAvailablePeripheral
Get a reachable peripheral with the given attachment name. This is a equivalent togetAvailablePeripherals()
.get(name)
, though may be more efficient.- Parameters:
name
- The peripheral's attached name- Returns:
- The reachable peripheral, or
null
if none can be found. - See Also:
-
getMainThreadMonitor
WorkMonitor getMainThreadMonitor()Get aWorkMonitor
for tasks your peripheral might execute on the main (server) thread.This should be used to ensure your peripheral integrates with ComputerCraft's monitoring and limiting of how much server time each computer consumes. You should not need to use this if you use
ILuaContext.issueMainThreadTask(LuaTask)
- this is intended for mods with their own system for running work on the main thread.Please note that the returned implementation is not thread-safe, and should only be used from the main thread.
- Returns:
- The work monitor for the main thread, or
null
if this computer does not have one. - Throws:
NotAttachedException
- If the peripheral has been detached.
-