Interface IPeripheral
- All Known Subinterfaces:
IDynamicPeripheral
In order to expose a peripheral for your block or block entity, you should either attach a capability (Forge) or use the block lookup API (Fabric). This interface cannot be implemented directly on the block entity.
Peripherals should provide a series of methods to the user, either using LuaFunction
or by implementing
IDynamicPeripheral
.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
attach
(IComputerAccess computer) Is called when when a computer is attaching to the peripheral.default void
detach
(IComputerAccess computer) Called when a computer is detaching from the peripheral.boolean
equals
(IPeripheral other) Determine whether this peripheral is equivalent to another one.Return additional types/traits associated with this object.default Object
Get the object that this peripheral provides methods for.getType()
Should return a string that uniquely identifies this type of peripheral.
-
Method Details
-
getType
String getType()Should return a string that uniquely identifies this type of peripheral. This can be queried from lua by callingperipheral.getType()
- Returns:
- A string identifying the type of peripheral.
-
getAdditionalTypes
Return additional types/traits associated with this object.- Returns:
- A collection of additional object traits.
- See Also:
-
attach
Is called when when a computer is attaching to the peripheral.This will occur when a peripheral is placed next to an active computer, when a computer is turned on next to a peripheral, when a turtle travels into a square next to a peripheral, or when a wired modem adjacent to this peripheral is does any of the above.
Between calls to attach and
detach(dan200.computercraft.api.peripheral.IComputerAccess)
, the attached computer can make method calls on the peripheral usingperipheral.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 will be called from both the server thread and ComputerCraft Lua thread, and so must be thread-safe and reentrant.
- Parameters:
computer
- The interface to the computer that is being attached. Remember that multiple computers can be attached to a peripheral at once.- See Also:
-
detach
Called when a computer is detaching from the peripheral.This will occur when a computer shuts down, when the peripheral is removed while attached to computers, when a turtle moves away from a block attached to a peripheral, or when a wired modem adjacent to this peripheral is detached.
This method can be used to keep track of which computers are attached to the peripheral, or to take action when detachment occurs.
Be aware that this will be called from both the server and ComputerCraft Lua thread, and must be thread-safe and reentrant.
- Parameters:
computer
- The interface to the computer that is being detached. Remember that multiple computers can be attached to a peripheral at once.- See Also:
-
getTarget
Get the object that this peripheral provides methods for. This will generally be the tile entity or block, but may be an inventory, entity, etc...- Returns:
- The object this peripheral targets
-
equals
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.
- Parameters:
other
- The peripheral to compare against. This may benull
.- Returns:
- Whether these peripherals are equivalent.
-