basic sound framework for disk activity and floppy sounds (thanks to asie for providing the samples!)

This commit is contained in:
Florian Nücke 2014-03-09 17:13:19 +01:00
parent f759a06ee3
commit dd41cb45a4
18 changed files with 173 additions and 62 deletions

View File

@ -6,6 +6,7 @@ import dan200.computer.api.IWritableMount;
import li.cil.oc.api.detail.FileSystemAPI;
import li.cil.oc.api.fs.Label;
import li.cil.oc.api.network.ManagedEnvironment;
import net.minecraft.tileentity.TileEntity;
/**
* This class provides factory methods for creating file systems that are
@ -46,7 +47,8 @@ public final class FileSystem {
* @return a file system wrapping the specified folder.
*/
public static li.cil.oc.api.fs.FileSystem fromClass(final Class<?> clazz, final String domain, final String root) {
if (instance != null) return instance.fromClass(clazz, domain, root);
if (instance != null)
return instance.fromClass(clazz, domain, root);
return null;
}
@ -74,7 +76,8 @@ public final class FileSystem {
* @return a file system wrapping the specified folder.
*/
public static li.cil.oc.api.fs.FileSystem fromSaveDirectory(final String root, final long capacity, final boolean buffered) {
if (instance != null) return instance.fromSaveDirectory(root, capacity, buffered);
if (instance != null)
return instance.fromSaveDirectory(root, capacity, buffered);
return null;
}
@ -103,7 +106,8 @@ public final class FileSystem {
* @return a file system residing in memory.
*/
public static li.cil.oc.api.fs.FileSystem fromMemory(final long capacity) {
if (instance != null) return instance.fromMemory(capacity);
if (instance != null)
return instance.fromMemory(capacity);
return null;
}
@ -115,7 +119,8 @@ public final class FileSystem {
*/
@Optional.Method(modid = "ComputerCraft")
public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final IMount mount) {
if (instance != null) return instance.fromComputerCraft(mount);
if (instance != null)
return instance.fromComputerCraft(mount);
return null;
}
@ -127,7 +132,8 @@ public final class FileSystem {
*/
@Optional.Method(modid = "ComputerCraft")
public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final IWritableMount mount) {
if (instance != null) return instance.fromComputerCraft(mount);
if (instance != null)
return instance.fromComputerCraft(mount);
return null;
}
@ -140,13 +146,36 @@ public final class FileSystem {
* more control over the node, implement your own, and connect this one to
* it. In that case you will have to forward any disk driver messages to the
* node, though.
* <p/>
* The container parameter is used to give the file system some physical
* relation to the world, for example this is used by hard drives to send
* the disk event notifications to the client that are used to play disk
* access sounds.
* <p/>
* The container may be <tt>null</tt>, if no such context can be provided.
*
* @param fileSystem the file system to wrap.
* @param label the label of the file system.
* @param container the tile entity containing the file system.
* @return the network node wrapping the file system.
*/
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label, final TileEntity container) {
if (instance != null)
return instance.asManagedEnvironment(fileSystem, label, container);
return null;
}
/**
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, TileEntity)},
* but does not provide a container.
*
* @param fileSystem the file system to wrap.
* @param label the label of the file system.
* @return the network node wrapping the file system.
*/
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label) {
if (instance != null) return instance.asManagedEnvironment(fileSystem, label);
if (instance != null)
return instance.asManagedEnvironment(fileSystem, label);
return null;
}
@ -159,7 +188,8 @@ public final class FileSystem {
* @return the network node wrapping the file system.
*/
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final String label) {
if (instance != null) return instance.asManagedEnvironment(fileSystem, label);
if (instance != null)
return instance.asManagedEnvironment(fileSystem, label);
return null;
}
@ -172,7 +202,8 @@ public final class FileSystem {
* @return the network node wrapping the file system.
*/
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem) {
if (instance != null) return instance.asManagedEnvironment(fileSystem);
if (instance != null)
return instance.asManagedEnvironment(fileSystem);
return null;
}

View File

@ -6,6 +6,7 @@ import dan200.computer.api.IWritableMount;
import li.cil.oc.api.fs.FileSystem;
import li.cil.oc.api.fs.Label;
import li.cil.oc.api.network.ManagedEnvironment;
import net.minecraft.tileentity.TileEntity;
public interface FileSystemAPI {
/**
@ -96,6 +97,24 @@ public interface FileSystemAPI {
* more control over the node, implement your own, and connect this one to
* it. In that case you will have to forward any disk driver messages to the
* node, though.
* <p/>
* The container parameter is used to give the file system some physical
* relation to the world, for example this is used by hard drives to send
* the disk event notifications to the client that are used to play disk
* access sounds.
* <p/>
* The container may be <tt>null</tt>, if no such context can be provided.
*
* @param fileSystem the file system to wrap.
* @param label the label of the file system.
* @param container the tile entity containing the file system.
* @return the network node wrapping the file system.
*/
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, TileEntity container);
/**
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, TileEntity)},
* but does not provide a container.
*
* @param fileSystem the file system to wrap.
* @param label the label of the file system.

View File

@ -1,7 +1,7 @@
package li.cil.oc.client
import cpw.mods.fml.client.registry.{RenderingRegistry, ClientRegistry}
import cpw.mods.fml.common.event.{FMLPostInitializationEvent, FMLInitializationEvent}
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLPostInitializationEvent, FMLInitializationEvent}
import cpw.mods.fml.common.network.NetworkRegistry
import cpw.mods.fml.common.registry.TickRegistry
import cpw.mods.fml.relauncher.Side
@ -9,8 +9,7 @@ import li.cil.oc.client.renderer.WirelessNetworkDebugRenderer
import li.cil.oc.client.renderer.block.BlockRenderer
import li.cil.oc.client.renderer.item.UpgradeRenderer
import li.cil.oc.client.renderer.tileentity._
import li.cil.oc.common.tileentity
import li.cil.oc.common.{Proxy => CommonProxy}
import li.cil.oc.common.{Proxy => CommonProxy, Sound, tileentity}
import li.cil.oc.{Items, Settings, OpenComputers}
import net.minecraft.client.Minecraft
import net.minecraft.client.resources.ReloadableResourceManager
@ -18,6 +17,12 @@ import net.minecraftforge.client.MinecraftForgeClient
import net.minecraftforge.common.MinecraftForge
private[oc] class Proxy extends CommonProxy {
override def preInit(e: FMLPreInitializationEvent) {
super.preInit(e)
MinecraftForge.EVENT_BUS.register(Sound)
}
override def init(e: FMLInitializationEvent) = {
super.init(e)

View File

@ -5,11 +5,11 @@ import cpw.mods.fml.common.network.PacketDispatcher
import cpw.mods.fml.common.network.Player
import java.io.{OutputStream, ByteArrayOutputStream, DataOutputStream}
import java.util.zip.GZIPOutputStream
import li.cil.oc.common.tileentity.TileEntity
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.item.ItemStack
import net.minecraft.nbt.{CompressedStreamTools, NBTTagCompound}
import net.minecraft.network.packet.Packet250CustomPayload
import net.minecraft.tileentity.TileEntity
import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection
import scala.collection.convert.WrapAsScala._
@ -17,10 +17,10 @@ import scala.collection.convert.WrapAsScala._
// Necessary to keep track of the GZIP stream.
abstract class PacketBuilderBase[T <: OutputStream](protected val stream: T) extends DataOutputStream(stream) {
def writeTileEntity(t: TileEntity) = {
writeInt(t.world.provider.dimensionId)
writeInt(t.x)
writeInt(t.y)
writeInt(t.z)
writeInt(t.getWorldObj.provider.dimensionId)
writeInt(t.xCoord)
writeInt(t.yCoord)
writeInt(t.zCoord)
}
def writeDirection(d: ForgeDirection) = writeInt(d.ordinal)
@ -37,7 +37,7 @@ abstract class PacketBuilderBase[T <: OutputStream](protected val stream: T) ext
def sendToAllPlayers() = PacketDispatcher.sendPacketToAllPlayers(packet)
def sendToNearbyPlayers(t: TileEntity, range: Double = 1024): Unit = sendToNearbyPlayers(t.world, t.x + 0.5, t.y + 0.5, t.z + 0.5, range)
def sendToNearbyPlayers(t: TileEntity, range: Double = 1024): Unit = sendToNearbyPlayers(t.getWorldObj, t.xCoord + 0.5, t.yCoord + 0.5, t.zCoord + 0.5, range)
def sendToNearbyPlayers(world: World, x: Double, y: Double, z: Double, range: Double) {
val dimension = world.provider.dimensionId

View File

@ -0,0 +1,41 @@
package li.cil.oc.common
import li.cil.oc.Settings
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.client.event.sound.SoundLoadEvent
import net.minecraftforge.event.ForgeSubscribe
import cpw.mods.fml.relauncher.{Side, SideOnly}
object Sound {
@SideOnly(Side.CLIENT)
@ForgeSubscribe
def onSoundLoad(event: SoundLoadEvent) {
for (i <- 1 to 6) {
event.manager.soundPoolSounds.addSound(Settings.resourceDomain + s":floppy_access$i.ogg")
}
event.manager.soundPoolSounds.addSound(Settings.resourceDomain + ":floppy_insert.ogg")
event.manager.soundPoolSounds.addSound(Settings.resourceDomain + ":floppy_eject.ogg")
}
def play(t: tileentity.TileEntity, name: String) {
t.world.playSoundEffect(t.x + 0.5, t.y + 0.5, t.z + 0.5, Settings.resourceDomain + ":" + name, 1, 1)
}
def playDiskInsert(t: tileentity.DiskDrive) {
play(t, "floppy_insert")
}
def playDiskEject(t: tileentity.DiskDrive) {
play(t, "floppy_eject")
}
def playDiskActivity(t: TileEntity) = this.synchronized {
t match {
case computer: tileentity.Computer => play(computer, "hdd_access")
case rack: tileentity.Rack => play(rack, "hdd_access")
case drive: tileentity.DiskDrive => play(drive, "floppy_access")
case _ => // Huh?
}
}
}

View File

@ -2,8 +2,9 @@ package li.cil.oc.common.tileentity
import li.cil.oc.api.driver.Slot
import li.cil.oc.api.network.{Analyzable, Component, Visibility}
import li.cil.oc.server.TickHandler
import li.cil.oc.common.Sound
import li.cil.oc.server.driver.Registry
import li.cil.oc.server.TickHandler
import li.cil.oc.{api, Settings}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
@ -45,5 +46,11 @@ class DiskDrive extends Environment with ComponentInventory with Rotatable with
}
case _ =>
}
Sound.playDiskInsert(this)
}
override protected def onItemRemoved(slot: Int, stack: ItemStack) {
super.onItemRemoved(slot, stack)
Sound.playDiskEject(this)
}
}

View File

@ -1,7 +1,7 @@
package li.cil.oc.server
import li.cil.oc.common
import li.cil.oc.common.tileentity._
import li.cil.oc.common.tileentity
import li.cil.oc.common.{CompressedPacketBuilder, PacketBuilder, PacketType}
import li.cil.oc.util.PackedColor
import net.minecraft.entity.player.EntityPlayerMP
@ -9,7 +9,7 @@ import net.minecraft.item.ItemStack
import net.minecraftforge.common.ForgeDirection
object PacketSender {
def sendAbstractBusState(t: AbstractBusAware) {
def sendAbstractBusState(t: tileentity.AbstractBusAware) {
val pb = new PacketBuilder(PacketType.AbstractBusState)
pb.writeTileEntity(t)
@ -26,7 +26,7 @@ object PacketSender {
pb.sendToPlayer(player)
}
def sendChargerState(t: Charger) {
def sendChargerState(t: tileentity.Charger) {
val pb = new PacketBuilder(PacketType.ChargerState)
pb.writeTileEntity(t)
@ -35,7 +35,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendComputerState(t: Computer) {
def sendComputerState(t: tileentity.Computer) {
val pb = new PacketBuilder(PacketType.ComputerState)
pb.writeTileEntity(t)
@ -44,7 +44,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendComputerUserList(t: Computer, list: Array[String]) {
def sendComputerUserList(t: tileentity.Computer, list: Array[String]) {
val pb = new PacketBuilder(PacketType.ComputerUserList)
pb.writeTileEntity(t)
@ -54,7 +54,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendHologramClear(t: Hologram) {
def sendHologramClear(t: tileentity.Hologram) {
val pb = new PacketBuilder(PacketType.HologramClear)
pb.writeTileEntity(t)
@ -62,7 +62,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendHologramPowerChange(t: Hologram) {
def sendHologramPowerChange(t: tileentity.Hologram) {
val pb = new PacketBuilder(PacketType.HologramPowerChange)
pb.writeTileEntity(t)
@ -71,7 +71,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendHologramScale(t: Hologram) {
def sendHologramScale(t: tileentity.Hologram) {
val pb = new PacketBuilder(PacketType.HologramScale)
pb.writeTileEntity(t)
@ -80,7 +80,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendHologramSet(t: Hologram) {
def sendHologramSet(t: tileentity.Hologram) {
val pb = new CompressedPacketBuilder(PacketType.HologramSet)
pb.writeTileEntity(t)
@ -97,7 +97,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendPowerState(t: PowerInformation) {
def sendPowerState(t: tileentity.PowerInformation) {
val pb = new PacketBuilder(PacketType.PowerState)
pb.writeTileEntity(t)
@ -107,7 +107,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendRedstoneState(t: RedstoneAware) {
def sendRedstoneState(t: tileentity.RedstoneAware) {
val pb = new PacketBuilder(PacketType.RedstoneState)
pb.writeTileEntity(t)
@ -119,7 +119,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendRobotMove(t: Robot, ox: Int, oy: Int, oz: Int, direction: ForgeDirection) {
def sendRobotMove(t: tileentity.Robot, ox: Int, oy: Int, oz: Int, direction: ForgeDirection) {
val pb = new PacketBuilder(PacketType.RobotMove)
// Custom pb.writeTileEntity() with fake coordinates (valid for the client).
@ -132,7 +132,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendRobotAnimateSwing(t: Robot) {
def sendRobotAnimateSwing(t: tileentity.Robot) {
val pb = new PacketBuilder(PacketType.RobotAnimateSwing)
pb.writeTileEntity(t.proxy)
@ -141,7 +141,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t, 64)
}
def sendRobotAnimateTurn(t: Robot) {
def sendRobotAnimateTurn(t: tileentity.Robot) {
val pb = new PacketBuilder(PacketType.RobotAnimateTurn)
pb.writeTileEntity(t.proxy)
@ -151,7 +151,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t, 64)
}
def sendRobotEquippedItemChange(t: Robot, stack: ItemStack) {
def sendRobotEquippedItemChange(t: tileentity.Robot, stack: ItemStack) {
val pb = new PacketBuilder(PacketType.RobotEquippedItemChange)
pb.writeTileEntity(t.proxy)
@ -160,7 +160,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendRobotEquippedUpgradeChange(t: Robot, stack: ItemStack) {
def sendRobotEquippedUpgradeChange(t: tileentity.Robot, stack: ItemStack) {
val pb = new PacketBuilder(PacketType.RobotEquippedUpgradeChange)
pb.writeTileEntity(t.proxy)
@ -169,7 +169,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendRobotSelectedSlotChange(t: Robot) {
def sendRobotSelectedSlotChange(t: tileentity.Robot) {
val pb = new PacketBuilder(PacketType.RobotSelectedSlotChange)
pb.writeTileEntity(t.proxy)
@ -178,7 +178,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t, 16)
}
def sendRobotXp(t: Robot) {
def sendRobotXp(t: tileentity.Robot) {
val pb = new PacketBuilder(PacketType.RobotXp)
pb.writeTileEntity(t)
@ -187,7 +187,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendRotatableState(t: Rotatable) {
def sendRotatableState(t: tileentity.Rotatable) {
val pb = new PacketBuilder(PacketType.RotatableState)
pb.writeTileEntity(t)
@ -201,7 +201,7 @@ object PacketSender {
val pb = new PacketBuilder(PacketType.ScreenColorChange)
val t = b.owner match {
case t: Buffer =>
case t: tileentity.Buffer =>
pb.writeTileEntity(t)
t
case t: common.component.Terminal =>
@ -220,7 +220,7 @@ object PacketSender {
val pb = new PacketBuilder(PacketType.ScreenCopy)
val t = b.owner match {
case t: Buffer =>
case t: tileentity.Buffer =>
pb.writeTileEntity(t)
t
case t: common.component.Terminal =>
@ -243,7 +243,7 @@ object PacketSender {
val pb = new PacketBuilder(PacketType.ScreenDepthChange)
val t = b.owner match {
case t: Buffer =>
case t: tileentity.Buffer =>
pb.writeTileEntity(t)
t
case t: common.component.Terminal =>
@ -261,7 +261,7 @@ object PacketSender {
val pb = new PacketBuilder(PacketType.ScreenFill)
val t = b.owner match {
case t: Buffer =>
case t: tileentity.Buffer =>
pb.writeTileEntity(t)
t
case t: common.component.Terminal =>
@ -279,7 +279,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendScreenPowerChange(t: Buffer, hasPower: Boolean) {
def sendScreenPowerChange(t: tileentity.Buffer, hasPower: Boolean) {
val pb = new PacketBuilder(PacketType.ScreenPowerChange)
pb.writeTileEntity(t)
@ -292,7 +292,7 @@ object PacketSender {
val pb = new PacketBuilder(PacketType.ScreenResolutionChange)
val t = b.owner match {
case t: Buffer =>
case t: tileentity.Buffer =>
pb.writeTileEntity(t)
t
case t: common.component.Terminal =>
@ -311,7 +311,7 @@ object PacketSender {
val pb = new PacketBuilder(PacketType.ScreenSet)
val t = b.owner match {
case t: Buffer =>
case t: tileentity.Buffer =>
pb.writeTileEntity(t)
t
case t: common.component.Terminal =>
@ -327,7 +327,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendServerPresence(t: Rack) {
def sendServerPresence(t: tileentity.Rack) {
val pb = new PacketBuilder(PacketType.ServerPresence)
pb.writeTileEntity(t)
@ -342,7 +342,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendServerState(t: Rack) {
def sendServerState(t: tileentity.Rack) {
val pb = new PacketBuilder(PacketType.ComputerState)
pb.writeTileEntity(t)
@ -352,7 +352,7 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendServerState(t: Rack, number: Int, player: Option[EntityPlayerMP] = None) {
def sendServerState(t: tileentity.Rack, number: Int, player: Option[EntityPlayerMP] = None) {
val pb = new PacketBuilder(PacketType.ComputerState)
pb.writeTileEntity(t)

View File

@ -1,15 +1,17 @@
package li.cil.oc.server.component
import java.io.{FileNotFoundException, IOException}
import li.cil.oc.Settings
import li.cil.oc.api.Network
import li.cil.oc.api.fs.{Label, Mode, FileSystem => IFileSystem}
import li.cil.oc.api.Network
import li.cil.oc.api.network._
import li.cil.oc.common.Sound
import li.cil.oc.Settings
import li.cil.oc.util.ExtendedNBT._
import net.minecraft.nbt.{NBTTagInt, NBTTagList, NBTTagCompound}
import net.minecraft.tileentity.TileEntity
import scala.collection.mutable
class FileSystem(val fileSystem: IFileSystem, var label: Label) extends ManagedComponent {
class FileSystem(val fileSystem: IFileSystem, var label: Label, val container: Option[TileEntity] = None) extends ManagedComponent {
val node = Network.newNode(this, Visibility.Network).
withComponent("filesystem", Visibility.Neighbors).
withConnector().
@ -148,6 +150,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label) extends ManagedC
if (!node.tryChangeBuffer(-Settings.get.hddReadCost * bytes.length)) {
throw new IOException("not enough energy")
}
container.foreach(Sound.playDiskActivity)
result(bytes)
}
else {
@ -185,7 +188,10 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label) extends ManagedC
}
checkOwner(context.node.address, handle)
Option(fileSystem.getHandle(handle)) match {
case Some(file) => file.write(value); result(true)
case Some(file) =>
file.write(value)
container.foreach(Sound.playDiskActivity)
result(true)
case _ => throw new IOException("bad file descriptor")
}
}

View File

@ -9,12 +9,12 @@ import li.cil.oc.util.mods.ComputerCraft
import li.cil.oc.{Settings, Items}
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.{TileEntity => MCTileEntity}
import net.minecraft.tileentity.TileEntity
object FileSystem extends Item {
override def worksWith(stack: ItemStack) = isOneOf(stack, Items.hdd1, Items.hdd2, Items.hdd3, Items.floppyDisk) || ComputerCraft.isDisk(stack)
override def createEnvironment(stack: ItemStack, container: MCTileEntity) =
override def createEnvironment(stack: ItemStack, container: TileEntity) =
if (ComputerCraft.isDisk(stack) && container != null) {
val address = addressFromTag(dataTag(stack))
val mount = ComputerCraft.createDiskMount(stack, container.getWorldObj)
@ -25,8 +25,8 @@ object FileSystem extends Item {
case _ => null
}
} else Items.multi.subItem(stack) match {
case Some(hdd: HardDiskDrive) => createEnvironment(stack, hdd.kiloBytes * 1024)
case Some(disk: FloppyDisk) => createEnvironment(stack, Settings.get.floppySize * 1024)
case Some(hdd: HardDiskDrive) => createEnvironment(stack, hdd.kiloBytes * 1024, container)
case Some(disk: FloppyDisk) => createEnvironment(stack, Settings.get.floppySize * 1024, container)
case _ => null
}
@ -44,18 +44,17 @@ object FileSystem extends Item {
case _ => 0
}
private def createEnvironment(stack: ItemStack, capacity: Int) = {
private def createEnvironment(stack: ItemStack, capacity: Int, container: TileEntity) = {
// We have a bit of a chicken-egg problem here, because we want to use the
// node's address as the folder name... so we generate the address here,
// if necessary. No one will know, right? Right!?
val address = addressFromTag(dataTag(stack))
Option(oc.api.FileSystem.asManagedEnvironment(oc.api.FileSystem.
fromSaveDirectory(address, capacity, Settings.get.bufferChanges), new ItemLabel(stack))) match {
case Some(environment) =>
environment.node.asInstanceOf[oc.server.network.Node].address = address
environment
case _ => null
val fs = oc.api.FileSystem.fromSaveDirectory(address, capacity, Settings.get.bufferChanges)
val environment = oc.api.FileSystem.asManagedEnvironment(fs, new ItemLabel(stack), container)
if (environment != null) {
environment.node.asInstanceOf[oc.server.network.Node].address = address
}
environment
}
private def addressFromTag(tag: NBTTagCompound) =

View File

@ -72,6 +72,9 @@ object FileSystem extends api.detail.FileSystemAPI {
@Optional.Method(modid = "ComputerCraft")
def fromComputerCraft(mount: IWritableMount) = new ComputerCraftWritableFileSystem(mount)
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, container: net.minecraft.tileentity.TileEntity) =
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(container)))).orNull
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label) =
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label))).orNull