### Complete Integration Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/prefab-classes.md A comprehensive example demonstrating the integration of a custom tile entity, block driver, and registration within OpenComputers. This covers environment initialization, method invocation, and driver setup. ```Java import li.cil.oc.api.*; import li.cil.oc.api.driver.*; import li.cil.oc.api.prefab.*; import net.minecraftforge.common.util.ForgeDirection; // 1. Tile entity environment public class MyTile extends TileEntityEnvironment { @Override protected void initialize() { node = (ComponentConnector)Network.newNode(this, Visibility.Network) .withComponent("mydevice") .withConnector(100) .create(); } @Override public void update() { // Update logic } @Override public String[] getMethodNames() { return new String[]{"test", "getValue"}; } @Override public Object[] invoke(String method, Context context, Arguments args) throws Exception { if ("test".equals(method)) { return new Object[]{true}; } else if ("getValue".equals(method)) { return new Object[]{42}; } return null; } } // 2. Block driver public class MyBlockDriver extends DriverBlock { @Override public Class block() { return MyBlock.class; } @Override public ManagedEnvironment createEnvironment(World world, int x, int y, int z) { return new MyTile(); } } // 3. Register in init handler public void init(FMLInitializationEvent event) { Driver.add(new MyBlockDriver()); } ``` -------------------------------- ### Item Driver Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/README.md Example demonstrating how to implement an Item driver for custom components. ```APIDOC ### Item Driver ```java public class MyItemDriver implements Item { @Override public Class slot() { return Slot.Card; } @Override public ManagedEnvironment createEnvironment(ItemStack stack) { return new MyItemEnvironment(stack); } @Override public int tier(ItemStack stack) { return 1; // Tier 1 component } @Override public Class hostClass() { return null; // Works in any host } } ``` ``` -------------------------------- ### Install OpenOS Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/doc/en_US/general/openOS.md Run the 'install' command in the OpenOS terminal to begin the installation process. Follow the on-screen prompts to complete the installation. The floppy disk can be removed after the system reboots. ```bash install ``` -------------------------------- ### Simple Block Component Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/README.md Example demonstrating how to create a simple block component that integrates with the OpenComputers network. ```APIDOC ### Simple Block Component ```java public class MyTile extends TileEntity implements Environment { private ComponentConnector node; public MyTile() { node = (ComponentConnector) Network.newNode(this, Visibility.Network) .withComponent("mydevice") .withConnector(100) .create(); } @Override public void updateEntity() { if (!worldObj.isRemote && node.network() == null) { Network.joinOrCreateNetwork(this); } } @Override public Node node() { return node; } @Override public void onConnect(Node node) {} @Override public void onDisconnect(Node node) {} @Override public void onMessage(Message message) {} @Callback public Object[] doSomething(Context context, Arguments args) throws Exception { return new Object[]{true}; } } ``` ``` -------------------------------- ### Example OpenComputers Configuration Section Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/configuration.md An example HOCON configuration section for OpenComputers, showing settings for computer, power, and memory. ```hocon computer { maxCallBudget = 2500 maxSignalDelay = 20 callBudgetFactor = 1.0 } power { enabled = true default_cost_per_tick = 1.0 } memory { ramSizes = [128, 256, 512, 1024, 2048, 4096, 8192] tmpfsSize = 33554432 } ``` -------------------------------- ### Lua Redstone Component Example Source: https://github.com/mightypirates/opencomputers/wiki/Component-Redstone Demonstrates how to get redstone input and set bundled redstone output using the OpenComputers Lua API. Requires the 'component', 'sides', and 'colors' modules. ```lua local component = require("component") local sides = require("sides") local colors = require("colors") local rs = component.redstone -- get primary redstone component print(rs.getInput(sides.back)) rs.setBundledOutput(sides.bottom, colors.green, rs.getBundledInput(sides.top, colors.red)) ``` -------------------------------- ### ResourceContentProvider Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/manual-api.md An example implementation of ContentProvider that loads manual page content from resource files. This is useful for organizing documentation within your mod's assets. ```Java public class ResourceContentProvider implements ContentProvider { private String modId; private String basePath; public ResourceContentProvider(String modId, String basePath) { this.modId = modId; this.basePath = basePath; } @Override public String getContent(String path) { try { InputStream is = getClass().getResourceAsStream( basePath + "/" + path + ".txt" ); if (is != null) { return readStream(is); } } catch (IOException e) { // Log error } return null; } @Override public boolean isValid(String path) { return getContent(path) != null; } } ``` -------------------------------- ### Complete Manual Integration Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/manual-api.md Demonstrates registering a content provider, an image provider, and a custom image renderer. ```java public class MyModManual { public static void register() { // Register content provider Manual.addProvider(new ResourceContentProvider("mymod", "assets/mymod/doc")); // Register image provider Manual.addProvider(new ImageProvider() { @Override public BufferedImage getImage(String path) { if (path.startsWith("mymod/images/")) { String imageName = path.substring("mymod/images/".length()); return loadImage("assets/mymod/textures/manual/" + imageName + ".png"); } return null; } @Override public boolean isValid(String path) { return path.startsWith("mymod/images/"); } }); // Register custom renderer Manual.addRenderer(new ImageRenderer() { @Override public void render(BufferedImage image, String path) { // Custom rendering logic } @Override public int getWidth(String path) { return 256; } @Override public int getHeight(String path) { return 256; } }); } } ``` -------------------------------- ### Setup Workspace for IntelliJ IDEA Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/README.md Run this command in the cloned repository to set up the workspace, including assets. ```bash gradlew setupDecompWorkspace ``` -------------------------------- ### Crafting Component Usage Example Source: https://github.com/mightypirates/opencomputers/wiki/Component-Crafting This Lua snippet demonstrates how to get the crafting component and use its `craft` method to craft up to 10 items. Ensure the crafting upgrade is installed on the robot. ```lua local component = require("component") local c = component.crafting -- get primary crafting component c.craft(10) -- craft up to 10 items ``` -------------------------------- ### Image Examples with Spacing Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/doc/en_US/general/example.md Demonstrates image rendering with different spacing and line breaks. ```plaintext this is a test for an![](oredict:oc:cpu1) an image with a break after it ``` ```plaintext this is a test for an ![](oredict:oc:cpu1) an image between two lines ``` ```plaintext this is a test for an ![](oredict:oc:cpu1) an image between two blank lines ``` -------------------------------- ### Computer Component API Usage Example Source: https://github.com/mightypirates/opencomputers/wiki/Component-Computer This Lua snippet demonstrates how to get the computer component and use its `isRunning` and `stop` methods. It's typically used within the computer itself. ```lua local component = require("component") local c = component.computer -- get primary computer, e.g. self print(c.isRunning()) -- definitely true if it's this computer c.stop() -- basically like computer.shutdown() if it's this computer ``` -------------------------------- ### Basic Modem Usage Example Source: https://github.com/mightypirates/opencomputers/wiki/Component-Modem Demonstrates opening a port, sending a broadcast message, and receiving an incoming message using the modem component and event system. ```lua local component = require("component") local event = require("event") local m = component.modem -- get primary modem component m.open(123) print(m.isOpen(123)) -- true -- Send some message. m.broadcast(321, "this is a test") -- Wait for a message from another network card. local _, _, from, port, _, message = event.pull("modem_message") print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message)) ``` -------------------------------- ### Setup Workspace for Eclipse Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/README.md If you prefer Eclipse, run this command to set up the workspace and generate Eclipse project files. ```bash gradlew eclipse ``` -------------------------------- ### computer.uptime() Source: https://github.com/mightypirates/opencomputers/wiki/API-Computer Gets the time in real-world seconds the computer has been running. ```APIDOC ## computer.uptime() ### Description Returns the time in real world seconds this computer has been running, measured based on the world time that passed since it was started. ### Method GET ### Endpoint /computer/uptime ### Response #### Success Response (200) - **uptime** (number) - The uptime in seconds. ``` -------------------------------- ### TextureTabIconRenderer Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/prefab-classes.md Example of how to create and register a TextureTabIconRenderer for a manual entry. Ensure the textureName correctly points to your icon resource. ```Java TabIconRenderer renderer = new TextureTabIconRenderer("mymod:textures/manual/icon.png"); Manual.addTabRenderer(renderer); ``` -------------------------------- ### Using the Note Block Component Source: https://github.com/mightypirates/opencomputers/wiki/Component-NoteBlock Demonstrates how to get the note_block component, set its pitch, trigger a single note, and play all possible pitches. ```lua local component = require("component") local nb = component.note_block -- get primary note block nb.setPitch(10) nb.trigger() for pitch = 1, 25 do nb.trigger(pitch) end ``` -------------------------------- ### ResourceContentProvider Usage Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/manual-api.md Example of creating and registering a ResourceContentProvider. ```java ContentProvider provider = new ResourceContentProvider( "mymod", "assets/mymod/doc" ); Manual.addProvider(provider); ``` -------------------------------- ### Wrapped Code Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/doc/en_US/general/example.md Demonstrates code that wraps due to line length limitations. ```plaintext 123456789012345678901234567890.1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 ``` ```plaintext 12345678901234567890.1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 ``` ```plaintext 123456789012345678901234567890.12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 ``` -------------------------------- ### Inline Code Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/doc/en_US/general/example.md Demonstrates the use of inline code formatting for short code snippets. ```plaintext test for code ``` ```plaintext that's not code yet ``` ```plaintext code ``` ```plaintext some more CODE that ``` -------------------------------- ### Rebooting Computer After a Delay Source: https://github.com/mightypirates/opencomputers/wiki/API-Event This example demonstrates using `event.timer` to repeatedly check a condition and trigger an action (rebooting the computer) if met. It also shows how to limit the number of timer executions. ```lua local computer = require("computer") local event = require("event") function onTimer() computer.shutdown(true) end event.timer(30, onTimer, 50) --run 50 times, then stop. If it's still not past 300 seconds by then, we've got other things to worry about. ``` -------------------------------- ### Code Block Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/doc/en_US/general/example.md Shows a multi-line code block with indentation and function definition. ```lua function f(a) testingIndent(a) do lalala() end end ``` -------------------------------- ### Simple Block Component Integration Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/README.md Example of creating a custom block component that integrates with the OpenComputers network. Ensure the component joins or creates a network when the entity updates. ```Java public class MyTile extends TileEntity implements Environment { private ComponentConnector node; public MyTile() { node = (ComponentConnector) Network.newNode(this, Visibility.Network) .withComponent("mydevice") .withConnector(100) .create(); } @Override public void updateEntity() { if (!worldObj.isRemote && node.network() == null) { Network.joinOrCreateNetwork(this); } } @Override public Node node() { return node; } @Override public void onConnect(Node node) {} @Override public void onDisconnect(Node node) {} @Override public void onMessage(Message message) {} @Callback public Object[] doSomething(Context context, Arguments args) throws Exception { return new Object[]{true}; } ``` -------------------------------- ### Get Labeling Program Usage Source: https://github.com/mightypirates/opencomputers/wiki/Tutorial-HardDrives Run the `label` command with no arguments to see its usage information and available options, such as `-a` for adding a label. ```bash label ``` -------------------------------- ### computer.totalMemory() Source: https://github.com/mightypirates/opencomputers/wiki/API-Computer Gets the total amount of installed memory in bytes. ```APIDOC ## computer.totalMemory() ### Description Returns the total amount of memory installed in this computer, in bytes. ### Method GET ### Endpoint /computer/totalMemory ### Response #### Success Response (200) - **memory** (number) - The total amount of installed memory in bytes. ``` -------------------------------- ### Accessing Key Codes by Name and Value Source: https://github.com/mightypirates/opencomputers/wiki/API-Keyboard Demonstrates how to use the `keyboard.keys` table to get the numerical code for a key name (e.g., `numpad0`) and vice-versa. ```Lua local numpad0_code = keyboard.keys.numpad0 local numpad0_name = keyboard.keys[0x52] ``` -------------------------------- ### Good Lua Function Example with checkArg Source: https://github.com/mightypirates/opencomputers/wiki/CodeConventions Demonstrates recommended Lua coding practices, including consistent naming, proper indentation, use of `checkArg` for argument validation, and concise code. ```lua function f(name, ...) checkArg(1, name, "string") if name then local result = 1 -- We extrapolate the b-spline of the non-euclidean space to -- determine the fraction of potential failures encountered. return result end end if f("a") == 1 then print("asd") end ``` -------------------------------- ### Create File System with Configuration Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/configuration.md Create a file system using configuration values for size and buffering. Uses FileSystem.fromMemory and FileSystem.asManagedEnvironment. ```java public ManagedEnvironment createFileSystem() { long tmpfsSize = API.config.getLong("memory.tmpfsSize"); boolean buffered = API.config.getBoolean("filesystem.buffer"); FileSystem fs = FileSystem.fromMemory(tmpfsSize); return FileSystem.asManagedEnvironment( fs, "tmp", null, null ); } ``` -------------------------------- ### FileSystem.asManagedEnvironment (minimal label) Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md Minimal configuration: just file system and label, no host or sound. ```APIDOC ## FileSystem.asManagedEnvironment (Label label) ### Description Minimal configuration: just file system and label, no host or sound. ### Method static ### Parameters #### Path Parameters - **fileSystem** (FileSystem) - Required - The file system to wrap - **label** (Label) - Required - Writable label object, or `null` for no label ### Returns `ManagedEnvironment` - Network node wrapping the file system ``` -------------------------------- ### Get Machine Timing Information Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/QUICK-REFERENCE.md Retrieve timing information for a machine, including world time, uptime since start, and CPU execution time. The `Machine` object is accessed via the `Context`. ```java @Callback public Object[] time(Context context, Arguments args) throws Exception { Machine m = context.machine(); long worldTime = m.worldTime(); double upTime = m.upTime(); // seconds since start double cpuTime = m.cpuTime(); // CPU execution time return new Object[]{worldTime}; } ``` -------------------------------- ### FileSystem.asManagedEnvironment (minimal string label) Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md Minimal configuration with read-only string label. ```APIDOC ## FileSystem.asManagedEnvironment (String label) ### Description Minimal configuration with read-only string label. ### Method static ### Parameters #### Path Parameters - **fileSystem** (FileSystem) - Required - The file system to wrap - **label** (String) - Required - Read-only label string ### Returns `ManagedEnvironment` - Network node wrapping the file system ``` -------------------------------- ### Thread Safety Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/README.md Example illustrating how to ensure thread safety for direct callbacks in OpenComputers components. ```APIDOC ### Thread Safety Direct callbacks must be thread-safe. Use `synchronized` blocks or thread-safe data structures: ```java @Callback(direct = true) public Object[] threadSafeGet(Context context, Arguments args) { synchronized(this) { return new Object[]{cachedValue}; } } ``` ``` -------------------------------- ### Create a File System Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/README.md This snippet shows how to create a file system, either from the save directory or as a managed environment, and associate it with a component. ```APIDOC ## Create a File System ### Description Creates a file system that can be used by OpenComputers machines. This can be a file system backed by the game's save directory or a managed environment. It can be assigned a specific size limit. ### Method `FileSystem.fromSaveDirectory()` and `FileSystem.asManagedEnvironment()` ### Parameters - **name** (String) - The name of the file system (e.g., for mounting). - **size** (Long) - The maximum size of the file system in bytes. - **owner** (Object) - The owner of the managed environment. - **mountPoint** (String) - The mount point for the file system within the computer. - **id** (String) - A unique identifier for the file system. ### Request Example ```java FileSystem fs = FileSystem.fromSaveDirectory("mydata", 1024*1024); ManagedEnvironment node = FileSystem.asManagedEnvironment( fs, "data", this, "opencomputers:harddrive_access" ); ``` ``` -------------------------------- ### Create and Manage a File System Component Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md This Java snippet demonstrates how to create a file system component, wrap it as a managed environment, and connect it to the network. It utilizes FileSystem.fromSaveDirectory and FileSystem.asManagedEnvironment. ```java public ManagedEnvironment createDrive(String name, long capacity) { // Create the underlying file system FileSystem fs = FileSystem.fromSaveDirectory(name, capacity, true); // Wrap as a managed environment ManagedEnvironment node = FileSystem.asManagedEnvironment( fs, name, // Label this, // Host "opencomputers:harddrive_access", // Sound 2 // Speed ); // Connect to network Network.joinOrCreateNetwork(this); return node; } ``` -------------------------------- ### Get File Size Source: https://github.com/mightypirates/opencomputers/wiki/API-Filesystem Gets the size of a file at the specified path. Returns 0 if the path points to a directory or does not exist. ```lua filesystem.size(path) ``` -------------------------------- ### TextureTabIconRenderer Usage Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/manual-api.md Example of creating and registering a TextureTabIconRenderer. ```java TabIconRenderer renderer = new TextureTabIconRenderer( "mymod:textures/gui/manual_icon.png" ); Manual.addTabRenderer(renderer); ``` -------------------------------- ### Basic GPU Screen Clearing and Drawing Source: https://github.com/mightypirates/opencomputers/wiki/Component-GPU This example demonstrates clearing the screen, setting foreground and background colors, filling a portion of the screen, and copying a screen region. It requires the 'component' library and assumes a primary GPU component is available. ```lua local component = require("component") local gpu = component.gpu -- get primary gpu component local w, h = gpu.getResolution() gpu.fill(1, 1, w, h, " ") -- clears the screen gpu.setForeground(0x000000) gpu.setBackground(0xFFFFFF) gpu.fill(1, 1, w/2, h/2, "X") -- fill top left quarter of screen gpu.copy(1, 1, w/2, h/2, w/2, h/2) -- copy top left quarter of screen to lower right ``` -------------------------------- ### ItemStackTabIconRenderer Usage Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/manual-api.md Example of creating and registering an ItemStackTabIconRenderer. ```java TabIconRenderer renderer = new ItemStackTabIconRenderer( new ItemStack(myItem) ); Manual.addTabRenderer(renderer); ``` -------------------------------- ### HOCON Basic Syntax Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/configuration.md Demonstrates the basic syntax of HOCON configuration files, including comments, values, strings, numbers, booleans, arrays, and nested objects. ```hocon # Comments start with # # Simple value key = value # Quoted strings name = "My String" # Numbers integer = 42 floating = 3.14 # Booleans enabled = true disabled = false # Arrays array = [1, 2, 3, 4] # Nested objects section { key1 = "value1" key2 = "value2" } # Dot notation section.key1 = "value1" ``` -------------------------------- ### Create IntelliJ IDEA Project Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/README.md After setting up the workspace, run this command to generate the IntelliJ IDEA project files. ```bash gradlew idea ``` -------------------------------- ### computer.freeMemory() Source: https://github.com/mightypirates/opencomputers/wiki/API-Computer Gets the amount of currently unused memory in bytes. ```APIDOC ## computer.freeMemory() ### Description Returns the amount of memory currently unused, in bytes. If this gets close to zero your computer will probably soon crash with an out of memory error. ### Method GET ### Endpoint /computer/freeMemory ### Response #### Success Response (200) - **memory** (number) - The amount of free memory in bytes. ``` -------------------------------- ### computer.energy() Source: https://github.com/mightypirates/opencomputers/wiki/API-Computer Gets the amount of energy available in the computer's network. ```APIDOC ## computer.energy() ### Description Returns the amount of energy currently available in the network the computer is in. For a robot this is the robot's own energy / fuel level. ### Method GET ### Endpoint /computer/energy ### Response #### Success Response (200) - **energy** (number) - The amount of available energy. ``` -------------------------------- ### computer.addUser(name: string) Source: https://github.com/mightypirates/opencomputers/wiki/API-Computer Registers a new user with the computer. ```APIDOC ## computer.addUser(name: string) ### Description Registers a new user with this computer. The user must be currently in the game and will gain full access rights. ### Method POST ### Endpoint /computer/addUser ### Parameters #### Request Body - **name** (string) - Required - The name of the user to add. ### Response #### Success Response (200) - **success** (boolean) - True if the user was successfully added. #### Error Response (400) - **error** (string) - An error message if the user could not be added. ``` -------------------------------- ### Inline Image Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/doc/en_US/general/example.md Shows an inline image rendered within text. ```plaintext this is a test for an![](oredict:oc:cpu1)an inline image kakakakalalsd 123 as ``` -------------------------------- ### Accessing Configuration API Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/configuration.md Demonstrates how to access the main configuration object and specific settings like power enablement and custom values using the OpenComputers API. ```java import com.typesafe.config.Config; import li.cil.oc.api.API; Config config = API.config; ``` -------------------------------- ### Machine.getArchitectureName Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/machine-api.md Gets the name of a registered architecture. Returns null if the architecture is not registered. ```APIDOC ## Machine.getArchitectureName(Class architecture) ### Description Gets the name of a registered architecture. ### Method `public static String getArchitectureName(Class architecture)` ### Parameters #### Path Parameters - **architecture** (Class) - Required - The architecture class ### Returns #### Success Response - **name** (String) - The name of the architecture, or `null` if not registered ### Response Example ```java String name = Machine.getArchitectureName(Machine.LuaArchitecture); System.out.println("Lua architecture: " + name); ``` ``` -------------------------------- ### FileSystem.asManagedEnvironment (full) Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md Creates a network node that exposes the file system as a component. The file system will appear as a `filesystem` component in the network. ```APIDOC ## FileSystem.asManagedEnvironment ### Description Creates a network node that exposes the file system as a component. The file system will appear as a `filesystem` component in the network. ### Method static ### Parameters #### Path Parameters - **fileSystem** (FileSystem) - Required - The file system to wrap - **label** (Label) - Required - Writable label object, or `null` for no label - **host** (EnvironmentHost) - Optional - Container for context (e.g., block position) - **accessSound** (String) - Optional - Resource name of access sound (e.g., "opencomputers:floppy_access") - **speed** (int) - Required - Speed multiplier (1-6). Default is 1 ### Returns `ManagedEnvironment` - Network node wrapping the file system ### Speed Multiplier - 1: Floppy disks (default) - 2-4: Hard drives (tier-dependent) - Higher: Faster access ### Example ```java FileSystem fs = FileSystem.fromMemory(1024 * 1024); ManagedEnvironment node = FileSystem.asManagedEnvironment( fs, "data", tileEntity, "opencomputers:harddrive_access", 2 ); node.node().sendToReachable("network.connect", new Object[]{}); ``` ``` -------------------------------- ### robot.name Source: https://github.com/mightypirates/opencomputers/wiki/API-Robot Gets the current name of the robot. The name can be changed using an anvil. ```APIDOC ## robot.name ### Description Gets the current name of the robot (can be changed using an anvil). ### Method `robot.name(): string` ``` -------------------------------- ### computer.maxEnergy() Source: https://github.com/mightypirates/opencomputers/wiki/API-Computer Gets the maximum amount of energy that can be stored in the computer's network. ```APIDOC ## computer.maxEnergy() ### Description Returns the maximum amount of energy that can be stored in the network the computer is in. For a robot this is the size of the robot's internal buffer. ### Method GET ### Endpoint /computer/maxEnergy ### Response #### Success Response (200) - **maxEnergy** (number) - The maximum energy capacity. ``` -------------------------------- ### FileSystem.fromClass Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md Creates a read-only file system from a JAR asset directory. The path is constructed as: `/assets/{domain}/{root}`. ```APIDOC ## FileSystem.fromClass ### Description Creates a read-only file system from a JAR asset directory. The path is constructed as: `/assets/{domain}/{root}`. ### Signature ```java public static li.cil.oc.api.fs.FileSystem fromClass( final Class clazz, final String domain, final String root) ``` ### Parameters #### Path Parameters - **clazz** (Class) - Required - The class whose containing JAR to use - **domain** (String) - Required - The domain/mod ID (e.g., "opencomputers") - **root** (String) - Optional - Optional subdirectory within assets ### Returns `li.cil.oc.api.fs.FileSystem` - Read-only file system, or `null` if path not found ### Example ```java FileSystem fs = FileSystem.fromClass( MyModClass.class, "mymod", "loot/startup" ); ``` ``` -------------------------------- ### List Item Code Example Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/doc/en_US/general/example.md Illustrates how code can be rendered within list items. ```plaintext work for code rendered text, if it doesn't i ``` -------------------------------- ### Setting and Running a Command Block Command Source: https://github.com/mightypirates/opencomputers/wiki/Component-CommandBlock This snippet demonstrates how to get the command block component, set a new command (in this case, changing the in-game time), and then execute it. It also shows how to print the current date before and after the command execution. ```lua local component = require("component") local cb = component.command_block -- get primary command block -- os.time() returns "in-game seconds" with a 6000 tick offset, so that -- midnight is actually midnight. local ticks = math.floor(1000/60/60 * os.time() - 6000) print(os.date()) cb.setValue("time set " .. (ticks + 24000)) cb.run() print(os.date()) -- one day more than before ``` -------------------------------- ### Print a Model using 3D Printer Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/doc/en_US/block/printer.md Use this command to initiate printing of a .3dm model file. Ensure the printer is configured and has the necessary input materials. ```bash print3d /path/to/file.3dm ``` -------------------------------- ### FileSystem.fromComputerCraft Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md Wraps a ComputerCraft file system mount. Supports both CC 1.5x and 1.6x mount types. ```APIDOC ## FileSystem.fromComputerCraft ### Description Wraps a ComputerCraft file system mount. Supports both CC 1.5x and 1.6x mount types. ### Signature ```java public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final Object mount) ``` ### Parameters #### Path Parameters - **mount** (Object) - Required - The ComputerCraft mount object ### Returns `li.cil.oc.api.fs.FileSystem` - Wrapped ComputerCraft file system ### Throws Exception if the mount type is unsupported. ### Example ```java Object ccMount = ...; // From ComputerCraft try { FileSystem fs = FileSystem.fromComputerCraft(ccMount); } catch (Exception e) { System.err.println("Unsupported CC mount type"); } ``` ``` -------------------------------- ### Label Interface Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/types.md Provides functionality to get and set a writable label for a file system. ```APIDOC ## Interface: Label ### Description Writable file system label. ### Methods - `String getLabel()`: Gets the current label of the file system. - `boolean setLabel(String label)`: Sets the label of the file system. - `int maxLabelLength()`: Returns the maximum allowed length for the label. ``` -------------------------------- ### Create an OpenComputers Machine Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/QUICK-REFERENCE.md Initializes a new OpenComputers machine instance. Requires an object implementing the MachineHost interface. The machine's update method must be called each tick. ```java li.cil.oc.api.machine.Machine machine = Machine.create(hostImplementing MachineHost); // Update each tick machine.update(); // Access components Map components = machine.components(); // Check for errors if (machine.lastError() != null) { System.err.println("Machine crashed: " + machine.lastError()); } ``` -------------------------------- ### ImageRenderer Interface Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/manual-api.md Defines methods for custom image rendering, including getting dimensions. ```java public interface ImageRenderer { void render(BufferedImage image, String path); int getWidth(String path); int getHeight(String path); } ``` -------------------------------- ### Machine.architecture Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/machine-api.md Returns the underlying architecture of the machine, or null if no CPU is installed. This is part of the Machine interface. ```APIDOC ## architecture() ### Description Returns the underlying architecture, or `null` if no CPU is installed. ### Method `Architecture architecture()` ### Returns #### Success Response - **architecture** (Architecture) - The underlying architecture, or `null` if no CPU is installed ``` -------------------------------- ### Create Directory Source: https://github.com/mightypirates/opencomputers/wiki/API-Filesystem Creates a new directory at the specified path. Parent directories are created automatically if they do not exist. Returns true on success or nil and an error message on failure. ```lua filesystem.makeDirectory(path) ``` -------------------------------- ### Create Managed Environment for FileSystem Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md Exposes a FileSystem as a network component. Configure with a label, host, access sound, and speed multiplier for network access. ```Java FileSystem fs = FileSystem.fromMemory(1024 * 1024); ManagedEnvironment node = FileSystem.asManagedEnvironment( fs, "data", tileEntity, "opencomputers:harddrive_access", 2 ); node.node().sendToReachable("network.connect", new Object[]{}); ``` -------------------------------- ### Manual Page Heading Markup Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/manual-api.md Example of using '#' for different heading levels in manual pages. ```text # Heading Level 1 ## Heading Level 2 ### Heading Level 3 ``` -------------------------------- ### Integrate File System with Tile Entity Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/src/main/java/li/cil/oc/api/README.md Wraps files from a mod into an OpenComputers file system and attaches it to the component network. This example shows how to create a managed file system environment within a tile entity. ```java import li.cil.oc.api.network.Node; import li.cil.oc.api.network.Visibility; import li.cil.oc.api.driver.EnvironmentProvider; import li.cil.oc.api.FileSystem; import li.cil.oc.api.Network; import li.cil.oc.api.prefab.TileEntityEnvironment; import li.cil.oc.api.Persistable; import li.cil.oc.api.Context; import java.util.Optional; public class TileEntityWithFileSystem extends TileEntityEnvironment { private final Node fileSystem; public TileEntityWithFileSystem() { node = Network.newNode(this, Visibility.Network).create(); fileSystem = FileSystem.asManagedEnvironment(FileSystem.fromClass(getClass, "yourmodid/lua"), "my_files"); } @Override public void onConnect(final Node node) { if (node.host() instanceof Context) { // Attach our file system to new computers we get connected to. // Note that this is also called for all already present computers ``` -------------------------------- ### FileSystem.asManagedEnvironment (string label) Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md Same as above but with a read-only string label. ```APIDOC ## FileSystem.asManagedEnvironment (String label) ### Description Same as above but with a read-only string label. ### Method static ### Parameters #### Path Parameters - **fileSystem** (FileSystem) - Required - The file system to wrap - **label** (String) - Required - Read-only label string - **host** (EnvironmentHost) - Optional - Container for context - **accessSound** (String) - Optional - Resource name of access sound - **speed** (int) - Required - Speed multiplier (1-6) ### Returns `ManagedEnvironment` - Network node wrapping the file system ``` -------------------------------- ### robot.space Source: https://github.com/mightypirates/opencomputers/wiki/API-Robot Gets the available space in a specified inventory slot, or the selected slot if no slot is specified. ```APIDOC ## robot.space ### Description Gets how many more items can be put into the specified slot, which depends on the item already in the slot (for example, buckets only stack up to 16, so if there are 2 buckets in the slot this will return 14). If no slot is specified gets the available space in the selected slot. ### Method `robot.space([slot: number]): number` ``` -------------------------------- ### FileSystem.asManagedEnvironment (no label) Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/filesystem-api.md Unlabeled file system with no host or sound configuration. ```APIDOC ## FileSystem.asManagedEnvironment ### Description Unlabeled file system with no host or sound configuration. ### Method static ### Parameters #### Path Parameters - **fileSystem** (FileSystem) - Required - The file system to wrap ### Returns `ManagedEnvironment` - Network node wrapping the file system ``` -------------------------------- ### robot.count Source: https://github.com/mightypirates/opencomputers/wiki/API-Robot Gets the number of items in a specified inventory slot, or the selected slot if no slot is specified. ```APIDOC ## robot.count ### Description Gets the number of item in the specified inventory slot. If no slot is specified returns the number of items in the selected slot. ### Method `robot.count([slot: number]): number` ``` -------------------------------- ### Implement Basic Component Environment Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/README.md Implement the Environment interface for a custom block to integrate it with OpenComputers. This involves providing a network node. ```java import li.cil.oc.api.network.*; public class MyBlock extends Block implements Environment { private ComponentConnector node; @Override public Node node() { return node; } // Implement Environment methods... } ``` -------------------------------- ### shell.getPath Source: https://github.com/mightypirates/opencomputers/wiki/API-Shell Gets the search path used by shell.resolve. Alias for os.getenv("PATH"). ```APIDOC ## shell.getPath ### Description Gets the search path used by `shell.resolve`. This can contain multiple paths, separated by colons (`:`). This is an alias for `os.getenv("PATH")`. ### Method `shell.getPath(): string` ``` -------------------------------- ### Read Integer Configuration Value Safely Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/configuration.md Demonstrates how to read an integer configuration value, including error handling for non-existent keys and checking for key existence before reading. ```Java // If a value doesn't exist, getInt throws exception try { int value = config.getInt("nonexistent.key"); } catch (com.typesafe.config.ConfigException e) { System.out.println("Key not found: " + e.getMessage()); } // Check before reading if (config.hasPath("my.key")) { int value = config.getInt("my.key"); } ``` -------------------------------- ### event.timer Source: https://github.com/mightypirates/opencomputers/wiki/API-Event Starts a new timer that executes a callback after a specified interval. Can be set to repeat indefinitely. ```APIDOC ## event.timer ### Description Starts a new timer that will be called after the time specified in `interval`. Per default, timers only fire once. Pass `times` with a value larger than one to have it fire as often as that number specifies. Pass `math.huge` to create an infinitely repeating interval. This returns a number that identifies the created timer, and can be used in `timer.cancel` to destroy it, possibly before it even ran once. *Note*: the timer resolution can vary. If the computer is idle and enters sleep mode, it will only be woken in a game tick, so the time the callback is called may be up to 0.05 seconds off. **Important**: timers are driven by the `event.pull` function. If you always pull signals directly from `os.pullSignal` and never call `event.pull`, timers will not work! ### Parameters - **interval** (number) - Required - The time in seconds to wait before the callback is executed. - **callback** (function) - Required - The function to execute when the timer fires. - **times** (number) - Optional - The number of times the timer should fire. Defaults to 1. Use `math.huge` for infinite repetition. ``` -------------------------------- ### Manual Page Code Markup Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/manual-api.md Examples of inline code and indented code blocks for manual pages. ```text `inline code` Code block Indented lines become code ``` -------------------------------- ### Create Autorun Script for Mounting Source: https://github.com/mightypirates/opencomputers/wiki/Tutorial-HardDrives Create an `autorun.lua` script in the root of a hard drive to automatically mount it when inserted into a computer. This script receives the storage medium's proxy as its first argument. ```lua local fs = require("filesystem") local drive = fs.mount(..., "drive") fs.mount(drive, "/mnt/mydisk") ``` -------------------------------- ### Machine Timing Information Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/machine-api.md Get timing information related to the machine's operation and the world time. ```APIDOC ## `worldTime()` ### Description Retrieves the current world time, which is updated each tick. ### Method GET ### Endpoint `/machine/worldTime` ### Returns - **long** - The current world time ## `upTime()` ### Description Retrieves the time since the machine started, in seconds (world time based). ### Method GET ### Endpoint `/machine/upTime` ### Returns - **double** - Time since machine started, in seconds ## `cpuTime()` ### Description Retrieves the time spent executing the architecture, in seconds. ### Method GET ### Endpoint `/machine/cpuTime` ### Returns - **double** - Time spent executing the architecture, in seconds ``` -------------------------------- ### Get Item Information Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/QUICK-REFERENCE.md Retrieves information about a registered OpenComputers item, such as its tier and the ability to create an ItemStack from it. ```java ItemInfo info = Items.get("computer1"); ItemStack stack = info.createItemStack(1); int tier = info.tier(); ``` -------------------------------- ### Check API Availability During Mod Initialization Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/QUICK-REFERENCE.md Demonstrates the correct event handlers for checking API availability. The `API` is null during `preInit` but available during `init` and `postInit`. ```java @Mod.EventHandler public void preInit(FMLPreInitializationEvent e) { // API.* are null here - don't use API } @Mod.EventHandler public void init(FMLInitializationEvent e) { // API.* are initialized here - safe to use Driver.add(myDriver); } @Mod.EventHandler public void postInit(FMLPostInitializationEvent e) { // API.* still available } ``` -------------------------------- ### robot.level Source: https://github.com/mightypirates/opencomputers/wiki/API-Robot Gets the current level of the robot. The fractional part indicates progress towards the next level. ```APIDOC ## robot.level ### Description Gets the current level of the robot, with the fractional part being the percentual progress towards the next level. For example, if this is `1.5`, then the robot is level one, and 50% towards achieving level two. ### Method `robot.level(): number` ``` -------------------------------- ### Sign Component Callbacks Source: https://github.com/mightypirates/opencomputers/wiki/Component-Sign Provides methods to get and set the text displayed on a sign in front of the robot. ```APIDOC ## Sign Component API ### Description This API allows you to interact with the sign component, enabling you to retrieve the text currently displayed on a sign in front of the robot and to set new text for the sign. ### Callbacks #### `getValue(): string or nil, string` ##### Description Gets the text currently displayed on the sign in front of the robot. ##### Returns - `string`: The text on the sign. - `nil, string`: If there is no sign in front of the robot, returns `nil` and an error message. #### `setValue(value: string): string or nil, string` ##### Description Sets the text of the sign in front of the robot. ##### Parameters - **value** (string) - Required - The desired text to display on the sign. This may be truncated if it exceeds the sign's capacity. ##### Returns - `string`: The new text on the sign (potentially truncated). - `nil, string`: If there is no sign in front of the robot, returns `nil` and an error message. ``` -------------------------------- ### AbstractProvider Source: https://github.com/mightypirates/opencomputers/blob/master-MC1.7.10/_autodocs/api-reference/prefab-classes.md Base class for environment and other providers in OpenComputers. ```APIDOC ## Class: AbstractProvider ### Description Base class for environment and other providers. This abstract class serves as a foundation for creating custom providers within the OpenComputers system. ### Methods to Override - `public abstract Class[] types()`: Returns an array of classes that this provider is responsible for. ``` -------------------------------- ### Get Shell Search Path Source: https://github.com/mightypirates/opencomputers/wiki/API-Shell Retrieves the search path used by shell.resolve. Paths are separated by colons. ```lua shell.getPath() ```