Minor API change, added methods to query list of all block/item drivers. Mainly to allow third-party mods to make any use at all of the EnvironmentAware interface.

This commit is contained in:
Florian Nücke 2014-10-12 13:25:45 +02:00
parent febcabdde9
commit 4f953d3277
8 changed files with 80 additions and 8 deletions

View File

@ -11,7 +11,7 @@ import li.cil.oc.api.detail.*;
*/
public class API {
public static final String ID_OWNER = "OpenComputers|Core";
public static final String VERSION = "3.1.0";
public static final String VERSION = "3.1.1";
public static DriverAPI driver = null;
public static FileSystemAPI fileSystem = null;

View File

@ -7,6 +7,8 @@ import li.cil.oc.api.driver.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import java.util.Collection;
/**
* This API allows registering new drivers with the mod.
* <p/>
@ -131,6 +133,40 @@ public final class Driver {
return null;
}
/**
* Get a list of all registered block drivers.
* <p/>
* This is intended to allow checking for particular drivers using more
* customized logic, and in particular to check for drivers with the
* {@link li.cil.oc.api.driver.EnvironmentAware} interface.
* <p/>
* The returned collection is read-only.
*
* @return the list of all registered block drivers.
*/
public static Collection<Block> blockDrivers() {
if (API.driver != null)
return API.driver.blockDrivers();
return null;
}
/**
* Get a list of all registered item drivers.
* <p/>
* This is intended to allow checking for particular drivers using more
* customized logic, and in particular to check for drivers with the
* {@link li.cil.oc.api.driver.EnvironmentAware} interface.
* <p/>
* The returned collection is read-only.
*
* @return the list of all registered item drivers.
*/
public static Collection<Item> itemDrivers() {
if (API.driver != null)
return API.driver.itemDrivers();
return null;
}
// ----------------------------------------------------------------------- //
private Driver() {

View File

@ -3,6 +3,7 @@ package li.cil.oc.api;
import li.cil.oc.api.machine.Architecture;
import li.cil.oc.api.machine.MachineHost;
import java.util.Collection;
import java.util.Collections;
/**
@ -38,7 +39,7 @@ public final class Machine {
/**
* A list of all <em>registered</em> architectures.
*/
public static Iterable<Class<? extends Architecture>> architectures() {
public static Collection<Class<? extends Architecture>> architectures() {
if (API.machine != null)
return API.machine.architectures();
return Collections.emptyList();

View File

@ -7,6 +7,8 @@ import li.cil.oc.api.driver.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import java.util.Collection;
public interface DriverAPI {
/**
* Registers a new driver for a block component.
@ -92,4 +94,26 @@ public interface DriverAPI {
* @return a driver for the item, or <tt>null</tt> if there is none.
*/
Item driverFor(ItemStack stack);
/**
* Get a list of all registered block drivers.
* <p/>
* This is intended to allow checking for particular drivers using more
* customized logic, and in particular to check for drivers with the
* {@link li.cil.oc.api.driver.EnvironmentAware} interface.
*
* @return the list of all registered block drivers.
*/
Collection<Block> blockDrivers();
/**
* Get a list of all registered item drivers.
* <p/>
* This is intended to allow checking for particular drivers using more
* customized logic, and in particular to check for drivers with the
* {@link li.cil.oc.api.driver.EnvironmentAware} interface.
*
* @return the list of all registered item drivers.
*/
Collection<Item> itemDrivers();
}

View File

@ -4,6 +4,8 @@ import li.cil.oc.api.machine.Architecture;
import li.cil.oc.api.machine.Machine;
import li.cil.oc.api.machine.MachineHost;
import java.util.Collection;
public interface MachineAPI {
/**
* Register an architecture that can be used to create new machines.
@ -25,7 +27,7 @@ public interface MachineAPI {
* a custom architecture also registers it, you may not see it in this list
* until it also created a new machine using that architecture.
*/
Iterable<Class<? extends Architecture>> architectures();
Collection<Class<? extends Architecture>> architectures();
/**
* Creates a new machine for the specified host.

View File

@ -3,6 +3,8 @@ package li.cil.oc.api.network;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import java.util.Collection;
/**
* Components are nodes that can be addressed computers via drivers.
* <p/>
@ -68,11 +70,13 @@ public interface Component extends Node {
/**
* The list of names of methods exposed by this component.
* <p/>
* Note: this does not return the callback annotations directly, because
* those may not contain the method's name (as it defaults to the name of
* the annotated method).
* This does not return the callback annotations directly, because those
* may not contain the method's name (as it defaults to the name of the
* annotated method).
* <p/>
* The returned collection is read-only.
*/
Iterable<String> methods();
Collection<String> methods();
/**
* Get the annotation information of a method.

View File

@ -11,6 +11,7 @@ import li.cil.oc.api.machine.Value
import net.minecraft.item.ItemStack
import net.minecraft.world.World
import scala.collection.convert.WrapAsJava._
import scala.collection.convert.WrapAsScala._
import scala.collection.mutable
import scala.math.ScalaNumber
@ -76,6 +77,10 @@ private[oc] object Registry extends api.detail.DriverAPI {
if (stack != null) items.find(_.worksWith(stack)).orNull
else null
override def blockDrivers = blocks.toSeq
override def itemDrivers = items.toSeq
def convert(value: Array[AnyRef]) = if (value != null) value.map(arg => convertRecursively(arg, new util.IdentityHashMap())) else null
def convertRecursively(value: Any, memo: util.IdentityHashMap[AnyRef, AnyRef], force: Boolean = false): AnyRef = {

View File

@ -889,7 +889,7 @@ object Machine extends MachineAPI {
}
}
override def architectures = scala.collection.convert.WrapAsJava.asJavaIterable(checked)
override def architectures = checked.toSeq
override def create(host: MachineHost) = new Machine(host)