mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Some more cleanup.
This commit is contained in:
parent
8e6c97efcb
commit
cb2bec3227
@ -1,25 +1,25 @@
|
|||||||
package li.cil.oc.integration.computercraft
|
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 dan200.computercraft.api.media.IMedia
|
||||||
import li.cil.oc
|
import li.cil.oc
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api.driver.EnvironmentHost
|
import li.cil.oc.api.driver.EnvironmentHost
|
||||||
import li.cil.oc.api.fs.Label
|
import li.cil.oc.api.fs.Label
|
||||||
import li.cil.oc.common.Slot
|
import li.cil.oc.common.Slot
|
||||||
import li.cil.oc.integration.Mods
|
|
||||||
import li.cil.oc.integration.opencomputers.Item
|
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.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
|
||||||
object DriverComputerCraftMedia extends Item {
|
object DriverComputerCraftMedia extends Item {
|
||||||
override def worksWith(stack: ItemStack) =
|
override def worksWith(stack: ItemStack) = stack.getItem.isInstanceOf[IMedia]
|
||||||
Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack)
|
|
||||||
|
|
||||||
override def createEnvironment(stack: ItemStack, host: EnvironmentHost) =
|
override def createEnvironment(stack: ItemStack, host: EnvironmentHost) = {
|
||||||
if (Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack) && host != null) {
|
|
||||||
val address = addressFromTag(dataTag(stack))
|
val address = addressFromTag(dataTag(stack))
|
||||||
val mount = ComputerCraft.createDiskMount(stack, host.world)
|
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 {
|
Option(oc.api.FileSystem.asManagedEnvironment(mount, new ComputerCraftLabel(stack), host, Settings.resourceDomain + ":floppy_access")) match {
|
||||||
case Some(environment) =>
|
case Some(environment) =>
|
||||||
environment.node.asInstanceOf[oc.server.network.Node].address = address
|
environment.node.asInstanceOf[oc.server.network.Node].address = address
|
||||||
@ -27,10 +27,14 @@ object DriverComputerCraftMedia extends Item {
|
|||||||
case _ => null
|
case _ => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else null
|
|
||||||
|
|
||||||
override def slot(stack: ItemStack) = Slot.Floppy
|
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) =
|
private def addressFromTag(tag: NBTTagCompound) =
|
||||||
if (tag.hasKey("node") && tag.getCompoundTag("node").hasKey("address")) {
|
if (tag.hasKey("node") && tag.getCompoundTag("node").hasKey("address")) {
|
||||||
tag.getCompoundTag("node").getString("address")
|
tag.getCompoundTag("node").getString("address")
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ import li.cil.oc.api.driver.EnvironmentHost
|
|||||||
import li.cil.oc.api.fs.Label
|
import li.cil.oc.api.fs.Label
|
||||||
import li.cil.oc.api.fs.Mode
|
import li.cil.oc.api.fs.Mode
|
||||||
import li.cil.oc.integration.Mods
|
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 li.cil.oc.server.component
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
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 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) {
|
if (Mods.ComputerCraft.isAvailable) {
|
||||||
ComputerCraft.createFileSystem(mount).orNull
|
DriverComputerCraftMedia.createFileSystem(mount).orNull
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
}
|
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: EnvironmentHost, sound: String) =
|
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
|
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(host), Option(sound)))).orNull
|
||||||
|
Loading…
x
Reference in New Issue
Block a user