public interface SimpleComponent
Environment
themselves. The simple implementation will provide no access to OC's internal
component network, since you won't have access to the node representing the
tile entity. Use this only for simple cases, where you want to expose a
couple of methods to the programs running computers.
This is an interface instead of an annotation, to allow stripping via the
ever so handy Optional
annotation, meaning there
will be no strong dependency on OpenComputers.
Classes implementing this interface will be expanded with the methods
required for them to function as native block components (say, like the
screen or keyboard). This means functions in the Environment
interface have to created using a class transformer. If any of the methods
already exist, this will fail! If things don't work, check your logs, first.
To expose methods to OC, tag them with Callback
and have them use the according signature (see the documentation on the
Callback annotation).
Alternatively, implement ManagedPeripheral
in
addition to this interface, to make methods available ComputerCraft style.
So, in short:
@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers") public class TileEntityMyFancyThing extends TileEntity implements SimpleComponent { @Override public String getComponentName() { return "fancy_thing"; } @Callback @Optional.Method(modid = "OpenComputers") public Object[] greet(Context context, Arguments args) { return new Object[]{String.format("Hello, %s!", args.checkString(0))}; } }Using the alternative method to provide methods:
@Optional.InterfaceList({ @Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers"), @Optional.Interface(iface = "li.cil.oc.api.network.ManagedPeripheral", modid = "OpenComputers") }) public class TileEntityMyFancyThing extends TileEntity implements SimpleComponent, ManagedPeripheral { @Override public String getComponentName() { return "fancy_thing"; } public String[] methods() { return new String[] {"greet"}; } @Optional.Method(modid = "OpenComputers") public Object[] invoke(String method, Context context, Arguments args) { if ("greet".equals(method)) { return new Object[]{String.format("Hello, %s!", args.checkString(0))}; } else { throw new NoSuchMethodException(); } } }
Modifier and Type | Interface and Description |
---|---|
static interface |
SimpleComponent.SkipInjection
Use this to skip logic injection for the class this is implemented by.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getComponentName()
The name the component should be made available as.
|
java.lang.String getComponentName()
component.list() in Lua, for example. You'll want to make this short and descriptive. The convention for component names is: all lowercase, underscores where necessary. Good component names are for example: disk_drive, furnace, crafting_table.