Add Config to Remove Crashing Items from Storage Cells (#2573)

Added a configuration option to enable players to recover their world if any of their items in storage cause crashes on load.
This commit is contained in:
shartte
2016-11-05 13:50:54 +01:00
committed by GitHub
parent b3560aaa00
commit 4253d659f1
2 changed files with 53 additions and 11 deletions
@@ -41,6 +41,8 @@ import appeng.api.storage.ISaveProvider;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
@@ -442,23 +444,60 @@ public class CellInventory implements ICellInventory
final int types = (int) this.getStoredItemTypes();
for( int x = 0; x < types; x++ )
for( int slot = 0; slot < types; slot++ )
{
final ItemStack t = ItemStack.loadItemStackFromNBT( this.tagCompound.getCompoundTag( itemSlots[x] ) );
if( t != null )
{
t.stackSize = this.tagCompound.getInteger( itemSlotCount[x] );
if( t.stackSize > 0 )
{
this.cellItems.add( AEItemStack.create( t ) );
}
}
NBTTagCompound compoundTag = this.tagCompound.getCompoundTag( itemSlots[slot] );
int stackSize = this.tagCompound.getInteger( itemSlotCount[slot] );
loadCellItem( compoundTag, stackSize );
}
// cellItems.clean();
}
private void loadCellItem( NBTTagCompound compoundTag, int stackSize )
{
// Now load the item stack
final ItemStack t;
try
{
t = ItemStack.loadItemStackFromNBT( compoundTag );
if( t == null )
{
AELog.warn( "Removing item " + compoundTag + " from storage cell because the associated item type couldn't be found." );
return;
}
}
catch( Throwable ex )
{
if( AEConfig.instance.removeCrashingItemsOnLoad )
{
AELog.warn( ex, "Removing item " + compoundTag + " from storage cell because loading the ItemStack crashed." );
return;
}
throw ex;
}
t.stackSize = stackSize;
if( t.stackSize > 0 )
{
try
{
this.cellItems.add( AEItemStack.create( t ) );
}
catch( Throwable ex )
{
if( AEConfig.instance.removeCrashingItemsOnLoad )
{
AELog.warn( ex, "Removing item " + t + " from storage cell because processing the loaded item crashed." );
return;
}
throw ex;
}
}
}
@Override
public IItemList getAvailableItems( final IItemList out )
{