diff --git a/src/main/java/li/cil/oc/api/component/package-info.java b/src/main/java/li/cil/oc/api/component/package-info.java index 16a4732ac..4de70a1bc 100644 --- a/src/main/java/li/cil/oc/api/component/package-info.java +++ b/src/main/java/li/cil/oc/api/component/package-info.java @@ -1,8 +1,12 @@ /** - * This package contains component specific interfaces. + * This package provides interfaces to allow interacting with some components. *

- * These are implemented by some of the environments created by item drivers - * for built-in items, which allows for them to be re-used by third-party mods - * without having to access the internals of OpenComputers. + * These interfaces allow more specific interaction with some of OpenComputers' + * components, which would otherwise require reflection or linking against the + * mod itself. */ +@cpw.mods.fml.common.API( + owner = "OpenComputers|Core", + provides = "OpenComputersAPI|Component", + apiVersion = "3.0.0") package li.cil.oc.api.component; \ No newline at end of file diff --git a/src/main/java/li/cil/oc/api/driver/Processor.java b/src/main/java/li/cil/oc/api/driver/Processor.java index 60bca3e37..8b12ea125 100644 --- a/src/main/java/li/cil/oc/api/driver/Processor.java +++ b/src/main/java/li/cil/oc/api/driver/Processor.java @@ -1,5 +1,6 @@ package li.cil.oc.api.driver; +import li.cil.oc.api.machine.Architecture; import net.minecraft.item.ItemStack; /** @@ -19,4 +20,16 @@ public interface Processor extends Item { * @return the number of additionally supported components. */ int supportedComponents(ItemStack stack); + + /** + * The architecture of this CPU. + *

+ * This usually controls which architecture is created for a machine the + * CPU is installed in (this is true for all computers built into OC, such + * as computer cases, server racks and robots, it my not be true for third- + * party computers). + * + * @return the type of this CPU's architecture. + */ + Class architecture(); } diff --git a/src/main/java/li/cil/oc/api/driver/package-info.java b/src/main/java/li/cil/oc/api/driver/package-info.java index 9dcdc933d..c33483a89 100644 --- a/src/main/java/li/cil/oc/api/driver/package-info.java +++ b/src/main/java/li/cil/oc/api/driver/package-info.java @@ -4,4 +4,8 @@ * Drivers are used to add items and third party blocks to the internal network, * which is mostly used to make components wrapping them available to computers. */ +@cpw.mods.fml.common.API( + owner = "OpenComputers|Core", + provides = "OpenComputersAPI|Driver", + apiVersion = "3.0.0") package li.cil.oc.api.driver; \ No newline at end of file diff --git a/src/main/java/li/cil/oc/api/event/package-info.java b/src/main/java/li/cil/oc/api/event/package-info.java new file mode 100644 index 000000000..51cc4aa3a --- /dev/null +++ b/src/main/java/li/cil/oc/api/event/package-info.java @@ -0,0 +1,9 @@ +/** + * Events dispatched by OpenComputers to allow other mods to hook into some + * of its functionality. + */ +@cpw.mods.fml.common.API( + owner = "OpenComputers|Core", + provides = "OpenComputersAPI|Event", + apiVersion = "3.0.0") +package li.cil.oc.api.event; \ No newline at end of file diff --git a/src/main/java/li/cil/oc/api/fs/package-info.java b/src/main/java/li/cil/oc/api/fs/package-info.java index 1a3d776d0..e72369faa 100644 --- a/src/main/java/li/cil/oc/api/fs/package-info.java +++ b/src/main/java/li/cil/oc/api/fs/package-info.java @@ -13,4 +13,8 @@ * that can be added as component nodes to the network, so they can be used * from computers). */ +@cpw.mods.fml.common.API( + owner = "OpenComputers|Core", + provides = "OpenComputersAPI|FileSystem", + apiVersion = "3.0.0") package li.cil.oc.api.fs; \ No newline at end of file diff --git a/src/main/java/li/cil/oc/api/machine/package-info.java b/src/main/java/li/cil/oc/api/machine/package-info.java index adc4883cb..d59bea436 100644 --- a/src/main/java/li/cil/oc/api/machine/package-info.java +++ b/src/main/java/li/cil/oc/api/machine/package-info.java @@ -16,4 +16,8 @@ * implemented, but merely to allow accessing some mod internals in a regulated * fashion, such as {@link li.cil.oc.api.machine.Robot}. */ +@cpw.mods.fml.common.API( + owner = "OpenComputers|Core", + provides = "OpenComputersAPI|Machine", + apiVersion = "3.0.0") package li.cil.oc.api.machine; \ No newline at end of file diff --git a/src/main/java/li/cil/oc/api/network/Arguments.java b/src/main/java/li/cil/oc/api/network/Arguments.java index d316a2038..c53fccfcc 100644 --- a/src/main/java/li/cil/oc/api/network/Arguments.java +++ b/src/main/java/li/cil/oc/api/network/Arguments.java @@ -117,6 +117,108 @@ public interface Arguments extends Iterable { */ Map checkTable(int index); + /** + * Get whatever is at the specified index. + *

+ * Return the specified default value if there is no such element, behaves + * like {@link #checkAny(int)} otherwise. + *

+ * The returned object will be one of the following, based on the conversion + * performed internally: + *

+ * + * @param index the index from which to get the argument. + * @return the raw value at that index. + * @throws IllegalArgumentException if there is no argument at that index. + */ + Object optAny(int index, Object def); + + /** + * Try to get a boolean value at the specified index. + *

+ * Return the specified default value if there is no such element, behaves + * like {@link #checkBoolean(int)} otherwise. + * + * @param index the index from which to get the argument. + * @return the boolean value at the specified index. + * @throws IllegalArgumentException if there is no argument at that index, + * or if the argument is not a boolean. + */ + boolean optBoolean(int index, boolean def); + + /** + * Try to get an integer value at the specified index. + *

+ * Return the specified default value if there is no such element, behaves + * like {@link #checkInteger(int)} otherwise. + * + * @param index the index from which to get the argument. + * @return the integer value at the specified index. + * @throws IllegalArgumentException if there is no argument at that index, + * or if the argument is not a number. + */ + int optInteger(int index, int def); + + /** + * Try to get a double value at the specified index. + *

+ * Return the specified default value if there is no such element, behaves + * like {@link #checkDouble(int)} otherwise. + * + * @param index the index from which to get the argument. + * @return the double value at the specified index. + * @throws IllegalArgumentException if there is no argument at that index, + * or if the argument is not a number. + */ + double optDouble(int index, double def); + + /** + * Try to get a string value at the specified index. + *

+ * Return the specified default value if there is no such element, behaves + * like {@link #checkString(int)} otherwise. + *

+ * This will actually check for a byte array and convert it to a string + * using UTF-8 encoding. + * + * @param index the index from which to get the argument. + * @return the boolean value at the specified index. + * @throws IllegalArgumentException if there is no argument at that index, + * or if the argument is not a string. + */ + String optString(int index, String def); + + /** + * Try to get a byte array at the specified index. + *

+ * Return the specified default value if there is no such element, behaves + * like {@link #checkByteArray(int)} otherwise. + * + * @param index the index from which to get the argument. + * @return the byte array at the specified index. + * @throws IllegalArgumentException if there is no argument at that index, + * or if the argument is not a byte array. + */ + byte[] optByteArray(int index, byte[] def); + + /** + * Try to get a table at the specified index. + *

+ * Return the specified default value if there is no such element, behaves + * like {@link #checkTable(int)} otherwise. + * + * @param index the index from which to get the argument. + * @return the table at the specified index. + * @throws IllegalArgumentException if there is no argument at that index, + * or if the argument is not a table. + */ + Map optTable(int index, Map def); + /** * Tests whether the argument at the specified index is a boolean value. *

@@ -182,4 +284,13 @@ public interface Arguments extends Iterable { * @return true if the argument is a string; false otherwise. */ boolean isTable(int index); + + /** + * Converts the argument list to a standard Java array, converting byte + * arrays to strings automatically, since this is usually what others + * want - if you need the actual raw byte arrays, don't use this method! + * + * @return an array containing all arguments. + */ + Object[] toArray(); } diff --git a/src/main/java/li/cil/oc/api/network/Component.java b/src/main/java/li/cil/oc/api/network/Component.java index b471692c2..d26c3342a 100644 --- a/src/main/java/li/cil/oc/api/network/Component.java +++ b/src/main/java/li/cil/oc/api/network/Component.java @@ -82,4 +82,16 @@ public interface Component extends Node { * @throws NoSuchMethodException if there is no method with that name. */ Object[] invoke(String method, Context context, Object... arguments) throws Exception; + + /** + * Whether the specified method should be called directly or synchronously. + *

+ * Direct callbacks are called from a machine's executor thread, meaning + * its implementation has to take care of synchronization itself. Otherwise + * the callback is invoked from the Minecraft server thread. + * + * @param method the method to the the info for. + * @return true if the method shall be called directly. + */ + boolean isDirect(String method); } diff --git a/src/main/java/li/cil/oc/api/network/package-info.java b/src/main/java/li/cil/oc/api/network/package-info.java new file mode 100644 index 000000000..bcbf469cd --- /dev/null +++ b/src/main/java/li/cil/oc/api/network/package-info.java @@ -0,0 +1,11 @@ +/** + * This package provides component networking related functionality. + *

+ * This mainly involves the (purely server-side!) network that is spanned over + * all of OpenComputers' components, including blocks and items alike. + */ +@cpw.mods.fml.common.API( + owner = "OpenComputers|Core", + provides = "OpenComputersAPI|Network", + apiVersion = "3.0.0") +package li.cil.oc.api.network; \ No newline at end of file diff --git a/src/main/java/li/cil/oc/api/package-info.java b/src/main/java/li/cil/oc/api/package-info.java index 3d9635cc0..058dfa5b1 100644 --- a/src/main/java/li/cil/oc/api/package-info.java +++ b/src/main/java/li/cil/oc/api/package-info.java @@ -37,5 +37,5 @@ @cpw.mods.fml.common.API( owner = "OpenComputers|Core", provides = "OpenComputersAPI", - apiVersion = "2.0.2") + apiVersion = "3.0.0") package li.cil.oc.api; \ No newline at end of file diff --git a/src/main/scala/li/cil/oc/server/component/machine/luac/ComponentAPI.scala b/src/main/scala/li/cil/oc/server/component/machine/luac/ComponentAPI.scala index f07a57f3c..82ec19bfa 100644 --- a/src/main/scala/li/cil/oc/server/component/machine/luac/ComponentAPI.scala +++ b/src/main/scala/li/cil/oc/server/component/machine/luac/ComponentAPI.scala @@ -1,6 +1,6 @@ package li.cil.oc.server.component.machine.luac -import li.cil.oc.server +import li.cil.oc.api.network.Component import li.cil.oc.server.component.machine.NativeLuaArchitecture import li.cil.oc.util.ExtendedLuaState.extendLuaState @@ -41,7 +41,7 @@ class ComponentAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) { lua.pushScalaFunction(lua => { Option(node.network.node(lua.checkString(1))) match { - case Some(component: server.network.Component) if component.canBeSeenFrom(node) || component == node => + case Some(component: Component) if component.canBeSeenFrom(node) || component == node => lua.newTable() for (method <- component.methods()) { lua.pushString(method) diff --git a/src/main/scala/li/cil/oc/server/network/ArgumentsImpl.scala b/src/main/scala/li/cil/oc/server/network/ArgumentsImpl.scala index cf9f1d4b8..02a627de6 100644 --- a/src/main/scala/li/cil/oc/server/network/ArgumentsImpl.scala +++ b/src/main/scala/li/cil/oc/server/network/ArgumentsImpl.scala @@ -1,5 +1,7 @@ package li.cil.oc.server.network +import java.util + import com.google.common.base.Charsets import li.cil.oc.api.network @@ -101,7 +103,7 @@ class ArgumentsImpl(val args: Seq[AnyRef]) extends network.Arguments { } } - def optTable(index: Int, default: Map[_, _]) = { + def optTable(index: Int, default: util.Map[_, _]) = { if (!isDefined(index)) default else checkTable(index) }