diff --git a/src/main/java/li/cil/oc/api/Driver.java b/src/main/java/li/cil/oc/api/Driver.java
index 760242449..0c446073a 100644
--- a/src/main/java/li/cil/oc/api/Driver.java
+++ b/src/main/java/li/cil/oc/api/Driver.java
@@ -16,6 +16,7 @@ import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import java.util.Collection;
+import java.util.Set;
/**
* This API allows registering new drivers with the mod.
@@ -217,13 +218,31 @@ public final class Driver {
*
* @param stack the item stack to get the environment type for.
* @return the type of environment associated with the stack, or null.
+ * @deprecated Use {@link #environmentsFor(ItemStack)} instead.
*/
+ @Deprecated
public static Class> environmentFor(ItemStack stack) {
if (API.driver != null)
return API.driver.environmentFor(stack);
return null;
}
+ /**
+ * Looks up the environments associated with the specified item stack.
+ *
+ * This will use the registered {@link EnvironmentProvider}s to find
+ * environment types for the specified item stack. If none can be
+ * found, returns an empty Set.
+ *
+ * @param stack the item stack to get the environment type for.
+ * @return the type of environment associated with the stack, or an empty Set, or null if the API is not present.
+ */
+ public static Set> environmentsFor(ItemStack stack) {
+ if (API.driver != null)
+ return API.driver.environmentsFor(stack);
+ return null;
+ }
+
/**
* @deprecated Use {@link #itemHandlerFor(ItemStack, EntityPlayer)} instead.
*/
diff --git a/src/main/java/li/cil/oc/api/detail/DriverAPI.java b/src/main/java/li/cil/oc/api/detail/DriverAPI.java
index d16313577..ad2fcd0fa 100644
--- a/src/main/java/li/cil/oc/api/detail/DriverAPI.java
+++ b/src/main/java/li/cil/oc/api/detail/DriverAPI.java
@@ -16,6 +16,7 @@ import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import java.util.Collection;
+import java.util.Set;
public interface DriverAPI {
/**
@@ -167,9 +168,23 @@ public interface DriverAPI {
*
* @param stack the item stack to get the environment type for.
* @return the type of environment associated with the stack, or null.
+ * @deprecated Use {@link #environmentsFor(ItemStack)} instead.
*/
+ @Deprecated
Class> environmentFor(ItemStack stack);
+ /**
+ * Looks up the environments associated with the specified item stack.
+ *
+ * This will use the registered {@link EnvironmentProvider}s to find
+ * environment types for the specified item stack. If none can be
+ * found, returns an empty Set.
+ *
+ * @param stack the item stack to get the environment type for.
+ * @return the type of environment associated with the stack, or an empty Set.
+ */
+ Set> environmentsFor(ItemStack stack);
+
/**
* @deprecated Use {@link #itemHandlerFor(ItemStack, EntityPlayer)} instead.
*/
diff --git a/src/main/scala/li/cil/oc/integration/nei/CallbackDocHandler.scala b/src/main/scala/li/cil/oc/integration/nei/CallbackDocHandler.scala
index 34dd0cb49..dccdd83ee 100644
--- a/src/main/scala/li/cil/oc/integration/nei/CallbackDocHandler.scala
+++ b/src/main/scala/li/cil/oc/integration/nei/CallbackDocHandler.scala
@@ -26,7 +26,7 @@ class CallbackDocHandler(pages: Option[Array[String]]) extends PagedUsageHandler
if (input == "item") {
ingredients.collect {
case stack: ItemStack if stack.getItem != null =>
- val callbacks = getCallbacks(api.Driver.environmentFor(stack)).toBuffer
+ val callbacks = api.Driver.environmentsFor(stack).flatMap(getCallbacks).toBuffer
// TODO remove in OC 1.7
if (callbacks.isEmpty) {
diff --git a/src/main/scala/li/cil/oc/server/driver/Registry.scala b/src/main/scala/li/cil/oc/server/driver/Registry.scala
index 751fd4621..8d7b64752 100644
--- a/src/main/scala/li/cil/oc/server/driver/Registry.scala
+++ b/src/main/scala/li/cil/oc/server/driver/Registry.scala
@@ -140,12 +140,15 @@ private[oc] object Registry extends api.detail.DriverAPI {
if (stack != null) items.find(_.worksWith(stack)).orNull
else null
+ @Deprecated
override def environmentFor(stack: ItemStack): Class[_] = {
environmentProviders.map(provider => provider.getEnvironment(stack)).collectFirst {
case clazz: Class[_] => clazz
}.orNull
}
+ override def environmentsFor(stack: ItemStack): util.Set[Class[_]] = environmentProviders.map(_.getEnvironment(stack)).filter(_ != null).toSet[Class[_]]
+
@Deprecated
override def inventoryFor(stack: ItemStack, player: EntityPlayer):IInventory = {
OpenComputers.log.warn("A mod is using the deprecated method li.cil.oc.api.Driver.inventoryFor; use itemHandlerFor instead.")