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:
parent
19c035495c
commit
fa7c499f29
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue