From c2a79a19eb1cf82600ef07ca47fc7333ede0c4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 18 Sep 2016 19:39:35 +0200 Subject: [PATCH] Power mountables without requiring them to be connected to the outside. Closes #2020. --- .../li/cil/oc/common/tileentity/Rack.scala | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Rack.scala b/src/main/scala/li/cil/oc/common/tileentity/Rack.scala index 2d1465e08..bf7ba7f26 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Rack.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Rack.scala @@ -383,15 +383,33 @@ class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalance override def updateEntity() { super.updateEntity() if (isServer && isConnected) { + lazy val connectors = ForgeDirection.VALID_DIRECTIONS.map(sidedNode).collect { + case connector: Connector => connector + } components.zipWithIndex.collect { - case (Some(mountable: RackMountable), slot) if hasChanged(slot) => - hasChanged(slot) = false - lastData(slot) = mountable.getData - ServerPacketSender.sendRackMountableData(this, slot) - world.notifyBlocksOfNeighborChange(x, y, z, block) - // These are working state dependent, so recompute them. - isOutputEnabled = hasRedstoneCard - isAbstractBusAvailable = hasAbstractBusCard + case (Some(mountable: RackMountable), slot) => + if (hasChanged(slot)) { + hasChanged(slot) = false + lastData(slot) = mountable.getData + ServerPacketSender.sendRackMountableData(this, slot) + world.notifyBlocksOfNeighborChange(x, y, z, block) + // These are working state dependent, so recompute them. + isOutputEnabled = hasRedstoneCard + isAbstractBusAvailable = hasAbstractBusCard + } + + // Power mountables without requiring them to be connected to the outside. + mountable.node match { + case connector: Connector => + var remaining = Settings.get.serverRackRate + for (outside <- connectors if remaining > 0) { + val received = remaining + outside.changeBuffer(-remaining) + val rejected = connector.changeBuffer(received) + outside.changeBuffer(rejected) + remaining -= received - rejected + } + case _ => // Nothing using energy. + } } updateComponents()