From fa7c499f29ebc59747e9be3970ef2e492d34e1d5 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 26 Oct 2019 22:06:00 -0400 Subject: [PATCH] Fix Interfaces not reading inventory contents immediately on world load This happened because the after a world load, there was no neighbor change to trigger an inventory update. --- .../block/networkinterface/NetworkInterfaceBlockEntity.kt | 5 +++++ 1 file changed, 5 insertions(+) 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()