Add more checks to prevent NPEs in the AE inventory handler.