made relay no longer violate physics
This commit is contained in:
@@ -10,6 +10,7 @@ import net.minecraft.network.chat.Component
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.world.ContainerHelper
|
||||
import net.minecraft.world.Containers
|
||||
import net.minecraft.world.InteractionResult
|
||||
import net.minecraft.world.MenuProvider
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
@@ -60,6 +61,7 @@ class RelayEntity(blockPos: BlockPos, blockState: BlockState): SingleDeviceBlock
|
||||
fun computeRelayCapacity(): Int = computeRelayBufferSize() + computeRelayQueueSize()
|
||||
|
||||
val queue = mutableListOf<Networking.ClassicPacket>()
|
||||
val justReceived = mutableListOf<Networking.ClassicPacket>()
|
||||
var activityTickLeft = 0
|
||||
var ticksUntilQueue = 0
|
||||
|
||||
@@ -68,8 +70,8 @@ class RelayEntity(blockPos: BlockPos, blockState: BlockState): SingleDeviceBlock
|
||||
override fun received(message: Networking.Message) {
|
||||
super.received(message)
|
||||
if(message.sender == this) return
|
||||
if(message is Networking.ClassicPacket && message.hopCount < 5 && queue.size < computeRelayCapacity()) {
|
||||
queue.addLast(message)
|
||||
if(message is Networking.ClassicPacket && message.hopCount < 5 && (queue.size + justReceived.size) < computeRelayCapacity()) {
|
||||
justReceived.addLast(message)
|
||||
activityTickLeft = 20
|
||||
markChanged()
|
||||
}
|
||||
@@ -80,7 +82,7 @@ class RelayEntity(blockPos: BlockPos, blockState: BlockState): SingleDeviceBlock
|
||||
buf.writeVarInt(computeRelayInterval())
|
||||
buf.writeVarInt(computeRelayBufferSize())
|
||||
buf.writeVarInt(computeRelayQueueSize())
|
||||
buf.writeVarInt(queue.size)
|
||||
buf.writeVarInt(queue.size + justReceived.size)
|
||||
}
|
||||
|
||||
override fun writeFullStateCommit(buf: FriendlyByteBuf) {
|
||||
@@ -120,6 +122,10 @@ class RelayEntity(blockPos: BlockPos, blockState: BlockState): SingleDeviceBlock
|
||||
activityTickLeft--
|
||||
deviceNode.markChanged()
|
||||
}
|
||||
queue.addAll(justReceived)
|
||||
justReceived.clear()
|
||||
val cap = computeRelayCapacity()
|
||||
while(queue.size > cap) queue.removeLast()
|
||||
ticksUntilQueue--
|
||||
if(ticksUntilQueue <= 0) {
|
||||
ticksUntilQueue = computeRelayInterval()
|
||||
@@ -129,8 +135,6 @@ class RelayEntity(blockPos: BlockPos, blockState: BlockState): SingleDeviceBlock
|
||||
}
|
||||
}
|
||||
deviceNode.markChanged()
|
||||
val cap = computeRelayCapacity()
|
||||
while(queue.size > cap) queue.removeLast()
|
||||
}
|
||||
|
||||
override fun getMachineBlockPosition() = blockPos!!
|
||||
@@ -176,4 +180,15 @@ class RelayBlock: DeviceBlock(Properties.of().sound(SoundType.METAL)) {
|
||||
}
|
||||
return InteractionResult.SUCCESS
|
||||
}
|
||||
|
||||
override fun onRemove(
|
||||
blockState: BlockState,
|
||||
level: Level,
|
||||
blockPos: BlockPos,
|
||||
blockState2: BlockState,
|
||||
bl: Boolean
|
||||
) {
|
||||
Containers.dropContentsOnDestroy(blockState, blockState2, level, blockPos)
|
||||
super.onRemove(blockState, level, blockPos, blockState2, bl)
|
||||
}
|
||||
}
|
||||
@@ -150,9 +150,9 @@ open class DeviceNode(_address: UUID? = null) {
|
||||
|
||||
fun getReachable(): Set<DeviceNode> {
|
||||
if(reachableCache == null) {
|
||||
reachableCache = computeReachable();
|
||||
reachableCache = computeReachable()
|
||||
}
|
||||
return reachableCache!!;
|
||||
return reachableCache!!
|
||||
}
|
||||
|
||||
open fun invalidateReachableCache() {
|
||||
@@ -165,21 +165,21 @@ open class DeviceNode(_address: UUID? = null) {
|
||||
|
||||
fun computeReachable(): Set<DeviceNode> {
|
||||
if(reachability == Visibility.NONE) {
|
||||
return setOf();
|
||||
return setOf()
|
||||
}
|
||||
if(reachability == Visibility.SOME) {
|
||||
return getPreferredFew()
|
||||
}
|
||||
if(reachability == Visibility.DIRECT) {
|
||||
return connections.minus(this);
|
||||
return connections.minus(this)
|
||||
}
|
||||
if(reachability == Visibility.NETWORK) {
|
||||
// absolute cinema
|
||||
val working = HashSet<DeviceNode>();
|
||||
val pending = mutableListOf(this);
|
||||
var iterCount = 0;
|
||||
val working = HashSet<DeviceNode>()
|
||||
val pending = mutableListOf(this)
|
||||
var iterCount = 0
|
||||
while(iterCount < maxHopCount && pending.isNotEmpty()) {
|
||||
iterCount++;
|
||||
iterCount++
|
||||
val subnode = pending.removeFirst()
|
||||
if(subnode in working) continue
|
||||
working.add(subnode)
|
||||
@@ -192,20 +192,20 @@ open class DeviceNode(_address: UUID? = null) {
|
||||
}
|
||||
}
|
||||
// cannot send to itself!
|
||||
working.remove(this);
|
||||
return working;
|
||||
working.remove(this)
|
||||
return working
|
||||
}
|
||||
throw NotImplementedError("visibility not implemented");
|
||||
throw NotImplementedError("visibility not implemented")
|
||||
}
|
||||
|
||||
fun connectTo(other: DeviceNode) {
|
||||
this.directConnectTo(other);
|
||||
other.directConnectTo(this);
|
||||
this.directConnectTo(other)
|
||||
other.directConnectTo(this)
|
||||
}
|
||||
|
||||
fun disconnectFrom(other: DeviceNode) {
|
||||
this.directDisconnectFrom(other);
|
||||
other.directDisconnectFrom(this);
|
||||
this.directDisconnectFrom(other)
|
||||
other.directDisconnectFrom(this)
|
||||
}
|
||||
|
||||
fun directConnectTo(other: DeviceNode) {
|
||||
|
||||
Reference in New Issue
Block a user