From 59689011a158bc62418466798499d90103e2e4f0 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 25 Feb 2023 17:59:24 +0700 Subject: [PATCH] Fix soft deadlock in storage interfaces --- .../block/entity/storage/StorageInterfaces.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt index fe8120e81..ec4d9b8b9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt @@ -36,6 +36,7 @@ import ru.dbotthepony.mc.otm.graph.storage.BasicStorageGraphNode import ru.dbotthepony.mc.otm.graph.storage.StorageNetworkGraph import ru.dbotthepony.mc.otm.menu.storage.StorageExporterMenu import ru.dbotthepony.mc.otm.menu.storage.StorageImporterMenu +import ru.dbotthepony.mc.otm.once import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MNames import ru.dbotthepony.mc.otm.storage.IStorageEventConsumer @@ -63,17 +64,25 @@ abstract class AbstractStorageImportExport( val cell: BasicStorageGraphNode = object : BasicStorageGraphNode(energy), GraphNodeListener { override fun onNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = this@AbstractStorageImportExport.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, true) + level?.once { + if (!isRemoved) { + val newState = this@AbstractStorageImportExport.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, true) - if (newState !== this@AbstractStorageImportExport.blockState && SERVER_IS_LIVE) - level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) + if (newState !== this@AbstractStorageImportExport.blockState && SERVER_IS_LIVE) + level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) + } + } } override fun onUnNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = this@AbstractStorageImportExport.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, false) + level?.once { + if (!isRemoved) { + val newState = this@AbstractStorageImportExport.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, false) - if (newState !== this@AbstractStorageImportExport.blockState && SERVER_IS_LIVE) - level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) + if (newState !== this@AbstractStorageImportExport.blockState && SERVER_IS_LIVE) + level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) + } + } } }