mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-08-04 03:27:19 -04:00
Fixed a few compile errors.
This commit is contained in:
parent
4673a8048b
commit
1adb34ab3c
@ -1,5 +1,8 @@
|
||||
package li.cil.oc.api.fs;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
/**
|
||||
@ -14,7 +17,7 @@ import java.io.FileNotFoundException;
|
||||
* you call any of the functions of a file system directly it is your
|
||||
* responsibility to ensure the path has been cleaned up.
|
||||
*/
|
||||
public interface FileSystem extends Persistable {
|
||||
public interface FileSystem extends INBTSerializable<NBTTagCompound> {
|
||||
/**
|
||||
* Whether this file system is read-only.
|
||||
* <p/>
|
||||
|
@ -1,28 +0,0 @@
|
||||
package li.cil.oc.common.capabilities;
|
||||
|
||||
import li.cil.oc.api.network.NodeContainer;
|
||||
import li.cil.oc.api.tileentity.Colored;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
|
||||
// Gotta be Java, @CapabilityInject don't werk for Scala ;_;
|
||||
public final class Capabilities {
|
||||
@CapabilityInject(Colored.class)
|
||||
public static Capability<Colored> ColoredCapability;
|
||||
|
||||
@CapabilityInject(NodeContainer.class)
|
||||
public static Capability<NodeContainer> EnvironmentCapability;
|
||||
|
||||
@CapabilityInject(SidedEnvironment.class)
|
||||
public static Capability<SidedEnvironment> SidedEnvironmentCapability;
|
||||
|
||||
public static void init() {
|
||||
CapabilityManager.INSTANCE.register(NodeContainer.class, new CapabilityEnvironment.DefaultStorage(), CapabilityEnvironment.DefaultImpl.class);
|
||||
CapabilityManager.INSTANCE.register(SidedEnvironment.class, new CapabilitySidedEnvironment.DefaultStorage(), CapabilitySidedEnvironment.DefaultImpl.class);
|
||||
CapabilityManager.INSTANCE.register(Colored.class, new CapabilityColored.DefaultStorage(), CapabilityColored.DefaultImpl.class);
|
||||
}
|
||||
|
||||
private Capabilities() {
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ import net.minecraftforge.oredict.OreDictionary
|
||||
|
||||
trait InventoryAnalytics extends InventoryAware with NetworkAware {
|
||||
@Callback(doc = """function([slot:number]):table -- Get a description of the stack in the specified slot or the selected slot.""")
|
||||
def getStackInInternalSlot(context: Context, args: Arguments): Array[AnyRef] = if (Settings.get.allowItemStackInspection) {
|
||||
def getStackInInternalSlot(context: Context, args: Arguments): Array[AnyRef] = if (Settings.Misc.allowItemStackInspection) {
|
||||
val slot = optSlot(args, 0)
|
||||
result(inventory.getStackInSlot(slot))
|
||||
}
|
||||
|
@ -21,13 +21,13 @@ trait TankInventoryControl extends WorldAware with InventoryAware with TankAware
|
||||
withFluidInfo(optSlot(args, 0), (_, capacity) => result(capacity))
|
||||
|
||||
@Callback(doc = """function([slot:number]):table -- Get a description of the fluid in the tank item in the specified slot or the selected slot.""")
|
||||
def getFluidInTankInSlot(context: Context, args: Arguments): Array[AnyRef] = if (Settings.get.allowItemStackInspection) {
|
||||
def getFluidInTankInSlot(context: Context, args: Arguments): Array[AnyRef] = if (Settings.Misc.allowItemStackInspection) {
|
||||
withFluidInfo(optSlot(args, 0), (fluid, _) => result(fluid.orNull))
|
||||
}
|
||||
else result(Unit, "not enabled in config")
|
||||
|
||||
@Callback(doc = """function([tank:number]):table -- Get a description of the fluid in the tank in the specified slot or the selected slot.""")
|
||||
def getFluidInInternalTank(context: Context, args: Arguments): Array[AnyRef] = if (Settings.get.allowItemStackInspection) {
|
||||
def getFluidInInternalTank(context: Context, args: Arguments): Array[AnyRef] = if (Settings.Misc.allowItemStackInspection) {
|
||||
result(Option(tank.getFluidTank(optTank(args, 0))).map(_.getFluid).orNull)
|
||||
}
|
||||
else result(Unit, "not enabled in config")
|
||||
|
@ -70,7 +70,7 @@ trait WorldInventoryAnalytics extends WorldAware with SideRestricted with Networ
|
||||
}
|
||||
|
||||
@Callback(doc = """function(side:number, slot:number):table -- Get a description of the stack in the inventory on the specified side of the device.""")
|
||||
def getStackInSlot(context: Context, args: Arguments): Array[AnyRef] = if (Settings.get.allowItemStackInspection) {
|
||||
def getStackInSlot(context: Context, args: Arguments): Array[AnyRef] = if (Settings.Misc.allowItemStackInspection) {
|
||||
val facing = checkSideForAction(args, 0)
|
||||
withInventory(facing, inventory => result(inventory.getStackInSlot(args.checkSlot(inventory, 1))))
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ trait WorldTankAnalytics extends WorldAware with SideRestricted {
|
||||
}
|
||||
|
||||
@Callback(doc = """function(side:number):table -- Get a description of the fluid in the the tank on the specified side.""")
|
||||
def getFluidInTank(context: Context, args: Arguments): Array[AnyRef] = if (Settings.get.allowItemStackInspection) {
|
||||
def getFluidInTank(context: Context, args: Arguments): Array[AnyRef] = if (Settings.Misc.allowItemStackInspection) {
|
||||
val facing = checkSideForAction(args, 0)
|
||||
FluidUtil.fluidHandlerAt(position.offset(facing), facing.getOpposite) match {
|
||||
case Some(handler) =>
|
||||
|
@ -12,9 +12,8 @@ import net.minecraft.util.EnumFacing
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.World
|
||||
|
||||
// TODO Remove blocks in OC 1.7.
|
||||
class CompoundBlockDriver(val sidedBlocks: Array[DriverBlock]) extends DriverBlock {
|
||||
override def createEnvironment(world: World, pos: BlockPos, side: EnumFacing) = {
|
||||
override def createEnvironment(world: World, pos: BlockPos, side: EnumFacing): CompoundBlockNodeContainer = {
|
||||
val list = sidedBlocks.map {
|
||||
driver => Option(driver.createEnvironment(world, pos, side)) match {
|
||||
case Some(environment) => (driver.getClass.getName, environment)
|
||||
@ -25,10 +24,10 @@ class CompoundBlockDriver(val sidedBlocks: Array[DriverBlock]) extends DriverBlo
|
||||
else new CompoundBlockNodeContainer(cleanName(tryGetName(world, pos, list.map(_._2))), list: _*)
|
||||
}
|
||||
|
||||
override def worksWith(world: World, pos: BlockPos, side: EnumFacing) = sidedBlocks.forall(_.worksWith(world, pos, side)) && blocks.forall(_.worksWith(world, pos))
|
||||
override def worksWith(world: World, pos: BlockPos, side: EnumFacing): Boolean = sidedBlocks.forall(_.worksWith(world, pos, side))
|
||||
|
||||
override def equals(obj: Any) = obj match {
|
||||
case multi: CompoundBlockDriver if multi.sidedBlocks.length == sidedBlocks.length && multi.blocks.length == blocks.length => sidedBlocks.intersect(multi.sidedBlocks).length == sidedBlocks.length && blocks.intersect(multi.blocks).length == blocks.length
|
||||
override def equals(obj: Any): Boolean = obj match {
|
||||
case multi: CompoundBlockDriver if multi.sidedBlocks.length == sidedBlocks.length && multi.blocks.length == blocks.length => sidedBlocks.intersect(multi.sidedBlocks).length == sidedBlocks.length
|
||||
case _ => false
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,13 @@ import com.google.common.hash.Hashing
|
||||
import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.network._
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class CompoundBlockNodeContainer(val name: String, val environments: (String, NodeContainerItem)*) extends NodeContainerItem {
|
||||
// Block drivers with visibility < network usually won't make much sense,
|
||||
// but let's play it safe and use the least possible visibility based on
|
||||
// the drivers we encapsulate.
|
||||
val getNode = api.Network.newNode(this, (environments.filter(_._2.getNode != null).map(_._2.getNode.getReachability) ++ Seq(Visibility.NONE)).max).
|
||||
val getNode: ComponentNode = api.Network.newNode(this, (environments.filter(_._2.getNode != null).map(_._2.getNode.getReachability) ++ Seq(Visibility.NONE)).max).
|
||||
withComponent(name).
|
||||
create()
|
||||
|
||||
@ -26,7 +25,7 @@ class CompoundBlockNodeContainer(val name: String, val environments: (String, No
|
||||
case _ =>
|
||||
}
|
||||
|
||||
override def canUpdate = environments.exists(_._2.canUpdate)
|
||||
override def canUpdate: Boolean = environments.exists(_._2.canUpdate)
|
||||
|
||||
override def update() {
|
||||
for (environment <- updatingEnvironments) {
|
||||
@ -54,14 +53,29 @@ class CompoundBlockNodeContainer(val name: String, val environments: (String, No
|
||||
|
||||
private final val TypeHashTag = "typeHash"
|
||||
|
||||
override def load(nbt: NBTTagCompound) {
|
||||
|
||||
override def serializeNBT(): NBTTagCompound = {
|
||||
val nbt = new NBTTagCompound()
|
||||
nbt.setLong(TypeHashTag, typeHash)
|
||||
getNode.save(nbt)
|
||||
for ((driver, environment) <- environments) {
|
||||
try {
|
||||
nbt.setTag(driver, environment.serializeNBT())
|
||||
} catch {
|
||||
case e: Throwable => OpenComputers.log.warn(s"A block component of type '${environment.getClass.getName}' (provided by driver '$driver') threw an error while saving.", e)
|
||||
}
|
||||
}
|
||||
nbt
|
||||
}
|
||||
|
||||
override def deserializeNBT(nbt: NBTTagCompound): Unit = {
|
||||
// Ignore existing data if the underlying type is different.
|
||||
if (nbt.hasKey(TypeHashTag) && nbt.getLong(TypeHashTag) != typeHash) return
|
||||
getNode.load(nbt)
|
||||
for ((driver, environment) <- environments) {
|
||||
if (nbt.hasKey(driver)) {
|
||||
try {
|
||||
environment.load(nbt.getCompoundTag(driver))
|
||||
environment.deserializeNBT(nbt.getCompoundTag(driver))
|
||||
} catch {
|
||||
case e: Throwable => OpenComputers.log.warn(s"A block component of type '${environment.getClass.getName}' (provided by driver '$driver') threw an error while loading.", e)
|
||||
}
|
||||
@ -70,15 +84,6 @@ class CompoundBlockNodeContainer(val name: String, val environments: (String, No
|
||||
}
|
||||
|
||||
override def save(nbt: NBTTagCompound) {
|
||||
nbt.setLong(TypeHashTag, typeHash)
|
||||
getNode.save(nbt)
|
||||
for ((driver, environment) <- environments) {
|
||||
try {
|
||||
nbt.setNewCompoundTag(driver, environment.save)
|
||||
} catch {
|
||||
case e: Throwable => OpenComputers.log.warn(s"A block component of type '${environment.getClass.getName}' (provided by driver '$driver') threw an error while saving.", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def typeHash = {
|
||||
|
@ -11,7 +11,6 @@ import li.cil.oc.api.driver.EnvironmentProvider
|
||||
import li.cil.oc.api.driver.InventoryProvider
|
||||
import li.cil.oc.api.driver.item.HostAware
|
||||
import li.cil.oc.api.machine.Value
|
||||
import li.cil.oc.api.network.{Environment, EnvironmentHost, NodeContainerItem}
|
||||
import li.cil.oc.api.util.Location
|
||||
import li.cil.oc.util.InventoryUtils
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
@ -26,6 +25,7 @@ import net.minecraftforge.items.IItemHandler
|
||||
import scala.collection.convert.WrapAsJava._
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
import scala.collection.mutable
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
import scala.math.ScalaNumber
|
||||
|
||||
/**
|
||||
@ -43,17 +43,17 @@ import scala.math.ScalaNumber
|
||||
* the computer, but may also provide context-free functions.
|
||||
*/
|
||||
private[oc] object Registry extends api.detail.DriverAPI {
|
||||
val sidedBlocks = mutable.ArrayBuffer.empty[DriverBlock]
|
||||
val sidedBlocks: ArrayBuffer[DriverBlock] = mutable.ArrayBuffer.empty[DriverBlock]
|
||||
|
||||
val items = mutable.ArrayBuffer.empty[DriverItem]
|
||||
val items: ArrayBuffer[DriverItem] = mutable.ArrayBuffer.empty[DriverItem]
|
||||
|
||||
val converters = mutable.ArrayBuffer.empty[api.driver.Converter]
|
||||
val converters: ArrayBuffer[Converter] = mutable.ArrayBuffer.empty[api.driver.Converter]
|
||||
|
||||
val environmentProviders = mutable.ArrayBuffer.empty[api.driver.EnvironmentProvider]
|
||||
val environmentProviders: ArrayBuffer[EnvironmentProvider] = mutable.ArrayBuffer.empty[api.driver.EnvironmentProvider]
|
||||
|
||||
val inventoryProviders = mutable.ArrayBuffer.empty[api.driver.InventoryProvider]
|
||||
val inventoryProviders: ArrayBuffer[InventoryProvider] = mutable.ArrayBuffer.empty[api.driver.InventoryProvider]
|
||||
|
||||
val blacklist = mutable.ArrayBuffer.empty[(ItemStack, mutable.Set[Class[_]])]
|
||||
val blacklist: ArrayBuffer[(ItemStack, mutable.Set[Class[_]])] = mutable.ArrayBuffer.empty[(ItemStack, mutable.Set[Class[_]])]
|
||||
|
||||
/** Used to keep track of whether we're past the init phase. */
|
||||
var locked = false
|
||||
@ -104,7 +104,7 @@ private[oc] object Registry extends api.detail.DriverAPI {
|
||||
case _ => null
|
||||
}
|
||||
|
||||
override def driverFor(stack: ItemStack, host: Class[_ <: Location]) =
|
||||
override def driverFor(stack: ItemStack, host: Class[_ <: Location]): DriverItem =
|
||||
if (stack != null) {
|
||||
val hostAware = items.collect {
|
||||
case driver: HostAware if driver.worksWith(stack) => driver
|
||||
@ -116,7 +116,7 @@ private[oc] object Registry extends api.detail.DriverAPI {
|
||||
}
|
||||
else null
|
||||
|
||||
override def driverFor(stack: ItemStack) =
|
||||
override def driverFor(stack: ItemStack): DriverItem =
|
||||
if (stack != null) items.find(_.worksWith(stack)).orNull
|
||||
else null
|
||||
|
||||
@ -145,9 +145,9 @@ private[oc] object Registry extends api.detail.DriverAPI {
|
||||
}
|
||||
}
|
||||
|
||||
override def blockDrivers = sidedBlocks.toSeq
|
||||
override def blockDrivers: util.List[DriverBlock] = sidedBlocks.toSeq
|
||||
|
||||
override def itemDrivers = items.toSeq
|
||||
override def itemDrivers: util.List[DriverItem] = items.toSeq
|
||||
|
||||
def blacklistHost(stack: ItemStack, host: Class[_]) {
|
||||
blacklist.find(_._1.isItemEqual(stack)) match {
|
||||
@ -156,7 +156,7 @@ private[oc] object Registry extends api.detail.DriverAPI {
|
||||
}
|
||||
}
|
||||
|
||||
def convert(value: Array[AnyRef]) = if (value != null) value.map(arg => convertRecursively(arg, new util.IdentityHashMap())) else null
|
||||
def convert(value: Array[AnyRef]): Array[AnyRef] = if (value != null) value.map(arg => convertRecursively(arg, new util.IdentityHashMap())) else null
|
||||
|
||||
def convertRecursively(value: Any, memo: util.IdentityHashMap[AnyRef, AnyRef], force: Boolean = false): AnyRef = {
|
||||
val valueRef = value match {
|
||||
@ -239,7 +239,7 @@ private[oc] object Registry extends api.detail.DriverAPI {
|
||||
}
|
||||
}
|
||||
|
||||
def convertList(obj: AnyRef, list: Iterator[(Any, Int)], memo: util.IdentityHashMap[AnyRef, AnyRef]) = {
|
||||
def convertList(obj: AnyRef, list: Iterator[(Any, Int)], memo: util.IdentityHashMap[AnyRef, AnyRef]): Array[AnyRef] = {
|
||||
val converted = mutable.ArrayBuffer.empty[AnyRef]
|
||||
memo += obj -> converted
|
||||
for ((value, index) <- list) {
|
||||
@ -248,7 +248,7 @@ private[oc] object Registry extends api.detail.DriverAPI {
|
||||
converted.toArray
|
||||
}
|
||||
|
||||
def convertMap(obj: AnyRef, map: Map[_, _], memo: util.IdentityHashMap[AnyRef, AnyRef]) = {
|
||||
def convertMap(obj: AnyRef, map: Map[_, _], memo: util.IdentityHashMap[AnyRef, AnyRef]): AnyRef = {
|
||||
val converted = memo.getOrElseUpdate(obj, mutable.Map.empty[AnyRef, AnyRef]) match {
|
||||
case map: mutable.Map[AnyRef, AnyRef]@unchecked => map
|
||||
case map: java.util.Map[AnyRef, AnyRef]@unchecked => mapAsScalaMap(map)
|
||||
|
@ -4,14 +4,15 @@ import java.io.FileNotFoundException
|
||||
import java.util.concurrent.Callable
|
||||
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.fs.FileSystem
|
||||
import li.cil.oc.api.fs.Handle
|
||||
import li.cil.oc.api.fs.Mode
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class CompositeReadOnlyFileSystem(factories: mutable.LinkedHashMap[String, Callable[api.fs.FileSystem]]) extends api.fs.FileSystem {
|
||||
var parts = mutable.LinkedHashMap.empty[String, api.fs.FileSystem]
|
||||
var parts: mutable.LinkedHashMap[String, FileSystem] = mutable.LinkedHashMap.empty[String, api.fs.FileSystem]
|
||||
for ((name, factory) <- factories) {
|
||||
val fs = factory.call()
|
||||
if (fs != null) {
|
||||
@ -23,21 +24,21 @@ class CompositeReadOnlyFileSystem(factories: mutable.LinkedHashMap[String, Calla
|
||||
|
||||
override def isReadOnly = true
|
||||
|
||||
override def spaceTotal = math.max(spaceUsed, parts.values.map(_.spaceTotal).sum)
|
||||
override def spaceTotal: Long = math.max(spaceUsed, parts.values.map(_.spaceTotal).sum)
|
||||
|
||||
override def spaceUsed = parts.values.map(_.spaceUsed).sum
|
||||
override def spaceUsed: Long = parts.values.map(_.spaceUsed).sum
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def exists(path: String) = findFileSystem(path).isDefined
|
||||
override def exists(path: String): Boolean = findFileSystem(path).isDefined
|
||||
|
||||
override def size(path: String) = findFileSystem(path).fold(0L)(_.size(path))
|
||||
override def size(path: String): Long = findFileSystem(path).fold(0L)(_.size(path))
|
||||
|
||||
override def isDirectory(path: String) = findFileSystem(path).fold(false)(_.isDirectory(path))
|
||||
override def isDirectory(path: String): Boolean = findFileSystem(path).fold(false)(_.isDirectory(path))
|
||||
|
||||
override def lastModified(path: String) = findFileSystem(path).fold(0L)(_.lastModified(path))
|
||||
override def lastModified(path: String): Long = findFileSystem(path).fold(0L)(_.lastModified(path))
|
||||
|
||||
override def list(path: String) = if (isDirectory(path)) {
|
||||
override def list(path: String): Array[String] = if (isDirectory(path)) {
|
||||
parts.values.foldLeft(mutable.Set.empty[String])((acc, fs) => {
|
||||
if (fs.exists(path)) try {
|
||||
val l = fs.list(path)
|
||||
@ -70,27 +71,32 @@ class CompositeReadOnlyFileSystem(factories: mutable.LinkedHashMap[String, Calla
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def open(path: String, mode: Mode) = findFileSystem(path) match {
|
||||
override def open(path: String, mode: Mode): Int = findFileSystem(path) match {
|
||||
case Some(fs) => fs.open(path, mode)
|
||||
case _ => throw new FileNotFoundException(path)
|
||||
}
|
||||
|
||||
override def getHandle(handle: Int) = parts.valuesIterator.map(_.getHandle(handle)).find(_ != null).orNull
|
||||
override def getHandle(handle: Int): Handle = parts.valuesIterator.map(_.getHandle(handle)).find(_ != null).orNull
|
||||
|
||||
override def close() = parts.values.foreach(_.close())
|
||||
override def close(): Unit = parts.values.foreach(_.close())
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def load(nbt: NBTTagCompound) {
|
||||
override def serializeNBT(): NBTTagCompound = {
|
||||
val nbt = new NBTTagCompound()
|
||||
for ((name, fs) <- parts) {
|
||||
fs.load(nbt.getCompoundTag(name))
|
||||
nbt.setTag(name, fs.serializeNBT)
|
||||
}
|
||||
nbt
|
||||
}
|
||||
|
||||
override def deserializeNBT(nbt: NBTTagCompound): Unit = {
|
||||
for ((name, fs) <- parts) {
|
||||
fs.deserializeNBT(nbt.getCompoundTag(name))
|
||||
}
|
||||
}
|
||||
|
||||
override def save(nbt: NBTTagCompound) {
|
||||
for ((name, fs) <- parts) {
|
||||
nbt.setNewCompoundTag(name, fs.save)
|
||||
}
|
||||
override def load(nbt: NBTTagCompound) {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
@ -6,13 +6,15 @@ import java.net.URISyntaxException
|
||||
import java.net.URL
|
||||
import java.util.UUID
|
||||
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.fs.FileSystem
|
||||
import li.cil.oc.api.fs.Label
|
||||
import li.cil.oc.api.network.EnvironmentHost
|
||||
import li.cil.oc.api.util.Location
|
||||
import li.cil.oc.server.component
|
||||
import li.cil.oc.server.component.FileSystem
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
@ -20,7 +22,7 @@ import net.minecraftforge.common.DimensionManager
|
||||
import scala.util.Try
|
||||
|
||||
object FileSystem extends api.detail.FileSystemAPI {
|
||||
lazy val isCaseInsensitive = Settings.Debug.forceCaseInsensitiveFS || (try {
|
||||
lazy val isCaseInsensitive: Boolean = Settings.Debug.forceCaseInsensitiveFS || (try {
|
||||
val uuid = UUID.randomUUID().toString
|
||||
val lowerCase = new io.File(DimensionManager.getCurrentSaveRootDirectory, uuid + "oc_rox")
|
||||
val upperCase = new io.File(DimensionManager.getCurrentSaveRootDirectory, uuid + "OC_ROX")
|
||||
@ -45,11 +47,12 @@ object FileSystem extends api.detail.FileSystemAPI {
|
||||
// Worst-case: we're on Windows or using a FAT32 partition mounted in *nix.
|
||||
// Note: we allow / as the path separator and expect all \s to be converted
|
||||
// accordingly before the path is passed to the file system.
|
||||
private val invalidChars = """\:*?"<>|""".toSet
|
||||
private val invalidChars =
|
||||
"""\:*?"<>|""".toSet
|
||||
|
||||
def isValidFilename(name: String) = !name.exists(invalidChars.contains)
|
||||
def isValidFilename(name: String): Boolean = !name.exists(invalidChars.contains)
|
||||
|
||||
def validatePath(path: String) = {
|
||||
def validatePath(path: String): String = {
|
||||
if (!isValidFilename(path)) {
|
||||
throw new java.io.IOException("path contains invalid characters")
|
||||
}
|
||||
@ -98,7 +101,7 @@ object FileSystem extends api.detail.FileSystemAPI {
|
||||
}
|
||||
}
|
||||
|
||||
override def fromSaveDirectory(root: String, capacity: Long, buffered: Boolean) = {
|
||||
override def fromSaveDirectory(root: String, capacity: Long, buffered: Boolean): Capacity = {
|
||||
val path = new io.File(DimensionManager.getCurrentSaveRootDirectory, Settings.savePath + root)
|
||||
if (!path.isDirectory) {
|
||||
path.delete()
|
||||
@ -113,29 +116,29 @@ object FileSystem extends api.detail.FileSystemAPI {
|
||||
|
||||
def fromMemory(capacity: Long): api.fs.FileSystem = new RamFileSystem(capacity)
|
||||
|
||||
override def asReadOnly(fileSystem: api.fs.FileSystem) =
|
||||
override def asReadOnly(fileSystem: api.fs.FileSystem): FileSystem =
|
||||
if (fileSystem.isReadOnly) fileSystem
|
||||
else new ReadOnlyWrapper(fileSystem)
|
||||
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: Location, accessSound: String, speed: Int) =
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: Location, accessSound: String, speed: Int): FileSystem =
|
||||
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(host), Option(accessSound), (speed - 1) max 0 min 5))).orNull
|
||||
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, host: Location, accessSound: String, speed: Int) =
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, host: Location, accessSound: String, speed: Int): FileSystem =
|
||||
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), host, accessSound, speed)
|
||||
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: Location, sound: String) =
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: Location, sound: String): FileSystem =
|
||||
asManagedEnvironment(fileSystem, label, host, sound, 1)
|
||||
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, host: Location, sound: String) =
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, host: Location, sound: String): FileSystem =
|
||||
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), host, sound, 1)
|
||||
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label) =
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label): FileSystem =
|
||||
asManagedEnvironment(fileSystem, label, null, null, 1)
|
||||
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String) =
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String): FileSystem =
|
||||
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), null, null, 1)
|
||||
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem) =
|
||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem): FileSystem =
|
||||
asManagedEnvironment(fileSystem, null: Label, null, null, 1)
|
||||
|
||||
abstract class ItemLabel(val stack: ItemStack) extends Label
|
||||
@ -143,7 +146,7 @@ object FileSystem extends api.detail.FileSystemAPI {
|
||||
private class ReadOnlyLabel(val label: String) extends Label {
|
||||
def setLabel(value: String) = throw new IllegalArgumentException("label is read only")
|
||||
|
||||
def getLabel = label
|
||||
def getLabel: String = label
|
||||
|
||||
private final val LabelTag = Constants.namespace + "fs.label"
|
||||
|
||||
@ -174,7 +177,7 @@ object FileSystem extends api.detail.FileSystemAPI {
|
||||
extends VirtualFileSystem
|
||||
with Buffered
|
||||
with Capacity {
|
||||
protected override def segments(path: String) = {
|
||||
protected override def segments(path: String): Array[String] = {
|
||||
val parts = super.segments(path)
|
||||
if (isCaseInsensitive) toCaseInsensitive(parts) else parts
|
||||
}
|
||||
|
@ -3,25 +3,26 @@ package li.cil.oc.server.fs
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.fs.Handle
|
||||
import li.cil.oc.api.fs.Mode
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
private class ReadOnlyWrapper(val fileSystem: api.fs.FileSystem) extends api.fs.FileSystem {
|
||||
override def isReadOnly = true
|
||||
|
||||
override def spaceTotal = fileSystem.spaceUsed()
|
||||
override def spaceTotal: Long = fileSystem.spaceUsed()
|
||||
|
||||
override def spaceUsed = fileSystem.spaceUsed()
|
||||
override def spaceUsed: Long = fileSystem.spaceUsed()
|
||||
|
||||
override def exists(path: String) = fileSystem.exists(path)
|
||||
override def exists(path: String): Boolean = fileSystem.exists(path)
|
||||
|
||||
override def size(path: String) = fileSystem.size(path)
|
||||
override def size(path: String): Long = fileSystem.size(path)
|
||||
|
||||
override def isDirectory(path: String) = fileSystem.isDirectory(path)
|
||||
override def isDirectory(path: String): Boolean = fileSystem.isDirectory(path)
|
||||
|
||||
override def lastModified(path: String) = fileSystem.lastModified(path)
|
||||
override def lastModified(path: String): Long = fileSystem.lastModified(path)
|
||||
|
||||
override def list(path: String) = fileSystem.list(path)
|
||||
override def list(path: String): Array[String] = fileSystem.list(path)
|
||||
|
||||
override def delete(path: String) = false
|
||||
|
||||
@ -31,17 +32,17 @@ private class ReadOnlyWrapper(val fileSystem: api.fs.FileSystem) extends api.fs.
|
||||
|
||||
override def setLastModified(path: String, time: Long) = false
|
||||
|
||||
override def open(path: String, mode: Mode) = mode match {
|
||||
override def open(path: String, mode: Mode): Int = mode match {
|
||||
case Mode.Read => fileSystem.open(path, mode)
|
||||
case Mode.Write => throw new FileNotFoundException("read-only filesystem; cannot open for writing: " + path)
|
||||
case Mode.Append => throw new FileNotFoundException("read-only filesystem; cannot open for appending: " + path)
|
||||
}
|
||||
|
||||
override def getHandle(handle: Int) = fileSystem.getHandle(handle)
|
||||
override def getHandle(handle: Int): Handle = fileSystem.getHandle(handle)
|
||||
|
||||
override def close() = fileSystem.close()
|
||||
override def close(): Unit = fileSystem.close()
|
||||
|
||||
override def load(nbt: NBTTagCompound) = fileSystem.load(nbt)
|
||||
override def serializeNBT(): NBTTagCompound = fileSystem.serializeNBT()
|
||||
|
||||
override def save(nbt: NBTTagCompound) = fileSystem.save(nbt)
|
||||
override def deserializeNBT(nbt: NBTTagCompound): Unit = fileSystem.deserializeNBT(nbt)
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package li.cil.oc.server.machine.luac
|
||||
|
||||
import li.cil.oc.api.network.{Component, ComponentNode, NodeComponent}
|
||||
import li.cil.oc.util.ExtendedLuaState.extendLuaState
|
||||
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
@ -4,7 +4,6 @@ import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.driver.item.MutableProcessor
|
||||
import li.cil.oc.api.driver.item.Processor
|
||||
import li.cil.oc.api.network.{Connector, EnergyNode, PowerNode}
|
||||
import li.cil.oc.util.ExtendedLuaState.extendLuaState
|
||||
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
@ -99,13 +98,13 @@ class ComputerAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
||||
if (Settings.Power.ignorePower)
|
||||
lua.pushNumber(Double.PositiveInfinity)
|
||||
else
|
||||
lua.pushNumber(node.asInstanceOf[EnergyNode].getGlobalBuffer)
|
||||
lua.pushNumber(node.getNetwork.getEnergyStored)
|
||||
1
|
||||
})
|
||||
lua.setField(-2, "energy")
|
||||
|
||||
lua.pushScalaFunction(lua => {
|
||||
lua.pushNumber(node.asInstanceOf[EnergyNode].getGlobalBufferSize)
|
||||
lua.pushNumber(node.getNetwork.getEnergyCapacity)
|
||||
1
|
||||
})
|
||||
lua.setField(-2, "maxEnergy")
|
||||
|
@ -8,18 +8,21 @@ import java.util.regex.Pattern
|
||||
|
||||
import com.google.common.base.Strings
|
||||
import com.google.common.io.PatternFilenameFilter
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.server.machine.Machine
|
||||
import li.cil.oc.util.ExtendedLuaState._
|
||||
import li.cil.repack.com.naef.jnlua
|
||||
import li.cil.repack.com.naef.jnlua.LuaState
|
||||
import li.cil.repack.com.naef.jnlua.LuaStateFiveThree
|
||||
import li.cil.repack.com.naef.jnlua.NativeSupport.Loader
|
||||
import org.apache.commons.lang3.SystemUtils
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
object LuaStateFactory {
|
||||
def isAvailable = {
|
||||
def isAvailable: Boolean = {
|
||||
// Force initialization of both.
|
||||
val lua52 = Lua52.isAvailable
|
||||
val lua53 = Lua53.isAvailable
|
||||
@ -29,7 +32,7 @@ object LuaStateFactory {
|
||||
object Lua52 extends LuaStateFactory {
|
||||
override def version: String = "lua52"
|
||||
|
||||
override protected def create(maxMemory: Option[Int]) = maxMemory.fold(new jnlua.LuaState())(new jnlua.LuaState(_))
|
||||
override protected def create(maxMemory: Option[Int]): LuaState = maxMemory.fold(new jnlua.LuaState())(new jnlua.LuaState(_))
|
||||
|
||||
override protected def openLibs(state: jnlua.LuaState): Unit = {
|
||||
state.openLib(jnlua.LuaState.Library.BASE)
|
||||
@ -47,7 +50,7 @@ object LuaStateFactory {
|
||||
object Lua53 extends LuaStateFactory {
|
||||
override def version: String = "lua53"
|
||||
|
||||
override protected def create(maxMemory: Option[Int]) = maxMemory.fold(new jnlua.LuaStateFiveThree())(new jnlua.LuaStateFiveThree(_))
|
||||
override protected def create(maxMemory: Option[Int]): LuaStateFiveThree = maxMemory.fold(new jnlua.LuaStateFiveThree())(new jnlua.LuaStateFiveThree(_))
|
||||
|
||||
override protected def openLibs(state: jnlua.LuaState): Unit = {
|
||||
state.openLib(jnlua.LuaState.Library.BASE)
|
||||
@ -121,7 +124,7 @@ abstract class LuaStateFactory {
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
def isAvailable = haveNativeLibrary
|
||||
def isAvailable: Boolean = haveNativeLibrary
|
||||
|
||||
val is64Bit = Architecture.IS_OS_X64
|
||||
|
||||
@ -377,15 +380,15 @@ abstract class LuaStateFactory {
|
||||
|
||||
// Inspired by org.apache.commons.lang3.SystemUtils
|
||||
object Architecture {
|
||||
val OS_ARCH = try System.getProperty("os.arch") catch {
|
||||
val OS_ARCH: String = try System.getProperty("os.arch") catch {
|
||||
case ex: SecurityException => null
|
||||
}
|
||||
|
||||
val IS_OS_ARM = isOSArchMatch("arm")
|
||||
val IS_OS_ARM: Boolean = isOSArchMatch("arm")
|
||||
|
||||
val IS_OS_X86 = isOSArchMatch("x86") || isOSArchMatch("i386")
|
||||
val IS_OS_X86: Boolean = isOSArchMatch("x86") || isOSArchMatch("i386")
|
||||
|
||||
val IS_OS_X64 = isOSArchMatch("x86_64") || isOSArchMatch("amd64")
|
||||
val IS_OS_X64: Boolean = isOSArchMatch("x86_64") || isOSArchMatch("amd64")
|
||||
|
||||
private def isOSArchMatch(archPrefix: String): Boolean = OS_ARCH != null && OS_ARCH.startsWith(archPrefix)
|
||||
}
|
||||
|
@ -142,9 +142,9 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def isInitialized = kernelMemory > 0
|
||||
override def isInitialized: Boolean = kernelMemory > 0
|
||||
|
||||
override def recomputeMemory(components: java.lang.Iterable[ItemStack]) = {
|
||||
override def recomputeMemory(components: java.lang.Iterable[ItemStack]): Boolean = {
|
||||
val memory = math.ceil(memoryInBytes(components) * ramScale).toInt
|
||||
Option(lua) match {
|
||||
case Some(l) if Settings.Debug.limitMemory =>
|
||||
|
@ -6,12 +6,12 @@ import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
|
||||
import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.api.Persistable
|
||||
import li.cil.oc.api.machine.Value
|
||||
import li.cil.oc.server.machine.ArgumentsImpl
|
||||
import li.cil.oc.util.ExtendedLuaState.extendLuaState
|
||||
import net.minecraft.nbt.CompressedStreamTools
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.INBTSerializable
|
||||
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
@ -20,10 +20,9 @@ class UserdataAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
||||
lua.newTable()
|
||||
|
||||
lua.pushScalaFunction(lua => {
|
||||
val nbt = new NBTTagCompound()
|
||||
val persistable = lua.toJavaObjectRaw(1).asInstanceOf[Persistable]
|
||||
val persistable = lua.toJavaObjectRaw(1).asInstanceOf[INBTSerializable]
|
||||
lua.pushString(persistable.getClass.getName)
|
||||
persistable.save(nbt)
|
||||
val nbt = persistable.serializeNBT()
|
||||
val baos = new ByteArrayOutputStream()
|
||||
val dos = new DataOutputStream(baos)
|
||||
CompressedStreamTools.write(nbt, dos)
|
||||
@ -36,12 +35,12 @@ class UserdataAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
||||
try {
|
||||
val className = lua.toString(1)
|
||||
val clazz = Class.forName(className)
|
||||
val persistable = clazz.newInstance.asInstanceOf[Persistable]
|
||||
val persistable = clazz.newInstance.asInstanceOf[INBTSerializable]
|
||||
val data = lua.toByteArray(2)
|
||||
val bais = new ByteArrayInputStream(data)
|
||||
val dis = new DataInputStream(bais)
|
||||
val nbt = CompressedStreamTools.read(dis)
|
||||
persistable.load(nbt)
|
||||
persistable.deserializeNBT(nbt)
|
||||
lua.pushJavaObjectRaw(persistable)
|
||||
1
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.driver.item.MutableProcessor
|
||||
import li.cil.oc.api.driver.item.Processor
|
||||
import li.cil.oc.api.network.EnergyNode
|
||||
import li.cil.oc.util.ScalaClosure._
|
||||
import li.cil.repack.org.luaj.vm2.LuaValue
|
||||
import li.cil.repack.org.luaj.vm2.Varargs
|
||||
@ -55,9 +54,9 @@ class ComputerAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) {
|
||||
if (Settings.Power.ignorePower)
|
||||
LuaValue.valueOf(Double.PositiveInfinity)
|
||||
else
|
||||
LuaValue.valueOf(node.asInstanceOf[EnergyNode].getGlobalBuffer))
|
||||
LuaValue.valueOf(node.getNetwork.getEnergyStored))
|
||||
|
||||
computer.set("maxEnergy", (_: Varargs) => LuaValue.valueOf(node.asInstanceOf[EnergyNode].getGlobalBufferSize))
|
||||
computer.set("maxEnergy", (_: Varargs) => LuaValue.valueOf(node.getNetwork.getEnergyCapacity))
|
||||
|
||||
computer.set("getArchitectures", (args: Varargs) => {
|
||||
machine.host.internalComponents.map(stack => (stack, api.Driver.driverFor(stack))).collectFirst {
|
||||
|
@ -4,6 +4,7 @@ import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
|
||||
import com.google.common.base.Strings
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
@ -95,9 +96,9 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def isInitialized = doneWithInitRun
|
||||
override def isInitialized: Boolean = doneWithInitRun
|
||||
|
||||
override def recomputeMemory(components: java.lang.Iterable[ItemStack]) = {
|
||||
override def recomputeMemory(components: java.lang.Iterable[ItemStack]): Boolean = {
|
||||
memory = memoryInBytes(components)
|
||||
memory > 0
|
||||
}
|
||||
@ -114,7 +115,7 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture
|
||||
synchronizedCall = null
|
||||
}
|
||||
|
||||
override def runThreaded(isSynchronizedReturn: Boolean) = {
|
||||
override def runThreaded(isSynchronizedReturn: Boolean): ExecutionResult = {
|
||||
try {
|
||||
// Resume the Lua state and remember the number of results we get.
|
||||
val results = if (isSynchronizedReturn) {
|
||||
@ -215,7 +216,7 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def initialize() = {
|
||||
override def initialize(): Boolean = {
|
||||
lua = JsePlatform.debugGlobals()
|
||||
lua.set("package", LuaValue.NIL)
|
||||
lua.set("require", LuaValue.NIL)
|
||||
@ -231,7 +232,7 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture
|
||||
|
||||
recomputeMemory(machine.host.internalComponents)
|
||||
|
||||
val kernel = lua.load(classOf[Machine].getResourceAsStream(Settings.scriptPath + "machine.lua"), "=machine", "t", lua)
|
||||
val kernel = lua.load(classOf[Machine].getResourceAsStream(Constants.scriptPath + "machine.lua"), "=machine", "t", lua)
|
||||
thread = new LuaThread(lua, kernel) // Left as the first value on the stack.
|
||||
|
||||
true
|
||||
@ -240,7 +241,7 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture
|
||||
override def onConnect() {
|
||||
}
|
||||
|
||||
override def close() = {
|
||||
override def close(): Unit = {
|
||||
lua = null
|
||||
thread = null
|
||||
synchronizedCall = null
|
||||
|
@ -2,8 +2,9 @@ package li.cil.oc.server.network
|
||||
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.common.tileentity.{TileEntityWaypoint, Waypoint}
|
||||
import li.cil.oc.util.BlockPosition
|
||||
import li.cil.oc.util.RTree
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.World
|
||||
import net.minecraftforge.event.world.ChunkEvent
|
||||
import net.minecraftforge.event.world.WorldEvent
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
|
||||
@ -48,8 +49,8 @@ object Waypoints {
|
||||
}
|
||||
}
|
||||
|
||||
def findWaypoints(pos: BlockPosition, range: Double): Iterable[TileEntityWaypoint] = {
|
||||
dimensions.get(pos.world.get.provider.getDimension) match {
|
||||
def findWaypoints(world: World, pos: BlockPos, range: Double): Iterable[TileEntityWaypoint] = {
|
||||
dimensions.get(world.provider.getDimension) match {
|
||||
case Some(set) =>
|
||||
val bounds = pos.bounds.expand(range * 0.5, range * 0.5, range * 0.5)
|
||||
set.query((bounds.minX, bounds.minY, bounds.minZ), (bounds.maxX, bounds.maxY, bounds.maxZ))
|
||||
|
@ -147,8 +147,8 @@ object Audio {
|
||||
checkALError()
|
||||
|
||||
AL10.alSource3f(source, AL10.AL_POSITION, x, y, z)
|
||||
AL10.alSourcef(source, AL10.AL_REFERENCE_DISTANCE, maxDistance)
|
||||
AL10.alSourcef(source, AL10.AL_MAX_DISTANCE, maxDistance)
|
||||
AL10.alSourcef(source, AL10.AL_REFERENCE_DISTANCE, maxDistance.toFloat)
|
||||
AL10.alSourcef(source, AL10.AL_MAX_DISTANCE, maxDistance.toFloat)
|
||||
AL10.alSourcef(source, AL10.AL_GAIN, gain * 0.3f)
|
||||
checkALError()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user