Skip to content
Branch: master-MC1.7.10
Find file History
payonel Merge pull request #2075 from thiakil/WorldInventoryAnalytics-updates-pr
World Inventory Analytics Improvements

closes #2771
Latest commit 352aaef Mar 11, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
component Only pass X and Y to RackMountable.onActivate, adjusted to the actual… May 14, 2016
detail Allow addons to register their floppies for loot disk cycling. Dec 30, 2016
driver Fixed CPU and memory not being neighbor only visible. Jun 5, 2016
event Added SignChangeEvent to sign upgrade Jul 31, 2016
fs Extended file system API to allow specifying a speed multiplier for f… Apr 22, 2015
internal Added `Rack.indexOfMountable`. Jan 6, 2016
machine Merge branch 'onesix' into rack-overhaul Oct 30, 2015
manual Fixed chamelium blocks being registered breaking mipmaps. Closes #1061. Apr 14, 2015
nanomachines Some tweaks to the nanomachines. Sep 18, 2015
network Fixed nodes able to reach an added node but not being reachable by th… Feb 5, 2017
prefab Merge pull request #2075 from thiakil/WorldInventoryAnalytics-updates-pr Mar 11, 2018
util Tons of hacking to allow components client side, specifically allow c… Nov 14, 2015 Added a rack mountable version of the disk drive. Nov 21, 2015 Robot assembler textures and renderer. May 17, 2014 Allow multiple environment providers to return environments for the s… Dec 11, 2016 Hrmm, where was I? Oh well. Oct 13, 2015 Added `computer.getProgramLocations` and IMC message to populate the … Jun 9, 2016 Allow addons to register their floppies for loot disk cycling. Dec 30, 2016 Some housekeeping, removing old code, resolving some old TODOs. Nov 15, 2015 Some more refactoring, vastly improved masking for manual. Apr 9, 2015 Energy based, configurable (and potentially deadly) buff system: nano… Sep 17, 2015 Tracking previous dimension in nanomachine controller to robustly han… Nov 21, 2015 moved things into separate folders to separate own source code from a… Feb 2, 2014 Added reference class to API to centralize version updating. Oct 10, 2014 Added reference class to API to centralize version updating. Oct 10, 2014

The API can be used to either interact with existing implementations in OpenComputers or to implement your own extensions for OpenComputers.

Extending OpenComputers

Making a tile entity available as a component / peripheral

If you simply wish to expose a couple of methods that can be called from a computer if your tile entity's block is 'connected' to the computer, you can use the SimpleComponent interface. This interface serves as a marker for OpenComputers to know it has to inject code that converts your tile entity into a component using its class transformer. It is an interface instead of an annotation to allow stripping it, removing any dependencies on OpenComputers. Here is an example implementation:

@Optional.Interface(iface = "", modid = "OpenComputers")
public class TileEntityMyFancyThing extends TileEntity
       implements SimpleComponent
    public String getComponentName() {
        return "fancy_thing";

    @Optional.Method(modid = "OpenComputers")
    public Object[] greet(Context context, Arguments args) {
        return new Object[]{String.format("Hello, %s!", args.checkString(0))};

The getComponentName determines with which name the tile entity will be available to computers. The Callback annotation tells OpenComputers to make the annotated method available to the computer. See the documentation on the Callback annotation for more information, in particular how it can be used to manipulate the call behavior (synchronized to the main thread vs. in the thread driving the calling computer).

So to call the greeter method, in Lua you'd do this:

print(component.fancy_thing.greet("Steve")) -- prints "Hello, Steve!"

More control

If you really need more control over how how your tile entity interacts with OpenComputer's internal network, you will have to implement the Environment interface on your tile entity. There's a basic implementation in the prefab package, named TileEntityEnvironment. Doing so will give you access to the Node that connects to the component network, and you must take care of the construction of the node itself (using the factory method in api.Network). This allows you to make the node a Connector node, which will allow you to draw internal power from OpenComputers or feed energy into it. You will also be able to send messages over the component network, see the send... methods in the Node interface. See the documentation on those interfaces to get a better idea on how they work together.

Making a third-party block available as component / peripheral

Blocks from other mods, i.e. blocks where you have no control over the tile entity implementation, can be accessed using the Adapter block as long as there is a driver available that supports the block. If there are multiple drivers they are automatically merged. Please see the integration package for examples, and consider contributing any block drivers you write. Thank you!

Making items available as components

To make items usable as components in computers, such as cards or hard drives, you have to provide a driver for that item. This means you have to implement the driver.Item interface on a class and register an instance of it via the api.Driver registry. You can base your item drivers on the DriverItem prefab. Please see the example project on Github for a working example, and read the documentation of the driver interface for more information.

FileSystem API

If you'd like to make some files/scripts you ship with your mod available to a computer, you can do so by wrapping those files using an OpenComputers file system. Use the factory methods in api.FileSystem to wrap the location your files are stored at in a file system, use the asManagedEnvironment methods to wrap it in a node that can be attached to the component network. For example, in an environment of a tile entity or created by an item driver you could do this in the onConnect method whenever a computer is connected (i.e. instanceof Context). Code-wise it may look something like this:

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");

    public void onConnect(final Node node) {
        if ( instanceof Context) {
            // Attach our file system to new computers we get connected to.
            // Note that this is also called for all already present computers
            // when we're added to an already existing network, so we don't
            // have to loop through the existing nodes manually.

    public void onDisconnect(final Node node) {
        if ( instanceof Context) {
            // Remove our file systems when we get disconnected from a
            // computer.
        } else if (node == this.node) {
            // Remove the file system if we are disconnected, because in that
            // case this method is only called once.
You can’t perform that action at this time.