Add block entity sync backlog handling
This commit is contained in:
parent
c04830a3bb
commit
bf450e2ff9
@ -535,6 +535,8 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
waitForServerLevel.forEach { it.invoke() }
|
waitForServerLevel.forEach { it.invoke() }
|
||||||
} else {
|
} else {
|
||||||
waitForServerLevel.clear()
|
waitForServerLevel.clear()
|
||||||
|
|
||||||
|
BlockEntitySyncPacket.applyBacklog(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +69,7 @@ class BlockEntitySyncPacket(val position: BlockPos, val buffer: ByteArray, val v
|
|||||||
val blockEntity = level.getBlockEntity(position)
|
val blockEntity = level.getBlockEntity(position)
|
||||||
|
|
||||||
if (blockEntity == null) {
|
if (blockEntity == null) {
|
||||||
LOGGER.warn("Putting BlockEntitySyncPacket received for $position into backlog because there is literally no block entity there!")
|
LOGGER.warn("Putting BlockEntitySyncPacket received for $position into backlog because there is literally no block entity there! This is CERTAINLY a bug in one of optimizing mods you have or server has installed! This might cause memory leak.")
|
||||||
LOGGER.warn("This is CERTAINLY a bug in one of optimizing mods you have or server has installed!")
|
|
||||||
LOGGER.warn("This can cause memory leak.")
|
|
||||||
|
|
||||||
backlog.computeIfAbsent(level) { Object2ObjectOpenHashMap() }
|
backlog.computeIfAbsent(level) { Object2ObjectOpenHashMap() }
|
||||||
.computeIfAbsent(position, Object2ObjectFunction { ArrayList() })
|
.computeIfAbsent(position, Object2ObjectFunction { ArrayList() })
|
||||||
@ -88,6 +86,8 @@ class BlockEntitySyncPacket(val position: BlockPos, val buffer: ByteArray, val v
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (packets != null) {
|
if (packets != null) {
|
||||||
|
LOGGER.info("Unfolding ${packets.size} backlog packets for $position (${level.getBlockState(position)}/$blockEntity)")
|
||||||
|
|
||||||
for (packet in packets) {
|
for (packet in packets) {
|
||||||
blockEntity.synchronizer.read(FastByteArrayInputStream(packet.buffer, 0, packet.validBytes))
|
blockEntity.synchronizer.read(FastByteArrayInputStream(packet.buffer, 0, packet.validBytes))
|
||||||
}
|
}
|
||||||
@ -115,6 +115,22 @@ class BlockEntitySyncPacket(val position: BlockPos, val buffer: ByteArray, val v
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val LOGGER = LogManager.getLogger()
|
private val LOGGER = LogManager.getLogger()
|
||||||
|
|
||||||
|
internal fun applyBacklog(blockEntity: MatteryBlockEntity) {
|
||||||
|
val packets = backlog[blockEntity.level]?.remove(blockEntity.blockPos)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (packets != null) {
|
||||||
|
LOGGER.info("Unfolding ${packets.size} backlog packets for ${blockEntity.blockPos} (${blockEntity.level!!.getBlockState(blockEntity.blockPos)}/$blockEntity)")
|
||||||
|
|
||||||
|
for (packet in packets) {
|
||||||
|
blockEntity.synchronizer.read(FastByteArrayInputStream(packet.buffer, 0, packet.validBytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(err: Throwable) {
|
||||||
|
LOGGER.error("Exception while reading synchronized BlockEntity data!\nPosition: ${blockEntity.blockPos}\nBlock: ${blockEntity.level!!.getBlockState(blockEntity.blockPos)}\nBlock entity: $blockEntity", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user