diff --git a/src/main/java/li/cil/oc/api/FileSystem.java b/src/main/java/li/cil/oc/api/FileSystem.java index eed3333e2..8ee5d01fa 100644 --- a/src/main/java/li/cil/oc/api/FileSystem.java +++ b/src/main/java/li/cil/oc/api/FileSystem.java @@ -1,6 +1,5 @@ package li.cil.oc.api; -import cpw.mods.fml.common.Optional; import li.cil.oc.api.detail.FileSystemAPI; import li.cil.oc.api.driver.Container; import li.cil.oc.api.fs.Label; @@ -110,52 +109,18 @@ public final class FileSystem { } /** - * Creates a new file system based on a read-only ComputerCraft mount. + * Creates a new file system based on a ComputerCraft mount. + *

+ * This supports read-only and writable mounts from either CC 1.5x or + * CC 1.6x. The argument is kept untyped to avoid having the OC API + * depend on the CC API. + *

+ * If the passed type is unsupported, this will throw an exception. * * @param mount the mount to wrap with a file system. * @return a file system wrapping the specified mount. */ - @Optional.Method(modid = "ComputerCraft") - public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final dan200.computer.api.IMount mount) { - if (instance != null) - return instance.fromComputerCraft(mount); - return null; - } - - /** - * Creates a new file system based on a read-write ComputerCraft mount. - * - * @param mount the mount to wrap with a file system. - * @return a file system wrapping the specified mount. - */ - @Optional.Method(modid = "ComputerCraft") - public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final dan200.computer.api.IWritableMount mount) { - if (instance != null) - return instance.fromComputerCraft(mount); - return null; - } - - /** - * Creates a new file system based on a read-only ComputerCraft mount. - * - * @param mount the mount to wrap with a file system. - * @return a file system wrapping the specified mount. - */ - @Optional.Method(modid = "ComputerCraft") - public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final dan200.computercraft.api.filesystem.IMount mount) { - if (instance != null) - return instance.fromComputerCraft(mount); - return null; - } - - /** - * Creates a new file system based on a read-write ComputerCraft mount. - * - * @param mount the mount to wrap with a file system. - * @return a file system wrapping the specified mount. - */ - @Optional.Method(modid = "ComputerCraft") - public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final dan200.computercraft.api.filesystem.IWritableMount mount) { + public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final Object mount) { if (instance != null) return instance.fromComputerCraft(mount); return null; diff --git a/src/main/java/li/cil/oc/api/detail/FileSystemAPI.java b/src/main/java/li/cil/oc/api/detail/FileSystemAPI.java index 8c8b06b16..3768bf061 100644 --- a/src/main/java/li/cil/oc/api/detail/FileSystemAPI.java +++ b/src/main/java/li/cil/oc/api/detail/FileSystemAPI.java @@ -1,6 +1,5 @@ package li.cil.oc.api.detail; -import cpw.mods.fml.common.Optional; import li.cil.oc.api.driver.Container; import li.cil.oc.api.fs.FileSystem; import li.cil.oc.api.fs.Label; @@ -70,39 +69,17 @@ public interface FileSystemAPI { /** * Creates a new file system based on a read-only ComputerCraft mount. + *

+ * This supports read-only and writable mounts from either CC 1.5x or + * CC 1.6x. The argument is kept untyped to avoid having the OC API + * depend on the CC API. + *

+ * If the passed type is unsupported, this will return null. * * @param mount the mount to wrap with a file system. * @return a file system wrapping the specified mount. */ - @Optional.Method(modid = "ComputerCraft") - FileSystem fromComputerCraft(dan200.computer.api.IMount mount); - - /** - * Creates a new file system based on a read-write ComputerCraft mount. - * - * @param mount the mount to wrap with a file system. - * @return a file system wrapping the specified mount. - */ - @Optional.Method(modid = "ComputerCraft") - FileSystem fromComputerCraft(dan200.computer.api.IWritableMount mount); - - /** - * Creates a new file system based on a read-only ComputerCraft mount. - * - * @param mount the mount to wrap with a file system. - * @return a file system wrapping the specified mount. - */ - @Optional.Method(modid = "ComputerCraft") - FileSystem fromComputerCraft(dan200.computercraft.api.filesystem.IMount mount); - - /** - * Creates a new file system based on a read-write ComputerCraft mount. - * - * @param mount the mount to wrap with a file system. - * @return a file system wrapping the specified mount. - */ - @Optional.Method(modid = "ComputerCraft") - FileSystem fromComputerCraft(dan200.computercraft.api.filesystem.IWritableMount mount); + FileSystem fromComputerCraft(Object mount); /** * Creates a network node that makes the specified file system available via diff --git a/src/main/scala/li/cil/oc/common/Proxy.scala b/src/main/scala/li/cil/oc/common/Proxy.scala index 7551f4db4..17ad2e66f 100644 --- a/src/main/scala/li/cil/oc/common/Proxy.scala +++ b/src/main/scala/li/cil/oc/common/Proxy.scala @@ -57,7 +57,6 @@ class Proxy { } def init(e: FMLInitializationEvent) { - api.Driver.add(driver.item.AbstractBusCard) api.Driver.add(driver.item.FileSystem) api.Driver.add(driver.item.GraphicsCard) api.Driver.add(driver.item.InternetCard) @@ -85,6 +84,9 @@ class Proxy { api.Driver.add(driver.item.UpgradeAngel) api.Driver.add(driver.item.WirelessNetworkCard) + if (Mods.StargateTech2.isAvailable) { + api.Driver.add(driver.item.AbstractBusCard) + } if (Mods.ComputerCraft15.isAvailable) { api.Driver.add(driver.item.CC15Media) } diff --git a/src/main/scala/li/cil/oc/server/driver/item/Item.scala b/src/main/scala/li/cil/oc/server/driver/item/Item.scala index 6dd959799..2d5f7b0ed 100644 --- a/src/main/scala/li/cil/oc/server/driver/item/Item.scala +++ b/src/main/scala/li/cil/oc/server/driver/item/Item.scala @@ -12,7 +12,7 @@ trait Item extends driver.Item { override def dataTag(stack: ItemStack) = Item.dataTag(stack) - protected def isOneOf(stack: ItemStack, items: api.detail.ItemInfo*) = items.contains(api.Items.get(stack)) + protected def isOneOf(stack: ItemStack, items: api.detail.ItemInfo*) = items.filter(_ != null).contains(api.Items.get(stack)) } object Item { diff --git a/src/main/scala/li/cil/oc/server/fs/FileSystem.scala b/src/main/scala/li/cil/oc/server/fs/FileSystem.scala index a7dd84483..e3d6c546b 100644 --- a/src/main/scala/li/cil/oc/server/fs/FileSystem.scala +++ b/src/main/scala/li/cil/oc/server/fs/FileSystem.scala @@ -9,6 +9,7 @@ import li.cil.oc.server.component import li.cil.oc.{Settings, api} import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.common.DimensionManager +import li.cil.oc.util.mods.{ComputerCraft15, ComputerCraft16, Mods} object FileSystem extends api.detail.FileSystemAPI { override def fromClass(clazz: Class[_], domain: String, root: String): api.fs.FileSystem = { @@ -66,17 +67,16 @@ object FileSystem extends api.detail.FileSystemAPI { def fromMemory(capacity: Long): api.fs.FileSystem = new RamFileSystem(capacity) - @Optional.Method(modid = "ComputerCraft") - def fromComputerCraft(mount: dan200.computer.api.IMount) = new CC15FileSystem(mount) - - @Optional.Method(modid = "ComputerCraft") - def fromComputerCraft(mount: dan200.computer.api.IWritableMount) = new CC15WritableFileSystem(mount) - - @Optional.Method(modid = "ComputerCraft") - def fromComputerCraft(mount: dan200.computercraft.api.filesystem.IMount) = new CC16FileSystem(mount) - - @Optional.Method(modid = "ComputerCraft") - def fromComputerCraft(mount: dan200.computercraft.api.filesystem.IWritableMount) = new CC16WritableFileSystem(mount) + def fromComputerCraft(mount: AnyRef): api.fs.FileSystem = { + var result: Option[api.fs.FileSystem] = None + if (result.isEmpty && Mods.ComputerCraft16.isAvailable) { + result = ComputerCraft16.createFileSystem(mount) + } + if (result.isEmpty && Mods.ComputerCraft15.isAvailable) { + result = ComputerCraft15.createFileSystem(mount) + } + result.orNull + } def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, container: Container) = Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(container)))).orNull diff --git a/src/main/scala/li/cil/oc/util/mods/ComputerCraft15.scala b/src/main/scala/li/cil/oc/util/mods/ComputerCraft15.scala index dbf596ac2..a409ffc2b 100644 --- a/src/main/scala/li/cil/oc/util/mods/ComputerCraft15.scala +++ b/src/main/scala/li/cil/oc/util/mods/ComputerCraft15.scala @@ -2,17 +2,18 @@ package li.cil.oc.util.mods import dan200.computer.api.{IMount, IWritableMount, IMedia} import li.cil.oc +import li.cil.oc.server.fs.{CC15FileSystem, CC15WritableFileSystem} import net.minecraft.item.ItemStack import net.minecraft.world.World object ComputerCraft15 { def isDisk(stack: ItemStack) = stack.getItem.isInstanceOf[IMedia] - def createDiskMount(stack: ItemStack, world: World) = if (isDisk(stack)) { - stack.getItem.asInstanceOf[IMedia].createDataMount(stack, world) match { - case mount: IWritableMount => oc.api.FileSystem.fromComputerCraft(mount) - case mount: IMount => oc.api.FileSystem.fromComputerCraft(mount) - case _ => null - } - } else null + def createDiskMount(stack: ItemStack, world: World) = + if (isDisk(stack)) oc.api.FileSystem.fromComputerCraft(stack.getItem.asInstanceOf[IMedia].createDataMount(stack, world)) else null + + def createFileSystem(mount: AnyRef) = Option(mount) collect { + case rw: IWritableMount => new CC15WritableFileSystem(rw) + case ro: IMount => new CC15FileSystem(ro) + } } diff --git a/src/main/scala/li/cil/oc/util/mods/ComputerCraft16.scala b/src/main/scala/li/cil/oc/util/mods/ComputerCraft16.scala index b720b6119..ce8a62dc2 100644 --- a/src/main/scala/li/cil/oc/util/mods/ComputerCraft16.scala +++ b/src/main/scala/li/cil/oc/util/mods/ComputerCraft16.scala @@ -2,13 +2,14 @@ package li.cil.oc.util.mods import dan200.computercraft.api.ComputerCraftAPI import dan200.computercraft.api.filesystem.{IMount, IWritableMount} +import dan200.computercraft.api.lua.ILuaContext import dan200.computercraft.api.media.IMedia import dan200.computercraft.api.peripheral.{IComputerAccess, IPeripheral, IPeripheralProvider} import li.cil.oc import li.cil.oc.common.tileentity.{ComputerWrapper, Router} +import li.cil.oc.server.fs.{CC16FileSystem, CC16WritableFileSystem} import net.minecraft.item.ItemStack import net.minecraft.world.World -import dan200.computercraft.api.lua.ILuaContext import scala.collection.mutable object ComputerCraft16 { @@ -23,13 +24,13 @@ object ComputerCraft16 { def isDisk(stack: ItemStack) = stack.getItem.isInstanceOf[IMedia] - def createDiskMount(stack: ItemStack, world: World) = if (isDisk(stack)) { - stack.getItem.asInstanceOf[IMedia].createDataMount(stack, world) match { - case mount: IWritableMount => oc.api.FileSystem.fromComputerCraft(mount) - case mount: IMount => oc.api.FileSystem.fromComputerCraft(mount) - case _ => null - } - } else null + def createDiskMount(stack: ItemStack, world: World) = + if (isDisk(stack)) oc.api.FileSystem.fromComputerCraft(stack.getItem.asInstanceOf[IMedia].createDataMount(stack, world)) else null + + def createFileSystem(mount: AnyRef) = Option(mount) collect { + case rw: IWritableMount => new CC16WritableFileSystem(rw) + case ro: IMount => new CC16FileSystem(ro) + } class RouterPeripheral(val router: Router) extends IPeripheral { override def getType = router.getType