public interface IPeripheral
IPeripheralProvider
for how to associate blocks with peripherals.Modifier and Type | Method and Description |
---|---|
default void |
attach(IComputerAccess computer)
Is called when canAttachToSide has returned true, and a computer is attaching to the peripheral.
|
java.lang.Object[] |
callMethod(IComputerAccess computer,
ILuaContext context,
int method,
java.lang.Object[] arguments)
This is called when a lua program on an attached computer calls
peripheral.call() with
one of the methods exposed by getMethodNames() . |
default void |
detach(IComputerAccess computer)
Is called when a computer is detaching from the peripheral.
|
boolean |
equals(IPeripheral other)
Determine whether this peripheral is equivalent to another one.
|
java.lang.String[] |
getMethodNames()
Should return an array of strings that identify the methods that this
peripheral exposes to Lua.
|
java.lang.String |
getType()
Should return a string that uniquely identifies this type of peripheral.
|
java.lang.String getType()
peripheral.getType()
java.lang.String[] getMethodNames()
callMethod(dan200.computercraft.api.peripheral.IComputerAccess, dan200.computercraft.api.lua.ILuaContext, int, java.lang.Object[])
java.lang.Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, java.lang.Object[] arguments) throws LuaException, java.lang.InterruptedException
peripheral.call()
with
one of the methods exposed by getMethodNames()
.
Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
when interacting with Minecraft objects.computer
- The interface to the computer that is making the call. Remember that multiple
computers can be attached to a peripheral at once.context
- The context of the currently running lua thread. This can be used to wait for events
or otherwise yield.method
- An integer identifying which of the methods from getMethodNames() the computercraft
wishes to call. The integer indicates the index into the getMethodNames() table
that corresponds to the string passed into peripheral.call()arguments
- An array of objects, representing the arguments passed into peripheral.call()
.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.java.lang.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.getMethodNames()
default void attach(IComputerAccess computer)
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
when interacting with Minecraft objects.computer
- The interface to the computer that is being attached. Remember that multiple
computers can be attached to a peripheral at once.detach(dan200.computercraft.api.peripheral.IComputerAccess)
default void detach(IComputerAccess computer)
computer
- The interface to the computer that is being detached. Remember that multiple
computers can be attached to a peripheral at once.detach(dan200.computercraft.api.peripheral.IComputerAccess)
boolean equals(IPeripheral other)
other
- The peripheral to compare against. This may be null
.