Fix P2P receiver constantly flooding network with request inventory packets
This commit is contained in:
parent
73de26387a
commit
b64a05e0ad
|
@ -38,6 +38,8 @@ class P2PReceiverBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntit
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val REQUEST_INVENTORY_TIMEOUT: Long = 100 // ticks
|
||||||
|
|
||||||
fun provideItemStorage(be: P2PReceiverBlockEntity, side: Direction): Storage<ItemVariant>? {
|
fun provideItemStorage(be: P2PReceiverBlockEntity, side: Direction): Storage<ItemVariant>? {
|
||||||
if (side == be.cachedState[FaceDeviceBlock.FACING]) {
|
if (side == be.cachedState[FaceDeviceBlock.FACING]) {
|
||||||
return be.getTargetInventory()
|
return be.getTargetInventory()
|
||||||
|
@ -48,6 +50,7 @@ class P2PReceiverBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntit
|
||||||
|
|
||||||
var target: IPAddress? = null
|
var target: IPAddress? = null
|
||||||
var status = Status.NO_TARGET
|
var status = Status.NO_TARGET
|
||||||
|
private var requestTimestamp: Long = 0
|
||||||
|
|
||||||
var clientObserver: (() -> Unit)? = null
|
var clientObserver: (() -> Unit)? = null
|
||||||
|
|
||||||
|
@ -80,7 +83,9 @@ class P2PReceiverBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntit
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (targetInventory?.get() == null) {
|
if (targetInventory?.get() == null && (counter - requestTimestamp) >= REQUEST_INVENTORY_TIMEOUT) {
|
||||||
|
status = Status.WAITING_FOR_RESPONSE
|
||||||
|
requestTimestamp = counter
|
||||||
sendPacket(RequestInventoryPacket(RequestInventoryPacket.Kind.SIDED, ipAddress, target!!))
|
sendPacket(RequestInventoryPacket(RequestInventoryPacket.Kind.SIDED, ipAddress, target!!))
|
||||||
}
|
}
|
||||||
return targetInventory?.get()
|
return targetInventory?.get()
|
||||||
|
|
Loading…
Reference in New Issue