mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 18:55:03 -04:00
Some more 1.4 API adjustments.
This commit is contained in:
parent
11ccc8898c
commit
2f8dca2643
@ -1,8 +1,12 @@
|
||||
/**
|
||||
* This package contains component specific interfaces.
|
||||
* This package provides interfaces to allow interacting with some components.
|
||||
* <p/>
|
||||
* 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;
|
@ -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.
|
||||
* <p/>
|
||||
* 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<? extends Architecture> architecture();
|
||||
}
|
||||
|
@ -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;
|
9
src/main/java/li/cil/oc/api/event/package-info.java
Normal file
9
src/main/java/li/cil/oc/api/event/package-info.java
Normal file
@ -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;
|
@ -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;
|
@ -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;
|
@ -117,6 +117,108 @@ public interface Arguments extends Iterable<Object> {
|
||||
*/
|
||||
Map checkTable(int index);
|
||||
|
||||
/**
|
||||
* Get whatever is at the specified index.
|
||||
* <p/>
|
||||
* Return the specified default value if there is no such element, behaves
|
||||
* like {@link #checkAny(int)} otherwise.
|
||||
* <p/>
|
||||
* The returned object will be one of the following, based on the conversion
|
||||
* performed internally:
|
||||
* <ul>
|
||||
* <li><tt>null</tt> if the Lua value was <tt>nil</tt>.</li>
|
||||
* <li><tt>java.lang.Boolean</tt> if the Lua value was a boolean.</li>
|
||||
* <li><tt>java.lang.Double</tt> if the Lua value was a number.</li>
|
||||
* <li><tt>byte[]</tt> if the Lua value was a string.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* Return the specified default value if there is no such element, behaves
|
||||
* like {@link #checkString(int)} otherwise.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
@ -182,4 +284,13 @@ public interface Arguments extends Iterable<Object> {
|
||||
* @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();
|
||||
}
|
||||
|
@ -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.
|
||||
* <p/>
|
||||
* 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 <tt>true</tt> if the method shall be called directly.
|
||||
*/
|
||||
boolean isDirect(String method);
|
||||
}
|
||||
|
11
src/main/java/li/cil/oc/api/network/package-info.java
Normal file
11
src/main/java/li/cil/oc/api/network/package-info.java
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* This package provides component networking related functionality.
|
||||
* <p/>
|
||||
* 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;
|
@ -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;
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user