Fixes #4213: Prevent NPE when inserting via conversion monitor (#4265)

This commit is contained in:
yueh
2020-01-26 13:36:06 +01:00
committed by GitHub
parent d5fc7a5b21
commit 1fc1d5517d
@@ -179,25 +179,29 @@ public class PartConversionMonitor extends AbstractPartMonitor
final IEnergySource energy = this.getProxy().getEnergy(); final IEnergySource energy = this.getProxy().getEnergy();
final IMEMonitor<IAEItemStack> cell = this.getProxy() final IMEMonitor<IAEItemStack> cell = this.getProxy()
.getStorage() .getStorage()
.getInventory( .getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( allItems ) if( allItems )
{ {
final IAEItemStack input = this.getDisplayed().copy(); if( this.getDisplayed() != null )
IItemHandler inv = new PlayerMainInvWrapper( player.inventory );
for( int x = 0; x < inv.getSlots(); x++ )
{ {
final ItemStack targetStack = inv.getStackInSlot( x ); final IAEItemStack input = this.getDisplayed().copy();
if( input.equals( targetStack ) ) IItemHandler inv = new PlayerMainInvWrapper( player.inventory );
for( int x = 0; x < inv.getSlots(); x++ )
{ {
final ItemStack canExtract = inv.extractItem( x, targetStack.getCount(), true ); final ItemStack targetStack = inv.getStackInSlot( x );
if( !canExtract.isEmpty() ) if( input.equals( targetStack ) )
{ {
input.setStackSize( canExtract.getCount() ); final ItemStack canExtract = inv.extractItem( x, targetStack.getCount(), true );
final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) ); if( !canExtract.isEmpty() )
inv.extractItem( x, failedToInsert == null ? canExtract.getCount() : canExtract.getCount() - (int) failedToInsert.getStackSize(), {
false ); input.setStackSize( canExtract.getCount() );
final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) );
inv.extractItem( x,
failedToInsert == null ? canExtract.getCount() : canExtract.getCount() - (int) failedToInsert.getStackSize(),
false );
}
} }
} }
} }