Skip to content

Commit

Permalink
Remove stale subscribers from channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Beachman4 committed Jan 30, 2023
1 parent 75f4e3b commit 90bdcb9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ configure<UserDevExtension> {

}
create("server") {
workingDirectory(project.file("run"))
workingDirectory(project.file("run-server"))

property("forge.logging.markers", "REGISTRIES")
property("forge.logging.console.level", "debug")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import appeng.api.networking.*
import appeng.api.util.AECableType
import appeng.me.helpers.BlockEntityNodeListener
import appeng.me.helpers.IGridConnectedBlockEntity
import com.the9grounds.aeadditions.Logger
import com.the9grounds.aeadditions.core.AEAConfig
import com.the9grounds.aeadditions.menu.MEWirelessTransceiverMenu
import com.the9grounds.aeadditions.registries.BlockEntities
Expand Down Expand Up @@ -86,6 +87,8 @@ class MEWirelessTransceiverBlockEntity(pos: BlockPos, blockState: BlockState) :

currentChannel = channel

channel.checkSubscribers()

setupLinks()
setChanged()
}
Expand All @@ -98,6 +101,7 @@ class MEWirelessTransceiverBlockEntity(pos: BlockPos, blockState: BlockState) :
val alreadyExists = channel.subscribers.find { it == this } != null

if (!alreadyExists) {
channel.checkSubscribers()
channel.subscribers.add(this)

currentChannel = channel
Expand All @@ -119,10 +123,14 @@ class MEWirelessTransceiverBlockEntity(pos: BlockPos, blockState: BlockState) :
subscriber.connection?.destroy()
subscriber.connection = null
}
val connection = GridHelper.createGridConnection(getGridNode(null), subscriber.getGridNode(null))
subscriber.connection = connection
connections.add(connection)
localIdleDraw += AEAConfig.meWirelessTransceiverDistanceMultiplier * blockPos.distSqr(subscriber.blockPos)
try {
val connection = GridHelper.createGridConnection(getGridNode(null), subscriber.getGridNode(null))
subscriber.connection = connection
connections.add(connection)
localIdleDraw += AEAConfig.meWirelessTransceiverDistanceMultiplier * blockPos.distSqr(subscriber.blockPos)
} catch (e: Exception) {
Logger.info(e)
}
}
}
idleDraw = localIdleDraw
Expand Down Expand Up @@ -231,7 +239,7 @@ class MEWirelessTransceiverBlockEntity(pos: BlockPos, blockState: BlockState) :
return null
}

if (_mainGridNode.node == null) {
if (!_mainGridNode.isReady) {
_mainGridNode.create(level, blockPos)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ object BlockEntityProvider : IProbeInfoProvider {
blockState: BlockState?,
hitdata: IProbeHitData?
) {
val blockEntity = level!!.getBlockEntity(hitdata!!.pos)

when(blockEntity) {
when(val blockEntity = level!!.getBlockEntity(hitdata!!.pos)) {
is MEWirelessTransceiverBlockEntity -> blockEntity.addProbeInfo(blockEntity, mode, info, player, level, blockState, hitdata)
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/the9grounds/aeadditions/util/Channel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ data class Channel(val channelInfo: ChannelInfo, var broadcaster: MEWirelessTran
return tag
}

// Check if subscribers are removed and remove them from the array
fun checkSubscribers() {
subscribers.removeAll { it.isRemoved }
}

fun hasAccessTo(player: ServerPlayer): Boolean {
return channelInfo.hasAccessTo(player)
}
Expand Down

0 comments on commit 90bdcb9

Please sign in to comment.