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.
This commit is contained in:
Shadowfacts 2019-10-26 22:06:00 -04:00
parent 19c035495c
commit fa7c499f29
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 5 additions and 0 deletions

View File

@ -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<ItemStack, Int> {
// 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()