From cb2bec3227490250378b5ca7efbb803d4795f1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 13 Oct 2014 16:51:58 +0200 Subject: [PATCH] Some more cleanup. --- .../DriverComputerCraftMedia.scala | 34 +++++++++++-------- .../oc/integration/util/ComputerCraft.scala | 22 ------------ .../li/cil/oc/server/fs/FileSystem.scala | 7 ++-- 3 files changed, 22 insertions(+), 41 deletions(-) delete mode 100644 src/main/scala/li/cil/oc/integration/util/ComputerCraft.scala diff --git a/src/main/scala/li/cil/oc/integration/computercraft/DriverComputerCraftMedia.scala b/src/main/scala/li/cil/oc/integration/computercraft/DriverComputerCraftMedia.scala index 6d3fe7ab1..67d83f529 100644 --- a/src/main/scala/li/cil/oc/integration/computercraft/DriverComputerCraftMedia.scala +++ b/src/main/scala/li/cil/oc/integration/computercraft/DriverComputerCraftMedia.scala @@ -1,36 +1,40 @@ package li.cil.oc.integration.computercraft +import dan200.computercraft.api.filesystem.IMount +import dan200.computercraft.api.filesystem.IWritableMount import dan200.computercraft.api.media.IMedia import li.cil.oc import li.cil.oc.Settings import li.cil.oc.api.driver.EnvironmentHost import li.cil.oc.api.fs.Label import li.cil.oc.common.Slot -import li.cil.oc.integration.Mods import li.cil.oc.integration.opencomputers.Item -import li.cil.oc.integration.util.ComputerCraft +import li.cil.oc.server.fs.ComputerCraftFileSystem +import li.cil.oc.server.fs.ComputerCraftWritableFileSystem import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound object DriverComputerCraftMedia extends Item { - override def worksWith(stack: ItemStack) = - Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack) + override def worksWith(stack: ItemStack) = stack.getItem.isInstanceOf[IMedia] - override def createEnvironment(stack: ItemStack, host: EnvironmentHost) = - if (Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack) && host != null) { - val address = addressFromTag(dataTag(stack)) - val mount = ComputerCraft.createDiskMount(stack, host.world) - Option(oc.api.FileSystem.asManagedEnvironment(mount, new ComputerCraftLabel(stack), host, Settings.resourceDomain + ":floppy_access")) match { - case Some(environment) => - environment.node.asInstanceOf[oc.server.network.Node].address = address - environment - case _ => null - } + override def createEnvironment(stack: ItemStack, host: EnvironmentHost) = { + val address = addressFromTag(dataTag(stack)) + val mount = oc.api.FileSystem.fromComputerCraft(stack.getItem.asInstanceOf[IMedia].createDataMount(stack, host.world)) + Option(oc.api.FileSystem.asManagedEnvironment(mount, new ComputerCraftLabel(stack), host, Settings.resourceDomain + ":floppy_access")) match { + case Some(environment) => + environment.node.asInstanceOf[oc.server.network.Node].address = address + environment + case _ => null } - else null + } override def slot(stack: ItemStack) = Slot.Floppy + def createFileSystem(mount: AnyRef) = Option(mount) collect { + case rw: IWritableMount => new ComputerCraftWritableFileSystem(rw) + case ro: IMount => new ComputerCraftFileSystem(ro) + } + private def addressFromTag(tag: NBTTagCompound) = if (tag.hasKey("node") && tag.getCompoundTag("node").hasKey("address")) { tag.getCompoundTag("node").getString("address") diff --git a/src/main/scala/li/cil/oc/integration/util/ComputerCraft.scala b/src/main/scala/li/cil/oc/integration/util/ComputerCraft.scala deleted file mode 100644 index 34c98099e..000000000 --- a/src/main/scala/li/cil/oc/integration/util/ComputerCraft.scala +++ /dev/null @@ -1,22 +0,0 @@ -package li.cil.oc.integration.util - -import dan200.computercraft.api.filesystem.IMount -import dan200.computercraft.api.filesystem.IWritableMount -import dan200.computercraft.api.media.IMedia -import li.cil.oc -import li.cil.oc.server.fs.ComputerCraftFileSystem -import li.cil.oc.server.fs.ComputerCraftWritableFileSystem -import net.minecraft.item.ItemStack -import net.minecraft.world.World - -object ComputerCraft { - def isDisk(stack: ItemStack) = stack.getItem.isInstanceOf[IMedia] - - 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 ComputerCraftWritableFileSystem(rw) - case ro: IMount => new ComputerCraftFileSystem(ro) - } -} 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 6a3a34d0f..2c48b6bb2 100644 --- a/src/main/scala/li/cil/oc/server/fs/FileSystem.scala +++ b/src/main/scala/li/cil/oc/server/fs/FileSystem.scala @@ -11,7 +11,7 @@ import li.cil.oc.api.driver.EnvironmentHost import li.cil.oc.api.fs.Label import li.cil.oc.api.fs.Mode import li.cil.oc.integration.Mods -import li.cil.oc.integration.util.ComputerCraft +import li.cil.oc.integration.computercraft.DriverComputerCraftMedia import li.cil.oc.server.component import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound @@ -98,12 +98,11 @@ object FileSystem extends api.detail.FileSystemAPI { def fromMemory(capacity: Long): api.fs.FileSystem = new RamFileSystem(capacity) - def fromComputerCraft(mount: AnyRef): api.fs.FileSystem = { + def fromComputerCraft(mount: AnyRef): api.fs.FileSystem = if (Mods.ComputerCraft.isAvailable) { - ComputerCraft.createFileSystem(mount).orNull + DriverComputerCraftMedia.createFileSystem(mount).orNull } else null - } def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: EnvironmentHost, sound: String) = Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(host), Option(sound)))).orNull