diff --git a/src/main/kotlin/net/shadowfacts/phycon/network/block/networkinterface/NetworkInterfaceBlockEntity.kt b/src/main/kotlin/net/shadowfacts/phycon/network/block/networkinterface/NetworkInterfaceBlockEntity.kt index 9a8a221..ff1a976 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/network/block/networkinterface/NetworkInterfaceBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/network/block/networkinterface/NetworkInterfaceBlockEntity.kt @@ -19,6 +19,7 @@ class NetworkInterfaceBlockEntity: DeviceBlockEntity(PhyBlockEntities.NETWORK_IN private val facing: Direction get() = world!!.getBlockState(pos)[NetworkInterfaceBlock.FACING] + // todo: should this be a weak ref? private var inventory: GroupedItemInv? = null fun updateInventory() { @@ -46,6 +47,10 @@ class NetworkInterfaceBlockEntity: DeviceBlockEntity(PhyBlockEntities.NETWORK_IN } fun readAll(): Map { + // if we don't have an inventory, try to get one + // this happens when readAll is called before a neighbor state changes, such as immediately after world load + if (inventory == null) updateInventory() + return inventory?.let { it.storedStacks.associateWith(it::getAmount) } ?: mapOf()