Class ComputerCraftAPI
Members in this class must be called after ComputerCraft has been initialised, but may be called before it is fully loaded.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MountcreateResourceMount(net.minecraft.server.MinecraftServer server, String domain, String subPath) Creates a file system mount to a resource folder, and returns it.static WritableMountcreateSaveDirMount(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.static intcreateUniqueNumberedSaveDir(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.static WiredNodecreateWiredNodeForElement(WiredElement element) Construct a new wired node for a given wired element.static intgetBundledRedstoneOutput(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.static Stringstatic PacketNetworkgetWirelessNetwork(net.minecraft.server.MinecraftServer server) Attempt to get the game-wide wireless network.static voidregisterAPIFactory(ILuaAPIFactory factory) Register a customILuaAPI, which may be added onto all computers without requiring a peripheral.static voidRegisters a bundled redstone provider to provide bundled redstone output for blocks.static voidregisterGenericSource(GenericSource source) Registers a method source for generic peripherals.static voidregisterMediaProvider(MediaProvider provider) Registers a media provider to provideIMediaimplementations for Items.static voidregisterRefuelHandler(TurtleRefuelHandler handler) Register a refuel handler for turtles.
-
Field Details
-
MOD_ID
- See Also:
-
-
Constructor Details
-
ComputerCraftAPI
public ComputerCraftAPI()
-
-
Method Details
-
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)orIComputerAccess.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". UsecreateUniqueNumberedSaveDir(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)orIComputerAccess.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
nullif it could be created for some reason. - See Also:
-
registerGenericSource
Registers a method source for generic peripherals.- Parameters:
source- The method source to register.- See Also:
-
registerBundledRedstoneProvider
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
Registers a media provider to provideIMediaimplementations for Items.- Parameters:
provider- The media provider to register.- See Also:
-
getWirelessNetwork
Attempt to get the game-wide wireless network.- Parameters:
server- The current Minecraft server.- Returns:
- The global wireless network, or
nullif it could not be fetched.
-
registerAPIFactory
Register a customILuaAPI, 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
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
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:
-