Power mountables without requiring them to be connected to the outside. Closes #2020.

This commit is contained in:
Florian Nücke 2016-09-18 19:39:35 +02:00
parent 7d6da949de
commit c2a79a19eb

View File

@ -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()