Class ComputerCraftAPI

java.lang.Object
dan200.computercraft.api.ComputerCraftAPI

public final class ComputerCraftAPI extends Object
The static entry point to the ComputerCraft API.

Members in this class must be called after ComputerCraft has been initialised, but may be called before it is fully loaded.

  • Field Details

  • Constructor Details

    • ComputerCraftAPI

      public ComputerCraftAPI()
  • Method Details

    • getInstalledVersion

      public static String getInstalledVersion()
    • createUniqueNumberedSaveDir

      public static int createUniqueNumberedSaveDir(net.minecraft.server.MinecraftServer server, String parentSubPath)
      Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.

      Use in conjunction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.

      Parameters:
      server - The server for which the save dir should be created.
      parentSubPath - The folder path within the save directory where the new directory should be created. eg: "computercraft/disk"
      Returns:
      The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.

      eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing.

      See Also:
    • createSaveDirMount

      public static WritableMount createSaveDirMount(net.minecraft.server.MinecraftServer server, String subPath, long capacity)
      Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.

      Use in conjunction with Use IComputerAccess.mount(String, Mount) or IComputerAccess.mountWritable(String, WritableMount) to mount this on a computer's file system.

      If the same folder may be mounted on multiple computers at once (for instance, if you provide a network file share), the same mount instance should be used for all computers. You should NOT have multiple mount instances for the same folder.

      Parameters:
      server - The server which the save dir can be found.
      subPath - The folder path within the save directory that the mount should map to. eg: "disk/42". Use createUniqueNumberedSaveDir(MinecraftServer, String) to create a new numbered folder to use.
      capacity - The amount of data that can be stored in the directory before it fills up, in bytes.
      Returns:
      The newly created mount.
      See Also:
    • createResourceMount

      @Nullable public static Mount createResourceMount(net.minecraft.server.MinecraftServer server, String domain, String subPath)
      Creates a file system mount to a resource folder, and returns it.

      Use in conjunction with IComputerAccess.mount(java.lang.String, dan200.computercraft.api.filesystem.Mount) or IComputerAccess.mountWritable(java.lang.String, dan200.computercraft.api.filesystem.WritableMount) to mount a resource folder onto a computer's file system.

      The files in this mount will be a combination of files in all mod jar, and data packs that contain resources with the same domain and path. For instance, ComputerCraft's resources are stored in "/data/computercraft/lua/rom". We construct a mount for that with createResourceMount("computercraft", "lua/rom").

      Parameters:
      server - The current Minecraft server, from which to read resources from.
      domain - The domain under which to look for resources. eg: "mymod".
      subPath - The subPath under which to look for resources. eg: "lua/myfiles".
      Returns:
      The mount, or null if it could be created for some reason.
      See Also:
    • registerGenericSource

      public static void registerGenericSource(GenericSource source)
      Registers a method source for generic peripherals.
      Parameters:
      source - The method source to register.
      See Also:
    • registerBundledRedstoneProvider

      public static void registerBundledRedstoneProvider(BundledRedstoneProvider provider)
      Registers a bundled redstone provider to provide bundled redstone output for blocks.
      Parameters:
      provider - The bundled redstone provider to register.
      See Also:
    • getBundledRedstoneOutput

      public static int getBundledRedstoneOutput(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side)
      If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output.
      Parameters:
      world - The world this block is in.
      pos - The position this block is at.
      side - The side to extract the bundled redstone output from.
      Returns:
      If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
      See Also:
    • registerMediaProvider

      public static void registerMediaProvider(MediaProvider provider)
      Registers a media provider to provide IMedia implementations for Items.
      Parameters:
      provider - The media provider to register.
      See Also:
    • getWirelessNetwork

      public static PacketNetwork getWirelessNetwork(net.minecraft.server.MinecraftServer server)
      Attempt to get the game-wide wireless network.
      Parameters:
      server - The current Minecraft server.
      Returns:
      The global wireless network, or null if it could not be fetched.
    • registerAPIFactory

      public static void registerAPIFactory(ILuaAPIFactory factory)
      Register a custom ILuaAPI, which may be added onto all computers without requiring a peripheral.

      Before implementing this interface, consider alternative methods of providing methods. It is generally preferred to use peripherals to provide functionality to users.

      Parameters:
      factory - The factory for your API subclass.
      See Also:
    • createWiredNodeForElement

      public static WiredNode createWiredNodeForElement(WiredElement element)
      Construct a new wired node for a given wired element.
      Parameters:
      element - The element to construct it for
      Returns:
      The element's node
      See Also:
    • registerRefuelHandler

      public static void registerRefuelHandler(TurtleRefuelHandler handler)
      Register a refuel handler for turtles. This may be used to provide alternative fuel sources, such as consuming RF batteries.
      Parameters:
      handler - The turtle refuel handler.
      See Also: