From b12913b8b774c380252ab6bfc7d42fd517ce87ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 8 Feb 2014 22:09:33 +0100 Subject: [PATCH 1/3] fixed internet card and abstract bus card in servers; made server implement context --- .../cil/oc/common/tileentity/Computer.scala | 2 +- .../li/cil/oc/common/tileentity/Rack.scala | 7 +++++ .../cil/oc/server/component/AbstractBus.scala | 24 +++++++++++++--- .../oc/server/component/InternetCard.scala | 28 ++++++++++++------- .../li/cil/oc/server/component/Server.scala | 20 +++++++++++++ .../server/component/UpgradeGenerator.scala | 5 ++-- .../oc/server/component/machine/Machine.scala | 7 +++-- .../server/driver/item/AbstractBusCard.scala | 7 +++-- .../oc/server/driver/item/FileSystem.scala | 19 +++++-------- .../oc/server/driver/item/InternetCard.scala | 8 ++---- .../server/driver/item/UpgradeGenerator.scala | 4 +-- .../driver/item/UpgradeNavigation.scala | 4 +-- .../driver/item/WirelessNetworkCard.scala | 4 +-- 13 files changed, 91 insertions(+), 48 deletions(-) diff --git a/src/main/java/li/cil/oc/common/tileentity/Computer.scala b/src/main/java/li/cil/oc/common/tileentity/Computer.scala index 0a1f44b01..3b0f602de 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Computer.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Computer.scala @@ -17,7 +17,7 @@ import stargatetech2.api.bus.IBusDevice // See AbstractBusAware as to why we have to define the IBusDevice here. @Optional.Interface(iface = "stargatetech2.api.bus.IBusDevice", modid = "StargateTech2") -abstract class Computer(isRemote: Boolean) extends Environment with ComponentInventory with Rotatable with BundledRedstoneAware with AbstractBusAware with IBusDevice with Analyzable with Context with Machine.Owner { +abstract class Computer(isRemote: Boolean) extends Environment with ComponentInventory with Rotatable with BundledRedstoneAware with AbstractBusAware with IBusDevice with Analyzable with Machine.Owner { protected val _computer = if (isRemote) null else new Machine(this) def computer = _computer diff --git a/src/main/java/li/cil/oc/common/tileentity/Rack.scala b/src/main/java/li/cil/oc/common/tileentity/Rack.scala index fcd029925..a30310ddd 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Rack.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Rack.scala @@ -1,6 +1,7 @@ package li.cil.oc.common.tileentity import cpw.mods.fml.common.Optional +import cpw.mods.fml.common.Optional.Method import cpw.mods.fml.relauncher.{Side, SideOnly} import li.cil.oc.api.Network import li.cil.oc.api.network.{Connector, Visibility, Node, Analyzable} @@ -39,6 +40,12 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun override def canConnect(side: ForgeDirection) = side != facing + @Method(modid = "StargateTech2") + override def getInterfaces(side: Int) = if (side != facing.ordinal) { + super.getInterfaces(side) + } + else null + // ----------------------------------------------------------------------- // def isRunning(number: Int) = diff --git a/src/main/java/li/cil/oc/server/component/AbstractBus.scala b/src/main/java/li/cil/oc/server/component/AbstractBus.scala index ade841524..359ba72e6 100644 --- a/src/main/java/li/cil/oc/server/component/AbstractBus.scala +++ b/src/main/java/li/cil/oc/server/component/AbstractBus.scala @@ -2,19 +2,19 @@ package li.cil.oc.server.component import li.cil.oc.Settings import li.cil.oc.api.Network -import li.cil.oc.api.network.{Arguments, Context, Callback, Visibility} +import li.cil.oc.api.network._ import net.minecraft.nbt.NBTTagCompound import scala.collection.convert.WrapAsScala._ import stargatetech2.api.StargateTechAPI import stargatetech2.api.bus._ -class AbstractBus(val owner: Context with IBusDevice) extends ManagedComponent with IBusDriver { +class AbstractBus(val device: IBusDevice) extends ManagedComponent with IBusDriver { val node = Network.newNode(this, Visibility.Neighbors). withComponent("abstract_bus"). withConnector(). create() - val busInterface: IBusInterface = StargateTechAPI.api.getFactory.getIBusInterface(owner, this) + val busInterface: IBusInterface = StargateTechAPI.api.getFactory.getIBusInterface(device, this) protected var isEnabled = true @@ -22,6 +22,8 @@ class AbstractBus(val owner: Context with IBusDevice) extends ManagedComponent w protected var sendQueue: Option[QueuedPacket] = None + protected var owner: Option[Context] = None + // ----------------------------------------------------------------------- // override def canHandlePacket(sender: Short, protocolID: Int, hasLIP: Boolean) = hasLIP @@ -30,7 +32,7 @@ class AbstractBus(val owner: Context with IBusDevice) extends ManagedComponent w val lip = packet.getPlainText val data = Map(lip.getEntryList.map(key => (key, lip.get(key))): _*) val metadata = Map("mod" -> lip.getMetadata.modID, "device" -> lip.getMetadata.deviceName, "player" -> lip.getMetadata.playerName) - owner.signal("bus_message", Int.box(packet.getProtocolID), Int.box(packet.getSender), Int.box(packet.getTarget), data, metadata) + owner.foreach(_.signal("bus_message", Int.box(packet.getProtocolID), Int.box(packet.getSender), Int.box(packet.getTarget), data, metadata)) } override def getNextPacketToSend = if (sendQueue.isDefined) { @@ -87,6 +89,20 @@ class AbstractBus(val owner: Context with IBusDevice) extends ManagedComponent w // ----------------------------------------------------------------------- // + override def onConnect(node: Node) { + super.onConnect(node) + if (owner.isEmpty && node.host.isInstanceOf[Context]) { + owner = Some(node.host.asInstanceOf[Context]) + } + } + + override def onDisconnect(node: Node) { + super.onDisconnect(node) + if (owner.isDefined && node.host.isInstanceOf[Context] && (node.host.asInstanceOf[Context] == owner.get)) { + owner = None + } + } + override def load(nbt: NBTTagCompound) { super.load(nbt) busInterface.readFromNBT(nbt, "bus") diff --git a/src/main/java/li/cil/oc/server/component/InternetCard.scala b/src/main/java/li/cil/oc/server/component/InternetCard.scala index 2f3f1c901..2b8d9f03d 100644 --- a/src/main/java/li/cil/oc/server/component/InternetCard.scala +++ b/src/main/java/li/cil/oc/server/component/InternetCard.scala @@ -8,16 +8,16 @@ import java.util.regex.Matcher import li.cil.oc.api import li.cil.oc.api.Network import li.cil.oc.api.network._ +import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.ThreadPoolFactory import li.cil.oc.{OpenComputers, Settings} -import li.cil.oc.util.ExtendedNBT._ import net.minecraft.nbt.NBTTagCompound import net.minecraft.server.MinecraftServer import scala.Array -import scala.collection.mutable import scala.collection.convert.WrapAsScala._ +import scala.collection.mutable -class InternetCard(val owner: Context) extends ManagedComponent { +class InternetCard extends ManagedComponent { val node = Network.newNode(this, Visibility.Network). withComponent("internet", Visibility.Neighbors). create() @@ -25,6 +25,8 @@ class InternetCard(val owner: Context) extends ManagedComponent { val romInternet = Option(api.FileSystem.asManagedEnvironment(api.FileSystem. fromClass(OpenComputers.getClass, Settings.resourceDomain, "lua/component/internet"), "internet")) + protected var owner: Option[Context] = None + protected val connections = mutable.Map.empty[Int, SocketChannel] // For HTTP requests the state switches like so: @@ -49,7 +51,7 @@ class InternetCard(val owner: Context) extends ManagedComponent { @Callback def request(context: Context, args: Arguments): Array[AnyRef] = { - if (context.node.address != owner.node.address) { + if (owner.isEmpty || context.node.address != owner.get.node.address) { throw new IllegalArgumentException("can only be used by the owning computer") } val address = args.checkString(0) @@ -105,16 +107,16 @@ class InternetCard(val owner: Context) extends ManagedComponent { finally { http.disconnect() } - case other => owner.signal("http_response", address, Unit, "connection failed") + case other => owner.foreach(_.signal("http_response", address, Unit, "connection failed")) } } catch { case e: FileNotFoundException => - owner.signal("http_response", address, Unit, "not found: " + Option(e.getMessage).getOrElse(e.toString)) + owner.foreach(_.signal("http_response", address, Unit, "not found: " + Option(e.getMessage).getOrElse(e.toString))) case _: SocketTimeoutException => - owner.signal("http_response", address, Unit, "timeout") + owner.foreach(_.signal("http_response", address, Unit, "timeout")) case e: Throwable => - owner.signal("http_response", address, Unit, Option(e.getMessage).getOrElse(e.toString)) + owner.foreach(_.signal("http_response", address, Unit, Option(e.getMessage).getOrElse(e.toString))) } finally { InternetCard.this.synchronized { @@ -200,7 +202,7 @@ class InternetCard(val owner: Context) extends ManagedComponent { this.synchronized { if (request.isEmpty && queue.isDefined) { val (address, packets) = queue.get - if (owner.signal("http_response", address, packets.front)) { + if (owner.fold(true)(_.signal("http_response", address, packets.front))) { packets.dequeue() } if (packets.isEmpty) { @@ -214,6 +216,9 @@ class InternetCard(val owner: Context) extends ManagedComponent { override def onConnect(node: Node) { super.onConnect(node) + if (owner.isEmpty && node.host.isInstanceOf[Context]) { + owner = Some(node.host.asInstanceOf[Context]) + } if (node == this.node) { romInternet.foreach(rom => node.neighbors.head.connect(rom.node)) } @@ -221,6 +226,9 @@ class InternetCard(val owner: Context) extends ManagedComponent { override def onDisconnect(node: Node) { super.onDisconnect(node) + if (owner.isDefined && node.host.isInstanceOf[Context] && (node.host.asInstanceOf[Context] == owner.get)) { + owner = None + } if (node == this.node) { for ((_, socket) <- connections) { socket.close() @@ -235,7 +243,7 @@ class InternetCard(val owner: Context) extends ManagedComponent { override def onMessage(message: Message) { super.onMessage(message) message.data match { - case Array() if (message.name == "computer.stopped" || message.name == "computer.started") && message.source.address == owner.node.address => + case Array() if (message.name == "computer.stopped" || message.name == "computer.started") && owner.isDefined && message.source.address == owner.get.node.address => connections.values.foreach(_.close()) connections.clear() InternetCard.this.synchronized { diff --git a/src/main/java/li/cil/oc/server/component/Server.scala b/src/main/java/li/cil/oc/server/component/Server.scala index 58ae4e2d6..48d9dc79a 100644 --- a/src/main/java/li/cil/oc/server/component/Server.scala +++ b/src/main/java/li/cil/oc/server/component/Server.scala @@ -18,6 +18,26 @@ class Server(val rack: tileentity.Rack, val number: Int) extends Machine.Owner { // ----------------------------------------------------------------------- // + override def address() = machine.node.address + + override def node() = machine.node + + override def start() = machine.start() + + override def stop() = machine.stop() + + override def pause(seconds: Double) = machine.pause(seconds) + + override def isPaused = machine.isPaused + + override def isRunning = machine.isRunning + + override def signal(name: String, args: AnyRef*) = machine.signal(name, args: _*) + + override def canInteract(player: String) = machine.canInteract(player) + + // ----------------------------------------------------------------------- // + override def installedMemory = inventory.items.foldLeft(0)((sum, stack) => sum + (stack match { case Some(item) => Registry.itemDriverFor(item) match { case Some(driver: driver.Memory) => driver.amount(item) diff --git a/src/main/java/li/cil/oc/server/component/UpgradeGenerator.scala b/src/main/java/li/cil/oc/server/component/UpgradeGenerator.scala index 5cd2a2892..16440355d 100644 --- a/src/main/java/li/cil/oc/server/component/UpgradeGenerator.scala +++ b/src/main/java/li/cil/oc/server/component/UpgradeGenerator.scala @@ -7,10 +7,9 @@ import li.cil.oc.util.ExtendedNBT._ import net.minecraft.entity.item.EntityItem import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound -import net.minecraft.tileentity.{TileEntity => MCTileEntity, TileEntityFurnace} -import scala.Some +import net.minecraft.tileentity.{TileEntity, TileEntityFurnace} -class UpgradeGenerator(val owner: MCTileEntity) extends ManagedComponent { +class UpgradeGenerator(val owner: TileEntity) extends ManagedComponent { val node = Network.newNode(this, Visibility.Network). withComponent("generator", Visibility.Neighbors). withConnector(). diff --git a/src/main/java/li/cil/oc/server/component/machine/Machine.scala b/src/main/java/li/cil/oc/server/component/machine/Machine.scala index 56d6e15fb..d8c173b71 100644 --- a/src/main/java/li/cil/oc/server/component/machine/Machine.scala +++ b/src/main/java/li/cil/oc/server/component/machine/Machine.scala @@ -483,10 +483,11 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi val invalid = mutable.Set.empty[String] for ((address, name) <- components) { if (node.network.node(address) == null) { - OpenComputers.log.fine("A component of type '%s' disappeared! This usually means that it didn't save its node.".format(name)) if (name == "filesystem") { - OpenComputers.log.fine("If this was a file system provided by a ComputerCraft peripheral, this is normal."); + OpenComputers.log.fine("A component of type '%s' disappeared! This usually means that it didn't save its node.".format(name)) + OpenComputers.log.fine("If this was a file system provided by a ComputerCraft peripheral, this is normal.") } + else OpenComputers.log.warning("A component of type '%s' disappeared! This usually means that it didn't save its node.".format(name)) signal("component_removed", address, name) invalid += address } @@ -794,7 +795,7 @@ object Machine { private val threadPool = ThreadPoolFactory.create("Computer", Settings.get.threads) - trait Owner { + trait Owner extends Context { def installedMemory: Int def maxComponents: Int diff --git a/src/main/java/li/cil/oc/server/driver/item/AbstractBusCard.scala b/src/main/java/li/cil/oc/server/driver/item/AbstractBusCard.scala index 4b986b6e5..227ca485c 100644 --- a/src/main/java/li/cil/oc/server/driver/item/AbstractBusCard.scala +++ b/src/main/java/li/cil/oc/server/driver/item/AbstractBusCard.scala @@ -2,19 +2,20 @@ package li.cil.oc.server.driver.item import li.cil.oc.Items import li.cil.oc.api.driver.Slot -import li.cil.oc.common.tileentity import li.cil.oc.server.component import li.cil.oc.util.mods.StargateTech2 import net.minecraft.item.ItemStack import net.minecraft.tileentity.{TileEntity => MCTileEntity} +import stargatetech2.api.bus.IBusDevice object AbstractBusCard extends Item { override def worksWith(stack: ItemStack) = isOneOf(stack, Items.abstractBus) - override def createEnvironment(stack: ItemStack, container: MCTileEntity) = container match { - case computer: tileentity.Computer if StargateTech2.isAvailable => new component.AbstractBus(computer) + override def createEnvironment(stack: ItemStack, container: MCTileEntity) = if (StargateTech2.isAvailable) container match { + case device: IBusDevice => new component.AbstractBus(device) case _ => null } + else null override def slot(stack: ItemStack) = Slot.Card } diff --git a/src/main/java/li/cil/oc/server/driver/item/FileSystem.scala b/src/main/java/li/cil/oc/server/driver/item/FileSystem.scala index d462f12cb..e6e601442 100644 --- a/src/main/java/li/cil/oc/server/driver/item/FileSystem.scala +++ b/src/main/java/li/cil/oc/server/driver/item/FileSystem.scala @@ -5,7 +5,6 @@ import li.cil.oc import li.cil.oc.api.driver.Slot import li.cil.oc.api.fs.Label import li.cil.oc.common.item.{FloppyDisk, HardDiskDrive} -import li.cil.oc.common.tileentity.TileEntity import li.cil.oc.util.mods.ComputerCraft import li.cil.oc.{Settings, Items} import net.minecraft.item.ItemStack @@ -16,17 +15,13 @@ 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) = - if (ComputerCraft.isDisk(stack)) { - container match { - case tileEntity: TileEntity => - val address = addressFromTag(dataTag(stack)) - val mount = ComputerCraft.createDiskMount(stack, tileEntity.world) - Option(oc.api.FileSystem.asManagedEnvironment(mount, new ComputerCraftLabel(stack))) match { - case Some(environment) => - environment.node.asInstanceOf[oc.server.network.Node].address = address - environment - case _ => null - } + if (ComputerCraft.isDisk(stack) && container != null) { + val address = addressFromTag(dataTag(stack)) + val mount = ComputerCraft.createDiskMount(stack, container.getWorldObj) + Option(oc.api.FileSystem.asManagedEnvironment(mount, new ComputerCraftLabel(stack))) match { + case Some(environment) => + environment.node.asInstanceOf[oc.server.network.Node].address = address + environment case _ => null } } else Items.multi.subItem(stack) match { diff --git a/src/main/java/li/cil/oc/server/driver/item/InternetCard.scala b/src/main/java/li/cil/oc/server/driver/item/InternetCard.scala index 807ccbb44..e222c253f 100644 --- a/src/main/java/li/cil/oc/server/driver/item/InternetCard.scala +++ b/src/main/java/li/cil/oc/server/driver/item/InternetCard.scala @@ -2,18 +2,14 @@ package li.cil.oc.server.driver.item import li.cil.oc.Items import li.cil.oc.api.driver.Slot -import li.cil.oc.api.network.Context import li.cil.oc.server.component import net.minecraft.item.ItemStack -import net.minecraft.tileentity.{TileEntity => MCTileEntity} +import net.minecraft.tileentity.TileEntity object InternetCard extends Item { override def worksWith(stack: ItemStack) = isOneOf(stack, Items.internet) - override def createEnvironment(stack: ItemStack, container: MCTileEntity) = container match { - case context: Context => new component.InternetCard(context) - case _ => null - } + override def createEnvironment(stack: ItemStack, container: TileEntity) = new component.InternetCard() override def slot(stack: ItemStack) = Slot.Card diff --git a/src/main/java/li/cil/oc/server/driver/item/UpgradeGenerator.scala b/src/main/java/li/cil/oc/server/driver/item/UpgradeGenerator.scala index 02c337736..063a6ea90 100644 --- a/src/main/java/li/cil/oc/server/driver/item/UpgradeGenerator.scala +++ b/src/main/java/li/cil/oc/server/driver/item/UpgradeGenerator.scala @@ -4,12 +4,12 @@ import li.cil.oc.Items import li.cil.oc.api.driver.Slot import li.cil.oc.server.component import net.minecraft.item.ItemStack -import net.minecraft.tileentity.{TileEntity => MCTileEntity} +import net.minecraft.tileentity.TileEntity object UpgradeGenerator extends Item { override def worksWith(stack: ItemStack) = isOneOf(stack, Items.upgradeGenerator) - override def createEnvironment(stack: ItemStack, container: MCTileEntity) = new component.UpgradeGenerator(container) + override def createEnvironment(stack: ItemStack, container: TileEntity) = new component.UpgradeGenerator(container) override def slot(stack: ItemStack) = Slot.Upgrade } diff --git a/src/main/java/li/cil/oc/server/driver/item/UpgradeNavigation.scala b/src/main/java/li/cil/oc/server/driver/item/UpgradeNavigation.scala index 5b01e1666..0367a6f9f 100644 --- a/src/main/java/li/cil/oc/server/driver/item/UpgradeNavigation.scala +++ b/src/main/java/li/cil/oc/server/driver/item/UpgradeNavigation.scala @@ -5,12 +5,12 @@ import li.cil.oc.server.component import li.cil.oc.server.driver.Registry import li.cil.oc.{Settings, Items} import net.minecraft.item.ItemStack -import net.minecraft.tileentity.{TileEntity => MCTileEntity} +import net.minecraft.tileentity.TileEntity object UpgradeNavigation extends Item { override def worksWith(stack: ItemStack) = isOneOf(stack, Items.upgradeNavigation) - override def createEnvironment(stack: ItemStack, container: MCTileEntity) = { + override def createEnvironment(stack: ItemStack, container: TileEntity) = { val nbt = Registry.itemDriverFor(stack) match { case Some(driver) => driver.dataTag(stack) case _ => null diff --git a/src/main/java/li/cil/oc/server/driver/item/WirelessNetworkCard.scala b/src/main/java/li/cil/oc/server/driver/item/WirelessNetworkCard.scala index f4ec50384..59c3b99b4 100644 --- a/src/main/java/li/cil/oc/server/driver/item/WirelessNetworkCard.scala +++ b/src/main/java/li/cil/oc/server/driver/item/WirelessNetworkCard.scala @@ -4,12 +4,12 @@ import li.cil.oc.Items import li.cil.oc.api.driver.Slot import li.cil.oc.server.component import net.minecraft.item.ItemStack -import net.minecraft.tileentity.{TileEntity => MCTileEntity} +import net.minecraft.tileentity.TileEntity object WirelessNetworkCard extends Item { override def worksWith(stack: ItemStack) = isOneOf(stack, Items.wlan) - override def createEnvironment(stack: ItemStack, container: MCTileEntity) = + override def createEnvironment(stack: ItemStack, container: TileEntity) = if (container != null) new component.WirelessNetworkCard(container) else null override def slot(stack: ItemStack) = Slot.Card From 05fb8f01baa90687106a81aae4a49b8037bfec37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 9 Feb 2014 00:11:00 +0100 Subject: [PATCH 2/3] multiple tiers for servers, with different inventory sizes and costs --- src/main/java/li/cil/oc/Items.scala | 6 ++-- src/main/java/li/cil/oc/Recipes.scala | 4 ++- src/main/java/li/cil/oc/Settings.scala | 10 +++++- .../java/li/cil/oc/client/GuiHandler.scala | 4 ++- .../java/li/cil/oc/common/GuiHandler.scala | 2 ++ .../li/cil/oc/common/container/Server.scala | 8 ++--- .../oc/common/inventory/ServerInventory.scala | 33 +++++++++++++++--- src/main/java/li/cil/oc/common/item/CPU.scala | 1 - .../java/li/cil/oc/common/item/Server.scala | 15 +++++--- .../li/cil/oc/common/tileentity/Rack.scala | 6 +++- .../li/cil/oc/server/component/Server.scala | 7 ++++ .../li/cil/oc/server/driver/item/Item.scala | 2 +- .../assets/opencomputers/lang/de_DE.lang | 6 ++-- .../assets/opencomputers/lang/en_US.lang | 6 ++-- .../opencomputers/recipes/default.recipes | 12 ++++++- .../opencomputers/recipes/hardmode.recipes | 14 ++++++-- .../opencomputers/textures/items/server.png | Bin 517 -> 0 bytes .../opencomputers/textures/items/server0.png | Bin 0 -> 521 bytes .../opencomputers/textures/items/server1.png | Bin 0 -> 525 bytes .../opencomputers/textures/items/server2.png | Bin 0 -> 531 bytes src/main/resources/reference.conf | 3 ++ 21 files changed, 111 insertions(+), 28 deletions(-) delete mode 100644 src/main/resources/assets/opencomputers/textures/items/server.png create mode 100644 src/main/resources/assets/opencomputers/textures/items/server0.png create mode 100644 src/main/resources/assets/opencomputers/textures/items/server1.png create mode 100644 src/main/resources/assets/opencomputers/textures/items/server2.png diff --git a/src/main/java/li/cil/oc/Items.scala b/src/main/java/li/cil/oc/Items.scala index 549fb2658..c167743b0 100644 --- a/src/main/java/li/cil/oc/Items.scala +++ b/src/main/java/li/cil/oc/Items.scala @@ -16,7 +16,7 @@ object Items { // ----------------------------------------------------------------------- // // Servers - var server: item.Server = _ + var server1, server2, server3: item.Server = _ // ----------------------------------------------------------------------- // // Memory @@ -125,11 +125,13 @@ object Items { ram5 = new item.Memory(multi, 4) // v1.2.0 - server = new item.Server(multi) + server3 = new item.Server(multi, 2) terminal = new item.Terminal(multi) cpu1 = new item.CPU(multi, 1) cpu2 = new item.CPU(multi, 2) internet = new item.InternetCard(multi) + server1 = new item.Server(multi, 0) + server2 = new item.Server(multi, 1) // ----------------------------------------------------------------------- // diff --git a/src/main/java/li/cil/oc/Recipes.scala b/src/main/java/li/cil/oc/Recipes.scala index c916df98c..c5641e90a 100644 --- a/src/main/java/li/cil/oc/Recipes.scala +++ b/src/main/java/li/cil/oc/Recipes.scala @@ -68,7 +68,9 @@ object Recipes { addRecipe(Items.hdd2.createItemStack(), recipes, "hdd2") addRecipe(Items.hdd3.createItemStack(), recipes, "hdd3") - addRecipe(Items.server.createItemStack(), recipes, "server") + addRecipe(Items.server1.createItemStack(), recipes, "server1") + addRecipe(Items.server2.createItemStack(), recipes, "server2") + addRecipe(Items.server3.createItemStack(), recipes, "server3") if (StargateTech2.isAvailable) { addRecipe(Items.abstractBus.createItemStack(), recipes, "abstractBusCard") diff --git a/src/main/java/li/cil/oc/Settings.scala b/src/main/java/li/cil/oc/Settings.scala index 4c1d30841..03d2c1888 100644 --- a/src/main/java/li/cil/oc/Settings.scala +++ b/src/main/java/li/cil/oc/Settings.scala @@ -165,7 +165,15 @@ class Settings(config: Config) { val maxClipboard = config.getInt("misc.maxClipboard") max 0 val maxNetworkPacketSize = config.getInt("misc.maxNetworkPacketSize") max 0 val maxWirelessRange = config.getDouble("misc.maxWirelessRange") max 0 - val rTreeMaxEntries = 10 // TODO config? + val rTreeMaxEntries = 10 + val terminalsPerTier = Array(config.getIntList("misc.terminalsPerTier"): _*) match { + case Array(tier1, tier2, tier3) => + Array(tier1: Int, tier2: Int, tier3: Int) + case _ => + OpenComputers.log.warning("Bad number of Remote Terminal counts, ignoring.") + Array(2, 4, 8) + } + } object Settings { diff --git a/src/main/java/li/cil/oc/client/GuiHandler.scala b/src/main/java/li/cil/oc/client/GuiHandler.scala index 68e287527..cf1236d32 100644 --- a/src/main/java/li/cil/oc/client/GuiHandler.scala +++ b/src/main/java/li/cil/oc/client/GuiHandler.scala @@ -25,7 +25,9 @@ object GuiHandler extends CommonGuiHandler { case _ => Items.multi.subItem(player.getCurrentEquippedItem) match { case Some(server: item.Server) if id == GuiType.Server.id => new gui.Server(player.inventory, new ServerInventory { - def container = player.getCurrentEquippedItem + override def tier = server.tier + + override def container = player.getCurrentEquippedItem override def isUseableByPlayer(player: EntityPlayer) = player == player }) diff --git a/src/main/java/li/cil/oc/common/GuiHandler.scala b/src/main/java/li/cil/oc/common/GuiHandler.scala index fdec9afa0..c1d275b2f 100644 --- a/src/main/java/li/cil/oc/common/GuiHandler.scala +++ b/src/main/java/li/cil/oc/common/GuiHandler.scala @@ -20,6 +20,8 @@ abstract class GuiHandler extends IGuiHandler { case _ => Items.multi.subItem(player.getCurrentEquippedItem) match { case Some(server: item.Server) if id == GuiType.Server.id => new container.Server(player.inventory, new ServerInventory { + override def tier = server.tier + override def container = player.getCurrentEquippedItem override def isUseableByPlayer(player: EntityPlayer) = player == player diff --git a/src/main/java/li/cil/oc/common/container/Server.scala b/src/main/java/li/cil/oc/common/container/Server.scala index ccccce67e..96a0a94d6 100644 --- a/src/main/java/li/cil/oc/common/container/Server.scala +++ b/src/main/java/li/cil/oc/common/container/Server.scala @@ -9,15 +9,15 @@ class Server(playerInventory: InventoryPlayer, serverInventory: ServerInventory) addSlotToContainer(76, 7 + i * slotSize, api.driver.Slot.Card, 2 - i) } - for (i <- 0 to 3) { - addSlotToContainer(100, 7 + i * slotSize, api.driver.Slot.Processor) + for (i <- 0 to 1 + serverInventory.tier) { + addSlotToContainer(100, 7 + i * slotSize, api.driver.Slot.Processor, 2) } - for (i <- 0 to 3) { + for (i <- 0 to 1 + serverInventory.tier) { addSlotToContainer(124, 7 + i * slotSize, api.driver.Slot.Memory, 2) } - for (i <- 0 to 3) { + for (i <- 0 to 1 + serverInventory.tier) { addSlotToContainer(148, 7 + i * slotSize, api.driver.Slot.HardDiskDrive, 2) } diff --git a/src/main/java/li/cil/oc/common/inventory/ServerInventory.scala b/src/main/java/li/cil/oc/common/inventory/ServerInventory.scala index 1987fb670..3c024a179 100644 --- a/src/main/java/li/cil/oc/common/inventory/ServerInventory.scala +++ b/src/main/java/li/cil/oc/common/inventory/ServerInventory.scala @@ -3,11 +3,17 @@ package li.cil.oc.common.inventory import li.cil.oc.Settings import li.cil.oc.api.driver.Slot import li.cil.oc.server.driver.Registry -import net.minecraft.item.ItemStack import net.minecraft.entity.player.EntityPlayer +import net.minecraft.item.ItemStack trait ServerInventory extends ItemStackInventory { - override def getSizeInventory = 14 + def tier: Int + + override def getSizeInventory = tier match { + case 1 => 11 + case 2 => 14 + case _ => 8 + } override def getInvName = Settings.namespace + "container.Server" @@ -15,8 +21,17 @@ trait ServerInventory extends ItemStackInventory { override def isUseableByPlayer(player: EntityPlayer) = false - override def isItemValidForSlot(slot: Int, stack: ItemStack) = - (slot, Registry.itemDriverFor(stack)) match { + override def isItemValidForSlot(slot: Int, stack: ItemStack) = tier match { + case 1 => (slot, Registry.itemDriverFor(stack)) match { + case (_, None) => false // Invalid item. + case (0, Some(driver)) => driver.slot(stack) == Slot.Card && driver.tier(stack) <= 2 + case (1, Some(driver)) => driver.slot(stack) == Slot.Card && driver.tier(stack) <= 1 + case (2 | 3 | 4, Some(driver)) => driver.slot(stack) == Slot.Processor && driver.tier(stack) <= 2 + case (5 | 6 | 7, Some(driver)) => driver.slot(stack) == Slot.Memory && driver.tier(stack) <= 2 + case (8 | 9 | 10, Some(driver)) => driver.slot(stack) == Slot.HardDiskDrive && driver.tier(stack) <= 2 + case _ => false // Invalid slot. + } + case 2 => (slot, Registry.itemDriverFor(stack)) match { case (_, None) => false // Invalid item. case (0, Some(driver)) => driver.slot(stack) == Slot.Card && driver.tier(stack) <= 2 case (1, Some(driver)) => driver.slot(stack) == Slot.Card && driver.tier(stack) <= 1 @@ -25,4 +40,14 @@ trait ServerInventory extends ItemStackInventory { case (10 | 11 | 12 | 13, Some(driver)) => driver.slot(stack) == Slot.HardDiskDrive && driver.tier(stack) <= 2 case _ => false // Invalid slot. } + case _ => (slot, Registry.itemDriverFor(stack)) match { + case (_, None) => false // Invalid item. + case (0, Some(driver)) => driver.slot(stack) == Slot.Card && driver.tier(stack) <= 2 + case (1, Some(driver)) => driver.slot(stack) == Slot.Card && driver.tier(stack) <= 1 + case (2 | 3, Some(driver)) => driver.slot(stack) == Slot.Processor && driver.tier(stack) <= 2 + case (4 | 5, Some(driver)) => driver.slot(stack) == Slot.Memory && driver.tier(stack) <= 2 + case (6 | 7, Some(driver)) => driver.slot(stack) == Slot.HardDiskDrive && driver.tier(stack) <= 2 + case _ => false // Invalid slot. + } + } } diff --git a/src/main/java/li/cil/oc/common/item/CPU.scala b/src/main/java/li/cil/oc/common/item/CPU.scala index 6b2ca7960..8023adefa 100644 --- a/src/main/java/li/cil/oc/common/item/CPU.scala +++ b/src/main/java/li/cil/oc/common/item/CPU.scala @@ -25,4 +25,3 @@ class CPU(val parent: Delegator, val tier: Int) extends Delegate { icon = iconRegister.registerIcon(Settings.resourceDomain + ":cpu" + tier) } } - diff --git a/src/main/java/li/cil/oc/common/item/Server.scala b/src/main/java/li/cil/oc/common/item/Server.scala index 681f7d2c5..07c5af98c 100644 --- a/src/main/java/li/cil/oc/common/item/Server.scala +++ b/src/main/java/li/cil/oc/common/item/Server.scala @@ -7,21 +7,26 @@ import li.cil.oc.util.Tooltip import li.cil.oc.{Settings, OpenComputers} import net.minecraft.client.renderer.texture.IconRegister import net.minecraft.entity.player.EntityPlayer -import net.minecraft.item.ItemStack +import net.minecraft.item.{EnumRarity, ItemStack} import net.minecraft.world.World import scala.collection.mutable -class Server(val parent: Delegator) extends Delegate { - val unlocalizedName = "Server" +class Server(val parent: Delegator, val tier: Int) extends Delegate { + val baseName = "Server" + val unlocalizedName = baseName + tier + + override def rarity = Array(EnumRarity.common, EnumRarity.uncommon, EnumRarity.rare).apply(tier max 0 min 2) override def maxStackSize = 1 private object HelperInventory extends ServerInventory { + def tier = Server.this.tier + var container: ItemStack = null } override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) { - tooltip.addAll(Tooltip.get(unlocalizedName)) + tooltip.addAll(Tooltip.get(baseName, Settings.get.terminalsPerTier(tier))) HelperInventory.container = stack HelperInventory.reinitialize() val items = mutable.Map.empty[String, Int] @@ -41,7 +46,7 @@ class Server(val parent: Delegator) extends Delegate { override def registerIcons(iconRegister: IconRegister) { super.registerIcons(iconRegister) - icon = iconRegister.registerIcon(Settings.resourceDomain + ":server") + icon = iconRegister.registerIcon(Settings.resourceDomain + ":server" + tier) } override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer) = { diff --git a/src/main/java/li/cil/oc/common/tileentity/Rack.scala b/src/main/java/li/cil/oc/common/tileentity/Rack.scala index a30310ddd..f98146a59 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Rack.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Rack.scala @@ -105,7 +105,11 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun override def getInventoryStackLimit = 1 - override def isItemValidForSlot(i: Int, stack: ItemStack) = Items.server.createItemStack().isItemEqual(stack) + override def isItemValidForSlot(i: Int, stack: ItemStack) = + Items.multi.subItem(stack) match { + case Some(subItem) => subItem == Items.server1 || subItem == Items.server2 || subItem == Items.server3 + case _ => false + } // ----------------------------------------------------------------------- // diff --git a/src/main/java/li/cil/oc/server/component/Server.scala b/src/main/java/li/cil/oc/server/component/Server.scala index 48d9dc79a..eb1c3a5bd 100644 --- a/src/main/java/li/cil/oc/server/component/Server.scala +++ b/src/main/java/li/cil/oc/server/component/Server.scala @@ -1,9 +1,11 @@ package li.cil.oc.server.component +import li.cil.oc.Items import li.cil.oc.api.driver import li.cil.oc.api.network.{Message, Node} import li.cil.oc.common.inventory.ComponentInventory import li.cil.oc.common.inventory.ServerInventory +import li.cil.oc.common.item import li.cil.oc.common.tileentity import li.cil.oc.server.component.machine.Machine import li.cil.oc.server.driver.Registry @@ -90,6 +92,11 @@ class Server(val rack: tileentity.Rack, val number: Int) extends Machine.Owner { } } + override def tier = Items.multi.subItem(container) match { + case Some(server: item.Server) => server.tier + case _ => 0 + } + var containerOverride: ItemStack = _ override def container = if (containerOverride != null) containerOverride else rack.getStackInSlot(number) diff --git a/src/main/java/li/cil/oc/server/driver/item/Item.scala b/src/main/java/li/cil/oc/server/driver/item/Item.scala index 450421ff5..0482122e4 100644 --- a/src/main/java/li/cil/oc/server/driver/item/Item.scala +++ b/src/main/java/li/cil/oc/server/driver/item/Item.scala @@ -13,8 +13,8 @@ trait Item extends driver.Item { protected def isOneOf(stack: ItemStack, items: common.item.Delegate*) = Items.multi.subItem(stack) match { - case None => false case Some(subItem) => items.contains(subItem) + case _ => false } } diff --git a/src/main/resources/assets/opencomputers/lang/de_DE.lang b/src/main/resources/assets/opencomputers/lang/de_DE.lang index ab030181d..ff6848bb8 100644 --- a/src/main/resources/assets/opencomputers/lang/de_DE.lang +++ b/src/main/resources/assets/opencomputers/lang/de_DE.lang @@ -60,7 +60,9 @@ oc:item.NumPad.name=Ziffernblock oc:item.PrintedCircuitBoard.name=Gedruckte Leiterplatte (PCB) oc:item.RawCircuitBoard.name=Leiterplattenrohling oc:item.RedstoneCard.name=Redstonekarte -oc:item.Server.name=Server +oc:item.Server0.name=Server (Stufe 1) +oc:item.Server1.name=Server (Stufe 2) +oc:item.Server2.name=Server (Stufe 3) oc:item.Terminal.name=Fernbedienung oc:item.Transistor.name=Transistor oc:item.UpgradeCrafting.name=Fertigungs-Upgrade @@ -154,7 +156,7 @@ oc:tooltip.Robot_Level=§fStufe§7: §a%s§7. oc:tooltip.Robot_StoredEnergy=§fGespeicherte Energie§7: §a%s§7. oc:tooltip.Router=Erlaubt es, mehrere Netzwerke miteinander zu verbinden. Leitet ausschließlich Netzwerknachrichten weiter, Komponenten "hinter" dem Router sind nicht sichtbar. Nützlich, um Netzwerke zu trennen, jedoch nach wie vor Kommunikation zwischen den Netzwerken zu erlauben, z.b. mittels Netzwerkkarten. oc:tooltip.Screen=Zeigt Text an, gesteuert von Grafikkarten in Computern.[nl] Höchstauflösung: §f%sx%s§7.[nl] Maximale Farbtiefe: §f%s§7. -oc:tooltip.Server=Ein Server kann wie ein gewöhnliches Computergehäuse mit Komponenten verbessert werden. Um den Server zu starten, muss er in einem Servergehäuse installiert werden. +oc:tooltip.Server=Ein Server kann wie ein gewöhnliches Computergehäuse mit Komponenten verbessert werden. Um den Server zu starten, muss er in einem Servergehäuse installiert werden.[nl] Anzahl unterstützter Fernbedienungen: §f%s§7. oc:tooltip.Server.Components=Installierte Komponenten: oc:tooltip.ServerRack=Erlaubt die Installation von bis zu vier Servern. Stellt für jeden eingebauten Server eine virtuelle Tastatur- und Bildschirmkomponente zur Verfügung, welche je eine Fernbedienung repräsentieren. oc:tooltip.Terminal=Erlaubt es, einen Server aus der Ferne zu steuern, so lange man sich in Reichweite des Servers befindet. Verhält sich wie Bildschirm und Tastatur in einem. Kann mit Shift-Rechtsklick an einen Server in einem Serverschrank gebunden werden. diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index 602c98c12..544af22b6 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -60,7 +60,9 @@ oc:item.NumPad.name=Numeric Keypad oc:item.PrintedCircuitBoard.name=Printed Circuit Board (PCB) oc:item.RawCircuitBoard.name=Raw Circuit Board oc:item.RedstoneCard.name=Redstone Card -oc:item.Server.name=Server +oc:item.Server0.name=Server (Tier 1) +oc:item.Server1.name=Server (Tier 2) +oc:item.Server2.name=Server (Tier 3) oc:item.Terminal.name=Remote Terminal oc:item.Transistor.name=Transistor oc:item.UpgradeCrafting.name=Crafting Upgrade @@ -154,7 +156,7 @@ oc:tooltip.Robot_Level=§fLevel§7: §a%s§7. oc:tooltip.Robot_StoredEnergy=§fStored energy§7: §a%s§7. oc:tooltip.Router=Allows connecting different networks to each other. Only network messages will be passed along, components will not be visible through this. Use this to separate networks while still allowing communication using Network Cards, for example. oc:tooltip.Screen=Display text, controlled by a Graphics Card in a Case.[nl] Maximum resolution: §f%sx%s§7.[nl] Maximum color depth: §f%s§7. -oc:tooltip.Server=This is a server, there are many like it, but this one can be upgraded with components much like a computer case can be. It can be run by inserting it into a server rack. +oc:tooltip.Server=This is a server, there are many like it, but this one can be upgraded with components much like a computer case can be. It can be run by inserting it into a server rack.[nl] Number of supported terminals: §f%s§7. oc:tooltip.Server.Components=Installed components: oc:tooltip.ServerRack=Allows the installation of up to four servers. Provides a built-in virtual keyboard and screen component for each server, representing a remote terminal. oc:tooltip.Terminal=Allows controlling a server remotely, as long as you are in range of it. Acts like a portable screen and keyboard. Shift-right-click a server in a server rack to bind the terminal to it. diff --git a/src/main/resources/assets/opencomputers/recipes/default.recipes b/src/main/resources/assets/opencomputers/recipes/default.recipes index 9154c1d31..e901711bb 100644 --- a/src/main/resources/assets/opencomputers/recipes/default.recipes +++ b/src/main/resources/assets/opencomputers/recipes/default.recipes @@ -12,11 +12,21 @@ terminal { [nuggetIron, "oc:craftingKeyboard", nuggetIron]] } -server { +server1 { input: [[obsidian, "oc:craftingRAMTier3", obsidian] + ["oc:circuitTier1", "oc:circuitTier2", "oc:circuitTier1"] + [obsidian, "oc:craftingCircuitBoardPrinted", obsidian]] +} +server2 { + input: [[obsidian, "oc:craftingRAMTier4", obsidian] ["oc:circuitTier2", "oc:circuitTier3", "oc:circuitTier2"] [obsidian, "oc:craftingCircuitBoardPrinted", obsidian]] } +server3 { + input: [[obsidian, "oc:craftingRAMTier5", obsidian] + ["oc:circuitTier3", "oc:circuitTier3", "oc:circuitTier3"] + [obsidian, "oc:craftingCircuitBoardPrinted", obsidian]] +} ram1 { input: [["oc:circuitTier1", "", "oc:circuitTier1"] diff --git a/src/main/resources/assets/opencomputers/recipes/hardmode.recipes b/src/main/resources/assets/opencomputers/recipes/hardmode.recipes index 807c4327e..571ef0346 100644 --- a/src/main/resources/assets/opencomputers/recipes/hardmode.recipes +++ b/src/main/resources/assets/opencomputers/recipes/hardmode.recipes @@ -12,8 +12,18 @@ terminal { [nuggetIron, "oc:craftingKeyboard", nuggetIron]] } -server { - input: [["oc:circuitTier3", "oc:craftingRAMTier4", "oc:circuitTier3"] +server1 { + input: [["oc:circuitTier1", "oc:craftingRAMTier3", "oc:circuitTier1"] + ["oc:circuitTier2", "oc:craftingCaseTier1", "oc:circuitTier2"] + ["oc:craftingCircuitBoardPrinted", "oc:craftingCircuitBoardPrinted", "oc:craftingCircuitBoardPrinted"]] +} +server2 { + input: [["oc:circuitTier2", "oc:craftingRAMTier4", "oc:circuitTier2"] + ["oc:circuitTier3", "oc:craftingCaseTier2", "oc:circuitTier3"] + ["oc:craftingCircuitBoardPrinted", "oc:craftingCircuitBoardPrinted", "oc:craftingCircuitBoardPrinted"]] +} +server3 { + input: [["oc:circuitTier3", "oc:craftingRAMTier5", "oc:circuitTier3"] ["oc:circuitTier3", "oc:craftingCaseTier3", "oc:circuitTier3"] ["oc:craftingCircuitBoardPrinted", "oc:craftingCircuitBoardPrinted", "oc:craftingCircuitBoardPrinted"]] } diff --git a/src/main/resources/assets/opencomputers/textures/items/server.png b/src/main/resources/assets/opencomputers/textures/items/server.png deleted file mode 100644 index 5088c51d6b586ed1926dca1339d3071c2d54b3c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 517 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!h8r2#%6u2IR!94tai?CiqA!m<{!3JwaAhLUU6q{~^$iHeHK z+sOxnhd+IMIwU&g>g7FJCMMS|Z8~ybv5bsN*TjjUTB5E#KBrG^-n(U?~B){c%VcI@n)F|)X$LRMDx z*^^5`LPEE1p4hf!*~Rnw7p&jl?BgRXEnQXRAtxsno{;$e|NjFgk2?Y#Y+e%N7YyW* z0T=`#=XL{)*zD=z7*cU7%0E4gdfE diff --git a/src/main/resources/assets/opencomputers/textures/items/server0.png b/src/main/resources/assets/opencomputers/textures/items/server0.png new file mode 100644 index 0000000000000000000000000000000000000000..6c82c19ca9ae2ce038b36b9ef23cf92ef7de69c3 GIT binary patch literal 521 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!h86#+gWu2IR!94tb@!oso^vP|sk3JwaAhLRJSo8_$K&rW~poH^?1 z>eIWrX7%;$+_>?{v0x}jdl{qYG-sJbv&XA0J-J6y}LJyD=MyBKEGi725U#h6+3py%F0ShOaK4>-`nL2$fp)1L4LtN zE;)d~I!5pm(2UKVE{-7;w?a-o=W90LVM#b}P{rYtmb4f5-RjT(^25}Fw7V)U;;x@i%_#)GkwxUuo#&DJ$*qSXD=Wh`W7%<$d1HD~IaIkK{{PhRfidGKsiW22*xkkGr2m;e9&?~ripGtk+V zB|(0{KrUH;!D>ya1JIDoo-U3d6}Li8Kj&*U;9*I4)xgPkDCcI0!}oi8{!hNzdBtn* z@5jGYq?;2ZK3B#)|C;0W++ioU6w2oU4ZQ z)%DLd=NcN>Ov9$N$nViTnJT00F#Ul-Di1>kzfIN$##LF8t{pR$N$G7c^!*$r5}V%7 zd51-~X~~w{-B&gopSR#VhY_!J4~H7BW3ie6$ok_4zBVK0cyaqV|iHO`S8xd)w~Gm#@j% zId`1DwDHn)bw70=(6iG|IdD`!KtRSqX6m7ntM1&7-FHYxNQjS*Pg+{q*~h22qQctI zF+3r$@A&!auiweZ$#u_|dFamlO*ikId;UsRR@St$_vXttD|YN$uzth;|NlKN#c={% zZdDTG7YyW*2N=u`{0D{JR!u_n@LmQG1CiaP6g`{ zRyh3KweGZ}!G#6KRHuJvPS@Mnlg#=;@XgX5Muv}F?7YqmH{Zyybj(nZiYwTplf5^h zWUj5!2c;g4MTfS%bvi6<+?3;FaB;)Yh6P!iw`3bD{g|>N*B*OpQagj|-=%sM35G{L W!s Date: Sun, 9 Feb 2014 00:43:10 +0100 Subject: [PATCH 3/3] number of terminals that can be bound to a single server rack now increases with server tier (2, 4, 8 by default) --- .../java/li/cil/oc/client/GuiHandler.scala | 2 +- .../java/li/cil/oc/client/PacketHandler.scala | 8 +++--- .../li/cil/oc/common/component/Terminal.scala | 26 +++++++------------ .../java/li/cil/oc/common/item/Terminal.scala | 9 +++++-- .../java/li/cil/oc/server/PacketSender.scala | 6 ++++- .../li/cil/oc/server/component/Server.scala | 10 ++++--- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/main/java/li/cil/oc/client/GuiHandler.scala b/src/main/java/li/cil/oc/client/GuiHandler.scala index cf1236d32..7bc08bd89 100644 --- a/src/main/java/li/cil/oc/client/GuiHandler.scala +++ b/src/main/java/li/cil/oc/client/GuiHandler.scala @@ -48,7 +48,7 @@ object GuiHandler extends CommonGuiHandler { case Some(term) => def inRange = player.isEntityAlive && term.rack.getDistanceFrom(player.posX, player.posY, player.posZ) < term.rack.range * term.rack.range if (inRange) { - if (term.key.isDefined && term.key.get == key) return new gui.Screen(term.buffer, true, () => { + if (term.keys.contains(key)) return new gui.Screen(term.buffer, true, () => { // Check if someone else bound a term to our server. if (stack.getTagCompound.getString(Settings.namespace + "key") != key) { Minecraft.getMinecraft.displayGuiScreen(null) diff --git a/src/main/java/li/cil/oc/client/PacketHandler.scala b/src/main/java/li/cil/oc/client/PacketHandler.scala index 6a3b79ad8..e397328fb 100644 --- a/src/main/java/li/cil/oc/client/PacketHandler.scala +++ b/src/main/java/li/cil/oc/client/PacketHandler.scala @@ -79,9 +79,11 @@ class PacketHandler extends CommonPacketHandler { else { t.setRunning(number, p.readBoolean()) t.sides(number) = p.readDirection() - val key = p.readUTF() - if (key != "") { - t.terminals(number).key = Option(key) + val keyCount = p.readInt() + val keys = t.terminals(number).keys + keys.clear() + for (i <- 0 until keyCount) { + keys += p.readUTF() } } case _ => // Invalid packet. diff --git a/src/main/java/li/cil/oc/common/component/Terminal.scala b/src/main/java/li/cil/oc/common/component/Terminal.scala index cdebbf1e4..5d26b21f6 100644 --- a/src/main/java/li/cil/oc/common/component/Terminal.scala +++ b/src/main/java/li/cil/oc/common/component/Terminal.scala @@ -10,7 +10,8 @@ import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.PackedColor.Depth import li.cil.oc.{Items, Settings, common} import net.minecraft.entity.player.EntityPlayer -import net.minecraft.nbt.NBTTagCompound +import net.minecraft.nbt.{NBTTagString, NBTTagCompound} +import scala.collection.mutable class Terminal(val rack: tileentity.Rack, val number: Int) extends Buffer.Owner { val buffer = new common.component.Buffer(this) @@ -22,8 +23,7 @@ class Terminal(val rack: tileentity.Rack, val number: Int) extends Buffer.Owner override def isUseableByPlayer(p: EntityPlayer) = { val stack = p.getCurrentEquippedItem Items.multi.subItem(stack) match { - case Some(t: item.Terminal) if key.isDefined && stack.hasTagCompound => - key.get == stack.getTagCompound.getString(Settings.namespace + "key") + case Some(t: item.Terminal) if stack.hasTagCompound => keys.contains(stack.getTagCompound.getString(Settings.namespace + "key")) case _ => false } } @@ -31,7 +31,7 @@ class Terminal(val rack: tileentity.Rack, val number: Int) extends Buffer.Owner } else null - var key: Option[String] = None + val keys = mutable.ListBuffer.empty[String] def isServer = rack.isServer @@ -48,34 +48,28 @@ class Terminal(val rack: tileentity.Rack, val number: Int) extends Buffer.Owner def load(nbt: NBTTagCompound) { buffer.load(nbt.getCompoundTag(Settings.namespace + "buffer")) keyboard.load(nbt.getCompoundTag(Settings.namespace + "keyboard")) + // Compatibility for previous dev versions where there was only one term. if (nbt.hasKey(Settings.namespace + "key")) { - key = Option(nbt.getString(Settings.namespace + "key")) + keys += nbt.getString(Settings.namespace + "key") } + nbt.getTagList(Settings.namespace + "keys").foreach[NBTTagString](keys += _.data) } def save(nbt: NBTTagCompound) { nbt.setNewCompoundTag(Settings.namespace + "buffer", buffer.save) nbt.setNewCompoundTag(Settings.namespace + "keyboard", keyboard.save) - key match { - case Some(value) => nbt.setString(Settings.namespace + "key", value) - case _ => - } + nbt.setNewTagList("keys", keys) } @SideOnly(Side.CLIENT) def readFromNBTForClient(nbt: NBTTagCompound) { buffer.buffer.load(nbt) - if (nbt.hasKey("key")) { - key = Option(nbt.getString("key")) - } + nbt.getTagList("keys").foreach[NBTTagString](keys += _.data) } def writeToNBTForClient(nbt: NBTTagCompound) { buffer.buffer.save(nbt) - key match { - case Some(value) => nbt.setString("key", value) - case _ => - } + nbt.setNewTagList("keys", keys) } // ----------------------------------------------------------------------- // diff --git a/src/main/java/li/cil/oc/common/item/Terminal.scala b/src/main/java/li/cil/oc/common/item/Terminal.scala index 10c4c5349..cf62e077f 100644 --- a/src/main/java/li/cil/oc/common/item/Terminal.scala +++ b/src/main/java/li/cil/oc/common/item/Terminal.scala @@ -58,11 +58,16 @@ class Terminal(val parent: Delegator) extends Delegate { if (!world.isRemote) { rack.servers(slot) match { case Some(server) => + val key = UUID.randomUUID().toString + val keys = rack.terminals(slot).keys if (!stack.hasTagCompound) { stack.setTagCompound(new NBTTagCompound("tag")) } - val key = UUID.randomUUID().toString - rack.terminals(slot).key = Some(key) + else { + keys -= stack.getTagCompound.getString(Settings.namespace + "key") + } + keys.remove(0, math.max(0, 1 + keys.length - Settings.get.terminalsPerTier(server.tier))) + keys += key ServerPacketSender.sendServerState(rack, slot) stack.getTagCompound.setString(Settings.namespace + "key", key) stack.getTagCompound.setString(Settings.namespace + "server", server.machine.node.address) diff --git a/src/main/java/li/cil/oc/server/PacketSender.scala b/src/main/java/li/cil/oc/server/PacketSender.scala index 45263b141..2e4ee1aaa 100644 --- a/src/main/java/li/cil/oc/server/PacketSender.scala +++ b/src/main/java/li/cil/oc/server/PacketSender.scala @@ -317,7 +317,11 @@ object PacketSender { pb.writeInt(number) pb.writeBoolean(t.isRunning(number)) pb.writeDirection(t.sides(number)) - pb.writeUTF(t.terminals(number).key.getOrElse("")) + val keys = t.terminals(number).keys + pb.writeInt(keys.length) + for (key <- keys) { + pb.writeUTF(key) + } player match { case Some(p) => pb.sendToPlayer(p) diff --git a/src/main/java/li/cil/oc/server/component/Server.scala b/src/main/java/li/cil/oc/server/component/Server.scala index eb1c3a5bd..5e74fa0b0 100644 --- a/src/main/java/li/cil/oc/server/component/Server.scala +++ b/src/main/java/li/cil/oc/server/component/Server.scala @@ -18,6 +18,11 @@ class Server(val rack: tileentity.Rack, val number: Int) extends Machine.Owner { val inventory = new NetworkedInventory() + def tier = Items.multi.subItem(rack.getStackInSlot(number)) match { + case Some(server: item.Server) => server.tier + case _ => 0 + } + // ----------------------------------------------------------------------- // override def address() = machine.node.address @@ -92,10 +97,7 @@ class Server(val rack: tileentity.Rack, val number: Int) extends Machine.Owner { } } - override def tier = Items.multi.subItem(container) match { - case Some(server: item.Server) => server.tier - case _ => 0 - } + override def tier = Server.this.tier var containerOverride: ItemStack = _