mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-24 21:47:12 -04:00
Re-enabled CC integration (untested), closes #1653.
This commit is contained in:
parent
4c5806eb1a
commit
8d45fc41c6
10
build.gradle
10
build.gradle
@ -79,6 +79,10 @@ repositories {
|
||||
name = "mobius"
|
||||
url = "http://mobiusstrip.eu/maven"
|
||||
}
|
||||
ivy {
|
||||
name 'ComputerCraft'
|
||||
artifactPattern "http://addons-origin.cursecdn.com/files/${config.cc.cf}/[module][revision].[ext]"
|
||||
}
|
||||
/*
|
||||
maven {
|
||||
name = "BluePower"
|
||||
@ -144,10 +148,6 @@ repositories {
|
||||
name 'MineFactoryReloaded'
|
||||
artifactPattern "http://addons-origin.cursecdn.com/files/${config.mfr.cf}/[module]-[revision].[ext]"
|
||||
}
|
||||
ivy {
|
||||
name 'ComputerCraft'
|
||||
artifactPattern "http://addons-origin.cursecdn.com/files/${config.cc.cf}/[module][revision].[ext]"
|
||||
}
|
||||
ivy {
|
||||
name 'EnderIO'
|
||||
artifactPattern "http://addons-origin.cursecdn.com/files/${config.eio.cf}/[module]-[revision].[ext]"
|
||||
@ -213,7 +213,6 @@ dependencies {
|
||||
provided name: 'CoFHLib', version: config.cofhlib.version, ext: 'jar'
|
||||
provided name: 'CoFHCore', version: config.cofhcore.version, ext: 'jar'
|
||||
provided name: 'MineFactoryReloaded', version: config.mfr.version, ext: 'jar'
|
||||
provided name: 'ComputerCraft', version: config.cc.version, ext: 'jar'
|
||||
provided name: 'EnderIO', version: config.eio.version, ext: 'jar'
|
||||
provided name: 'Railcraft', version: config.rc.version, ext: 'jar'
|
||||
provided name: 'BloodMagic', version: config.bloodmagic.version, ext: 'jar'
|
||||
@ -221,6 +220,7 @@ dependencies {
|
||||
provided name: 'ThaumicEnergistics', version: config.thaumicenergistics.version, ext: 'jar'
|
||||
provided "cyano.poweradvantage:PowerAdvantage-API:${config.poweradvantage.version}"
|
||||
*/
|
||||
provided name: 'ComputerCraft', version: config.cc.version, ext: 'jar'
|
||||
|
||||
compile 'com.google.code.findbugs:jsr305:1.3.9' // Annotations used by google libs.
|
||||
|
||||
|
@ -9,8 +9,8 @@ bc.version=7.0.9
|
||||
bloodmagic.cf=2223/203
|
||||
bloodmagic.version=1.3.0a-1
|
||||
bluepower.version=0.2.928
|
||||
cc.cf=2228/723
|
||||
cc.version=1.73
|
||||
cc.cf=2275/878
|
||||
cc.version=1.78
|
||||
ccc.version=1.0.5.34
|
||||
ccl.version=1.1.2.115
|
||||
cofhlib.cf=2230/207
|
||||
|
@ -0,0 +1,34 @@
|
||||
package li.cil.oc.integration.computercraft
|
||||
|
||||
import dan200.computercraft.api.filesystem.IMount
|
||||
import li.cil.oc.server.fs.InputStreamFileSystem
|
||||
|
||||
class ComputerCraftFileSystem(val mount: IMount) extends InputStreamFileSystem {
|
||||
override def spaceTotal = 0
|
||||
|
||||
override def spaceUsed = 0
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def exists(path: String) = mount.exists(path)
|
||||
|
||||
override def isDirectory(path: String) = mount.isDirectory(path)
|
||||
|
||||
override def lastModified(path: String) = 0L
|
||||
|
||||
override def list(path: String) = {
|
||||
val result = new java.util.ArrayList[String]
|
||||
mount.list(path, result)
|
||||
result.toArray.map(_.asInstanceOf[String])
|
||||
}
|
||||
|
||||
override def size(path: String) = mount.getSize(path)
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
protected def openInputChannel(path: String) = try {
|
||||
Some(new InputStreamChannel(mount.openForRead(path)))
|
||||
} catch {
|
||||
case _: Throwable => None
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package li.cil.oc.integration.computercraft
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
|
||||
import dan200.computercraft.api.filesystem.IWritableMount
|
||||
import li.cil.oc.api.fs.Mode
|
||||
import li.cil.oc.server.fs.OutputStreamFileSystem
|
||||
|
||||
class ComputerCraftWritableFileSystem(override val mount: IWritableMount)
|
||||
extends ComputerCraftFileSystem(mount)
|
||||
with OutputStreamFileSystem {
|
||||
|
||||
override def delete(path: String) = try {
|
||||
mount.delete(path)
|
||||
true
|
||||
} catch {
|
||||
case _: Throwable => false
|
||||
}
|
||||
|
||||
override def makeDirectory(path: String) = try {
|
||||
mount.makeDirectory(path)
|
||||
true
|
||||
} catch {
|
||||
case _: Throwable => false
|
||||
}
|
||||
|
||||
override protected def openOutputHandle(id: Int, path: String, mode: Mode): Option[OutputHandle] = try {
|
||||
Some(new ComputerCraftOutputHandle(mount, mode match {
|
||||
case Mode.Append => mount.openForAppend(path)
|
||||
case Mode.Write => mount.openForWrite(path)
|
||||
case _ => throw new IllegalArgumentException()
|
||||
}, this, id, path))
|
||||
} catch {
|
||||
case _: Throwable => None
|
||||
}
|
||||
|
||||
protected class ComputerCraftOutputHandle(val mount: IWritableMount, val stream: OutputStream, owner: OutputStreamFileSystem, handle: Int, path: String) extends OutputHandle(owner, handle, path) {
|
||||
override def length() = mount.getSize(path)
|
||||
|
||||
override def position() = throw new IOException("bad file descriptor")
|
||||
|
||||
override def write(value: Array[Byte]) = stream.write(value)
|
||||
}
|
||||
|
||||
}
|
@ -5,12 +5,11 @@ 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.network.EnvironmentHost
|
||||
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.common.Slot
|
||||
import li.cil.oc.integration.opencomputers.Item
|
||||
import li.cil.oc.server.fs.ComputerCraftFileSystem
|
||||
import li.cil.oc.server.fs.ComputerCraftWritableFileSystem
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
@ -19,7 +18,7 @@ object DriverComputerCraftMedia extends Item {
|
||||
|
||||
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))
|
||||
val mount = 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
|
||||
@ -28,6 +27,8 @@ object DriverComputerCraftMedia extends Item {
|
||||
}
|
||||
}
|
||||
|
||||
def fromComputerCraft(mount: AnyRef): FileSystem = DriverComputerCraftMedia.createFileSystem(mount).orNull
|
||||
|
||||
override def slot(stack: ItemStack) = Slot.Floppy
|
||||
|
||||
def createFileSystem(mount: AnyRef) = Option(mount) collect {
|
||||
|
@ -19,6 +19,8 @@ import li.cil.oc.api.network.Node;
|
||||
import li.cil.oc.api.network.Visibility;
|
||||
import li.cil.oc.util.Reflection;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -26,7 +28,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class DriverPeripheral implements li.cil.oc.api.driver.Block {
|
||||
public final class DriverPeripheral implements li.cil.oc.api.driver.SidedBlock {
|
||||
private static Set<Class<?>> blacklist;
|
||||
|
||||
private boolean isBlacklisted(final Object o) {
|
||||
@ -53,21 +55,21 @@ public final class DriverPeripheral implements li.cil.oc.api.driver.Block {
|
||||
return false;
|
||||
}
|
||||
|
||||
private IPeripheral findPeripheral(final World world, final int x, final int y, final int z) {
|
||||
private IPeripheral findPeripheral(final World world, final BlockPos pos) {
|
||||
try {
|
||||
final IPeripheral p = dan200.computercraft.ComputerCraft.getPeripheralAt(world, x, y, z, -1);
|
||||
final IPeripheral p = dan200.computercraft.ComputerCraft.getPeripheralAt(world, pos, null);
|
||||
if (!isBlacklisted(p)) {
|
||||
return p;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
OpenComputers.log().warn(String.format("Error accessing ComputerCraft peripheral @ (%d, %d, %d).", x, y, z), e);
|
||||
OpenComputers.log().warn(String.format("Error accessing ComputerCraft peripheral @ (%d, %d, %d).", pos.getX(), pos.getY(), pos.getZ()), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean worksWith(final World world, final int x, final int y, final int z) {
|
||||
final TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
public boolean worksWith(final World world, final BlockPos pos, final EnumFacing side) {
|
||||
final TileEntity tileEntity = world.getTileEntity(pos);
|
||||
return tileEntity != null
|
||||
// This ensures we don't get duplicate components, in case the
|
||||
// tile entity is natively compatible with OpenComputers.
|
||||
@ -76,12 +78,12 @@ public final class DriverPeripheral implements li.cil.oc.api.driver.Block {
|
||||
// to be incompatible with OpenComputers when used directly.
|
||||
&& !isBlacklisted(tileEntity)
|
||||
// Actual check if it's a peripheral.
|
||||
&& findPeripheral(world, x, y, z) != null;
|
||||
&& findPeripheral(world, pos) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManagedEnvironment createEnvironment(final World world, final int x, final int y, final int z) {
|
||||
return new Environment(findPeripheral(world, x, y, z));
|
||||
public ManagedEnvironment createEnvironment(final World world, final BlockPos pos, final EnumFacing side) {
|
||||
return new Environment(findPeripheral(world, pos));
|
||||
}
|
||||
|
||||
public static class Environment extends li.cil.oc.api.prefab.ManagedEnvironment implements li.cil.oc.api.network.ManagedPeripheral {
|
||||
@ -169,7 +171,7 @@ public final class DriverPeripheral implements li.cil.oc.api.driver.Block {
|
||||
if (fileSystems.containsKey(desiredLocation)) {
|
||||
return null;
|
||||
}
|
||||
return mount(desiredLocation, FileSystem.asManagedEnvironment(FileSystem.fromComputerCraft(mount)));
|
||||
return mount(desiredLocation, FileSystem.asManagedEnvironment(DriverComputerCraftMedia.fromComputerCraft(mount)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -177,7 +179,7 @@ public final class DriverPeripheral implements li.cil.oc.api.driver.Block {
|
||||
if (fileSystems.containsKey(desiredLocation)) {
|
||||
return null;
|
||||
}
|
||||
return mount(desiredLocation, FileSystem.asManagedEnvironment(FileSystem.fromComputerCraft(mount), driveName));
|
||||
return mount(desiredLocation, FileSystem.asManagedEnvironment(DriverComputerCraftMedia.fromComputerCraft(mount), driveName));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -185,7 +187,7 @@ public final class DriverPeripheral implements li.cil.oc.api.driver.Block {
|
||||
if (fileSystems.containsKey(desiredLocation)) {
|
||||
return null;
|
||||
}
|
||||
return mount(desiredLocation, FileSystem.asManagedEnvironment(FileSystem.fromComputerCraft(mount)));
|
||||
return mount(desiredLocation, FileSystem.asManagedEnvironment(DriverComputerCraftMedia.fromComputerCraft(mount)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,7 +195,7 @@ public final class DriverPeripheral implements li.cil.oc.api.driver.Block {
|
||||
if (fileSystems.containsKey(desiredLocation)) {
|
||||
return null;
|
||||
}
|
||||
return mount(desiredLocation, FileSystem.asManagedEnvironment(FileSystem.fromComputerCraft(mount), driveName));
|
||||
return mount(desiredLocation, FileSystem.asManagedEnvironment(DriverComputerCraftMedia.fromComputerCraft(mount), driveName));
|
||||
}
|
||||
|
||||
private String mount(final String path, final li.cil.oc.api.network.ManagedEnvironment fileSystem) {
|
||||
|
@ -1,8 +1,11 @@
|
||||
package li.cil.oc.integration.computercraft
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI
|
||||
import dan200.computercraft.api.peripheral.IPeripheral
|
||||
import dan200.computercraft.api.peripheral.IPeripheralProvider
|
||||
import li.cil.oc.common.tileentity.traits.SwitchLike
|
||||
import net.minecraft.util.BlockPos
|
||||
import net.minecraft.util.EnumFacing
|
||||
import net.minecraft.world.World
|
||||
|
||||
object PeripheralProvider extends IPeripheralProvider {
|
||||
@ -10,7 +13,7 @@ object PeripheralProvider extends IPeripheralProvider {
|
||||
ComputerCraftAPI.registerPeripheralProvider(this)
|
||||
}
|
||||
|
||||
override def getPeripheral(world: World, x: Int, y: Int, z: Int, side: Int) = world.getTileEntity(x, y, z) match {
|
||||
override def getPeripheral(world: World, blockPos: BlockPos, enumFacing: EnumFacing): IPeripheral = world.getTileEntity(blockPos) match {
|
||||
case switch: SwitchLike => new SwitchPeripheral(switch)
|
||||
case _ => null
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import li.cil.oc.api.machine.Context
|
||||
import li.cil.oc.api.network.Component
|
||||
import li.cil.oc.common.tileentity.traits.SwitchLike
|
||||
import li.cil.oc.util.ResultWrapper._
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import net.minecraft.util.EnumFacing
|
||||
|
||||
import scala.collection.convert.WrapAsJava._
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
@ -138,7 +138,7 @@ class SwitchPeripheral(val switch: SwitchLike) extends IPeripheral {
|
||||
}
|
||||
|
||||
private def visibleComponents = {
|
||||
ForgeDirection.VALID_DIRECTIONS.flatMap(side => {
|
||||
EnumFacing.values().flatMap(side => {
|
||||
val node = switch.sidedNode(side)
|
||||
node.reachableNodes.collect {
|
||||
case component: Component if component.canBeSeenFrom(node) => component
|
||||
|
Loading…
x
Reference in New Issue
Block a user