Interface IPeripheral

All Known Subinterfaces:
IDynamicPeripheral

public interface IPeripheral
The interface that defines a peripheral.

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 Type
    Method
    Description
    default void
    Is called when when a computer is attaching to the peripheral.
    default void
    Called when a computer is detaching from the peripheral.
    boolean
    Determine whether this peripheral is equivalent to another one.
    default Set<String>
    Return additional types/traits associated with this object.
    default Object
    Get the object that this peripheral provides methods for.
    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 calling peripheral.getType()
      Returns:
      A string identifying the type of peripheral.
    • getAdditionalTypes

      default Set<String> getAdditionalTypes()
      Return additional types/traits associated with this object.
      Returns:
      A collection of additional object traits.
      See Also:
    • attach

      default void attach(IComputerAccess computer)
      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 using 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 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

      default void detach(IComputerAccess computer)
      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

      @Nullable default Object 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

      boolean equals(@Nullable IPeripheral other)
      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 be null.
      Returns:
      Whether these peripherals are equivalent.