Merge branch 'master-MC1.11' into master-MC1.12

This commit is contained in:
payonel 2019-06-11 17:07:08 -07:00
commit 42fa189475
2 changed files with 27 additions and 10 deletions

View File

@ -125,12 +125,7 @@ class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalance
}
}
// ----------------------------------------------------------------------- //
// Hub
override protected def relayPacket(sourceSide: Option[EnumFacing], packet: Packet): Unit = {
if (isRelayEnabled) super.relayPacket(sourceSide, packet)
protected def sendPacketToMountables(sourceSide: Option[EnumFacing], packet: Packet): Unit = {
// When a message arrives on a bus, also send it to all secondary nodes
// connected to it. Only deliver it to that very node, if it's not the
// sender, to avoid loops.
@ -152,6 +147,22 @@ class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalance
}
}
// ----------------------------------------------------------------------- //
// Hub
override def tryEnqueuePacket(sourceSide: Option[EnumFacing], packet: Packet): Boolean = {
sendPacketToMountables(sourceSide, packet)
if (isRelayEnabled)
super.tryEnqueuePacket(sourceSide, packet)
else
true
}
override protected def relayPacket(sourceSide: Option[EnumFacing], packet: Packet): Unit = {
if (isRelayEnabled)
super.relayPacket(sourceSide, packet)
}
override protected def onPlugConnect(plug: Plug, node: Node): Unit = {
super.onPlugConnect(plug, node)
connectComponents()

View File

@ -69,8 +69,9 @@ trait Hub extends traits.Environment with SidedEnvironment with Tickable {
else {
relayCooldown = -1
if (queue.nonEmpty) queue.synchronized {
packetsPerCycleAvg += queue.size
for (i <- 0 until math.min(queue.size, relayAmount)) {
val packetsToRely = math.min(queue.size, relayAmount)
packetsPerCycleAvg += packetsToRely
for (i <- 0 until packetsToRely) {
val (sourceSide, packet) = queue.dequeue()
relayPacket(sourceSide, packet)
}
@ -96,8 +97,13 @@ trait Hub extends traits.Environment with SidedEnvironment with Tickable {
}
protected def relayPacket(sourceSide: Option[EnumFacing], packet: Packet) {
for (side <- EnumFacing.values if Option(side) != sourceSide && sidedNode(side) != null) {
sidedNode(side).sendToReachable("network.message", packet)
for (side <- EnumFacing.values) {
if (sourceSide.isEmpty || sourceSide.get != side) {
val node = sidedNode(side)
if (node != null) {
node.sendToReachable("network.message", packet)
}
}
}
}