Performance improvements for saveChanges() and ICellInventory (#3586)

API break!
Fixes #3553
This commit is contained in:
fscan
2018-07-14 16:53:49 +02:00
committed by GitHub
parent 71a9bb2532
commit e809c688df
37 changed files with 292 additions and 166 deletions
@@ -52,12 +52,12 @@ public interface ICellHandler
* *
* @param is a storage cell item. * @param is a storage cell item.
* @param host anytime the contents of your storage cell changes it should use this to request a save, please * @param host anytime the contents of your storage cell changes it should use this to request a save, please
* note, this value can be null. * note, this value can be null. If provided, the host is responsible for persisting the cell content.
* @param channel the storage channel requested. * @param channel the storage channel requested.
* *
* @return a new IMEHandler for the provided item * @return a new IMEHandler for the provided item
*/ */
<T extends IAEStack<T>> IMEInventoryHandler<T> getCellInventory( ItemStack is, ISaveProvider host, IStorageChannel<T> channel ); <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( ItemStack is, ISaveProvider host, IStorageChannel<T> channel );
/** /**
* Called when the storage cell is planed in an ME Chest and the user tries to open the terminal side, if your item * Called when the storage cell is planed in an ME Chest and the user tries to open the terminal side, if your item
@@ -118,4 +118,9 @@ public interface ICellInventory<T extends IAEStack<T>> extends IMEInventory<T>
* @return the status number for this drive. * @return the status number for this drive.
*/ */
int getStatusForCell(); int getStatusForCell();
/**
* Tells the cell to persist to NBT
*/
void persist();
} }
@@ -34,7 +34,7 @@ public interface ICellInventoryHandler<T extends IAEStack<T>> extends IMEInvento
/** /**
* @return get access to the Cell Inventory. * @return get access to the Cell Inventory.
*/ */
ICellInventory getCellInv(); ICellInventory<T> getCellInv();
boolean isPreformatted(); boolean isPreformatted();
@@ -77,11 +77,11 @@ public interface ICellRegistry
* returns an IMEInventoryHandler for the provided item. * returns an IMEInventoryHandler for the provided item.
* *
* @param is item with inventory handler * @param is item with inventory handler
* @param host can be null, or the hosting tile / part. * @param host can be null. If provided, the host is responsible for persisting the cell content.
* @param chan the storage channel to request the handler for. * @param chan the storage channel to request the handler for.
* *
* @return new IMEInventoryHandler, or null if there isn't one. * @return new IMEInventoryHandler, or null if there isn't one.
*/ */
@Nullable @Nullable
<T extends IAEStack<T>> IMEInventoryHandler<T> getCellInventory( ItemStack is, ISaveProvider host, IStorageChannel<T> chan ); <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( ItemStack is, ISaveProvider host, IStorageChannel<T> chan );
} }
@@ -24,8 +24,11 @@
package appeng.api.storage; package appeng.api.storage;
/**
* Tells the cell provider that changes have been made an the cell must be persisted
*
*/
public interface ISaveProvider public interface ISaveProvider
{ {
void saveChanges( ICellInventory<?> cellInventory );
void saveChanges( IMEInventory<?> cellInventory );
} }
@@ -51,11 +51,11 @@ public class BasicItemCellHandler implements ICellHandler
} }
@Override @Override
public <T extends IAEStack<T>> IMEInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> channel ) public <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> channel )
{ {
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{ {
return ItemCellInventory.getCell( is, container ); return (ICellInventoryHandler<T>) ItemCellInventory.getCell( is, container );
} }
return null; return null;
@@ -28,8 +28,8 @@ import com.google.common.base.Verify;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import appeng.api.storage.ICellHandler; import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.ICellRegistry; import appeng.api.storage.ICellRegistry;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider; import appeng.api.storage.ISaveProvider;
import appeng.api.storage.IStorageChannel; import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IAEStack;
@@ -92,7 +92,7 @@ public class CellRegistry implements ICellRegistry
} }
@Override @Override
public <T extends IAEStack<T>> IMEInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> chan ) public <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> chan )
{ {
if( is.isEmpty() ) if( is.isEmpty() )
{ {
@@ -26,6 +26,7 @@ import net.minecraft.tileentity.TileEntity;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.implementations.tiles.IChestOrDrive; import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellHandler; import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider; import appeng.api.storage.ISaveProvider;
@@ -48,7 +49,7 @@ public final class CreativeCellHandler implements ICellHandler
} }
@Override @Override
public IMEInventoryHandler getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel channel ) public ICellInventoryHandler getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel channel )
{ {
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) && !is.isEmpty() && is if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) && !is.isEmpty() && is
.getItem() instanceof ItemCreativeStorageCell ) .getItem() instanceof ItemCreativeStorageCell )
@@ -577,7 +577,7 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable
public void saveChanges() public void saveChanges()
{ {
this.iHost.getTileEntity().markDirty(); this.iHost.saveChanges();
} }
@Override @Override
@@ -36,4 +36,6 @@ public interface IFluidInterfaceHost extends IActionHost, IGridProxyable, IUpgra
EnumSet<EnumFacing> getTargets(); EnumSet<EnumFacing> getTargets();
TileEntity getTileEntity(); TileEntity getTileEntity();
void saveChanges();
} }
@@ -51,11 +51,11 @@ public class BasicFluidCellHandler implements ICellHandler
} }
@Override @Override
public <T extends IAEStack<T>> IMEInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> channel ) public <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> channel )
{ {
if( channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ) if( channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
{ {
return (IMEInventoryHandler<T>) FluidCellInventory.getCell( is, container ); return (ICellInventoryHandler<T>) FluidCellInventory.getCell( is, container );
} }
return null; return null;
@@ -29,7 +29,7 @@ import appeng.api.config.Actionable;
import appeng.api.exceptions.AppEngException; import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.items.IStorageCell; import appeng.api.implementations.items.IStorageCell;
import appeng.api.networking.security.IActionSource; import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.ISaveProvider; import appeng.api.storage.ISaveProvider;
import appeng.api.storage.IStorageChannel; import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel; import appeng.api.storage.channels.IFluidStorageChannel;
@@ -47,17 +47,12 @@ import appeng.me.storage.AbstractCellInventory;
*/ */
public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack> public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack>
{ {
protected FluidCellInventory( final NBTTagCompound data, final ISaveProvider container )
{
super( data, container, 8000 );
}
private FluidCellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException private FluidCellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException
{ {
super( o, container, 8000 ); super( o, container, 8000 );
} }
public static IMEInventoryHandler<IAEFluidStack> getCell( final ItemStack o, final ISaveProvider container2 ) public static ICellInventoryHandler<IAEFluidStack> getCell( final ItemStack o, final ISaveProvider container2 )
{ {
try try
{ {
@@ -123,7 +118,6 @@ public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack>
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
l.setStackSize( l.getStackSize() + remainingItemSlots ); l.setStackSize( l.getStackSize() + remainingItemSlots );
this.updateItemCount( remainingItemSlots );
this.saveChanges(); this.saveChanges();
} }
return r; return r;
@@ -133,7 +127,6 @@ public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack>
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
l.setStackSize( l.getStackSize() + input.getStackSize() ); l.setStackSize( l.getStackSize() + input.getStackSize() );
this.updateItemCount( input.getStackSize() );
this.saveChanges(); this.saveChanges();
} }
return null; return null;
@@ -155,8 +148,6 @@ public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack>
toWrite.amount = remainingItemCount; toWrite.amount = remainingItemCount;
this.cellItems.add( AEFluidStack.fromFluidStack( toWrite ) ); this.cellItems.add( AEFluidStack.fromFluidStack( toWrite ) );
this.updateItemCount( toWrite.amount );
this.saveChanges(); this.saveChanges();
} }
return AEFluidStack.fromFluidStack( toReturn ); return AEFluidStack.fromFluidStack( toReturn );
@@ -164,7 +155,6 @@ public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack>
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
this.updateItemCount( input.getStackSize() );
this.cellItems.add( input ); this.cellItems.add( input );
this.saveChanges(); this.saveChanges();
} }
@@ -198,7 +188,6 @@ public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack>
results.setStackSize( l.getStackSize() ); results.setStackSize( l.getStackSize() );
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
this.updateItemCount( -l.getStackSize() );
l.setStackSize( 0 ); l.setStackSize( 0 );
this.saveChanges(); this.saveChanges();
} }
@@ -209,7 +198,6 @@ public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack>
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
l.setStackSize( l.getStackSize() - size ); l.setStackSize( l.getStackSize() - size );
this.updateItemCount( -size );
this.saveChanges(); this.saveChanges();
} }
} }
@@ -561,14 +561,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
return this.storage; return this.storage;
} }
public void markDirty()
{
for( int slot = 0; slot < this.storage.getSlots(); slot++ )
{
this.storage.markDirty( slot );
}
}
@Override @Override
public TickingRequest getTickingRequest( final IGridNode node ) public TickingRequest getTickingRequest( final IGridNode node )
{ {
@@ -869,8 +861,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
{ {
this.cancelCrafting(); this.cancelCrafting();
} }
this.iHost.saveChanges();
this.markDirty();
} }
private void cancelCrafting() private void cancelCrafting()
@@ -1251,7 +1242,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
public void setPriority( final int newValue ) public void setPriority( final int newValue )
{ {
this.priority = newValue; this.priority = newValue;
this.markDirty(); this.iHost.saveChanges();
try try
{ {
@@ -54,11 +54,9 @@ import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IStorageCell; import appeng.api.implementations.items.IStorageCell;
import appeng.api.storage.ICellInventory; import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler; import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IStorageChannel; import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList; import appeng.api.storage.data.IItemList;
import appeng.api.util.AEColor; import appeng.api.util.AEColor;
import appeng.api.util.DimensionalCoord; import appeng.api.util.DimensionalCoord;
@@ -77,7 +75,6 @@ import appeng.items.contents.CellUpgrades;
import appeng.items.misc.ItemPaintBall; import appeng.items.misc.ItemPaintBall;
import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.me.helpers.PlayerSource; import appeng.me.helpers.PlayerSource;
import appeng.me.storage.ItemCellInventoryHandler;
import appeng.tile.misc.TilePaint; import appeng.tile.misc.TilePaint;
import appeng.util.LookDirection; import appeng.util.LookDirection;
import appeng.util.Platform; import appeng.util.Platform;
@@ -97,12 +94,15 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell<
{ {
super.addCheckedInformation( stack, world, lines, advancedTooltips ); super.addCheckedInformation( stack, world, lines, advancedTooltips );
final IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( stack, null, final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); .registries()
.cell()
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( cdi instanceof ItemCellInventoryHandler ) if( cdi != null )
{ {
final ICellInventory cd = ( (ICellInventoryHandler) cdi ).getCellInv(); final ICellInventory<IAEItemStack> cd = cdi.getCellInv();
if( cd != null ) if( cd != null )
{ {
lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + ' ' + cd.getTotalBytes() + ' ' + GuiText.BytesUsed.getLocal() ); lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + ' ' + cd.getTotalBytes() + ' ' + GuiText.BytesUsed.getLocal() );
@@ -124,17 +124,22 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell<
shots += cu.getInstalledUpgrades( Upgrades.SPEED ); shots += cu.getInstalledUpgrades( Upgrades.SPEED );
} }
final IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( p.getHeldItem( hand ), null, final ICellInventoryHandler<IAEItemStack> inv = AEApi.instance()
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); .registries()
.cell()
.getCellInventory( p.getHeldItem( hand ), null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( inv != null ) if( inv != null )
{ {
final IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() ); final IItemList<IAEItemStack> itemList = inv
IAEStack aeAmmo = itemList.getFirstItem(); .getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
if( aeAmmo instanceof IAEItemStack ) IAEItemStack req = itemList.getFirstItem();
if( req instanceof IAEItemStack )
{ {
shots = Math.min( shots, (int) aeAmmo.getStackSize() ); shots = Math.min( shots, (int) req.getStackSize() );
for( int sh = 0; sh < shots; sh++ ) for( int sh = 0; sh < shots; sh++ )
{ {
IAEItemStack aeAmmo = req.copy();
this.extractAEPower( p.getHeldItem( hand ), 1600, Actionable.MODULATE ); this.extractAEPower( p.getHeldItem( hand ), 1600, Actionable.MODULATE );
if( Platform.isClient() ) if( Platform.isClient() )
@@ -206,7 +206,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
} }
te.setCoreBlock( false ); te.setCoreBlock( false );
te.markDirty(); te.saveChanges();
this.tiles.add( 0, te ); this.tiles.add( 0, te );
if( te.isStorage() ) if( te.isStorage() )
@@ -395,7 +395,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
private void markDirty() private void markDirty()
{ {
this.getCore().markDirty(); this.getCore().saveChanges();
} }
private void postCraftingStatusChange( final IAEItemStack diff ) private void postCraftingStatusChange( final IAEItemStack diff )
@@ -42,7 +42,7 @@ import appeng.util.Platform;
*/ */
public abstract class AbstractCellInventory<T extends IAEStack<T>> implements ICellInventory<T> public abstract class AbstractCellInventory<T extends IAEStack<T>> implements ICellInventory<T>
{ {
private static final int MAX_ITEM_TYPES = 63;
private static final String ITEM_TYPE_TAG = "it"; private static final String ITEM_TYPE_TAG = "it";
private static final String ITEM_COUNT_TAG = "ic"; private static final String ITEM_COUNT_TAG = "ic";
private static final String ITEM_SLOT = "#"; private static final String ITEM_SLOT = "#";
@@ -51,46 +51,37 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
protected static final String ITEM_PRE_FORMATTED_SLOT = "PF#"; protected static final String ITEM_PRE_FORMATTED_SLOT = "PF#";
protected static final String ITEM_PRE_FORMATTED_NAME = "PN"; protected static final String ITEM_PRE_FORMATTED_NAME = "PN";
protected static final String ITEM_PRE_FORMATTED_FUZZY = "FP"; protected static final String ITEM_PRE_FORMATTED_FUZZY = "FP";
private static String[] itemSlots; private static final String[] ITEM_SLOT_KEYS = new String[MAX_ITEM_TYPES];
private static String[] itemSlotCount; private static final String[] ITEM_SLOT_COUNT_KEYS = new String[MAX_ITEM_TYPES];
private final NBTTagCompound tagCompound; private final NBTTagCompound tagCompound;
protected final ISaveProvider container; protected final ISaveProvider container;
private int maxItemTypes = 63; private int maxItemTypes = MAX_ITEM_TYPES;
private short storedItems = 0; private short storedItems = 0;
private int storedItemCount = 0; private int storedItemCount = 0;
protected IItemList<T> cellItems; protected IItemList<T> cellItems;
protected ItemStack i; protected final ItemStack i;
protected IStorageCell<T> cellType; protected final IStorageCell<T> cellType;
protected final int itemsPerByte; protected final int itemsPerByte;
private boolean isPersisted = true;
protected AbstractCellInventory( final NBTTagCompound data, final ISaveProvider container, final int itemsPerByte ) static
{ {
this.tagCompound = data; for( int x = 0; x < MAX_ITEM_TYPES; x++ )
this.container = container; {
this.itemsPerByte = itemsPerByte; ITEM_SLOT_KEYS[x] = ITEM_SLOT + x;
ITEM_SLOT_COUNT_KEYS[x] = ITEM_SLOT_COUNT + x;
}
} }
protected AbstractCellInventory( final ItemStack o, final ISaveProvider container, final int itemsPerByte ) throws AppEngException protected AbstractCellInventory( final ItemStack o, final ISaveProvider container, final int itemsPerByte ) throws AppEngException
{ {
this.itemsPerByte = itemsPerByte; this.itemsPerByte = itemsPerByte;
if( itemSlots == null )
{
itemSlots = new String[this.maxItemTypes];
itemSlotCount = new String[this.maxItemTypes];
for( int x = 0; x < this.maxItemTypes; x++ )
{
itemSlots[x] = ITEM_SLOT + x;
itemSlotCount[x] = ITEM_SLOT_COUNT + x;
}
}
if( o == null ) if( o == null )
{ {
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" ); throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
} }
this.cellType = null;
this.i = o; this.i = o;
final Item type = this.i.getItem(); final Item type = this.i.getItem();
@@ -99,8 +90,7 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
this.cellType = (IStorageCell<T>) this.i.getItem(); this.cellType = (IStorageCell<T>) this.i.getItem();
this.maxItemTypes = this.cellType.getTotalTypes( this.i ); this.maxItemTypes = this.cellType.getTotalTypes( this.i );
} }
else
if( this.cellType == null )
{ {
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" ); throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
} }
@@ -110,9 +100,9 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" ); throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
} }
if( this.maxItemTypes > 63 ) if( this.maxItemTypes > MAX_ITEM_TYPES )
{ {
this.maxItemTypes = 63; this.maxItemTypes = MAX_ITEM_TYPES;
} }
if( this.maxItemTypes < 1 ) if( this.maxItemTypes < 1 )
{ {
@@ -142,14 +132,14 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
return this.cellItems; return this.cellItems;
} }
protected void updateItemCount( final long delta ) @Override
public void persist()
{ {
this.storedItemCount += delta; if( this.isPersisted )
this.tagCompound.setInteger( ITEM_COUNT_TAG, this.storedItemCount ); {
} return;
}
protected void saveChanges()
{
int itemCount = 0; int itemCount = 0;
// add new pretty stuff... // add new pretty stuff...
@@ -160,9 +150,8 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
final NBTTagCompound g = new NBTTagCompound(); final NBTTagCompound g = new NBTTagCompound();
v.writeToNBT( g ); v.writeToNBT( g );
this.tagCompound.setTag( itemSlots[x], g ); this.tagCompound.setTag( ITEM_SLOT_KEYS[x], g );
this.tagCompound.setInteger( ITEM_SLOT_COUNT_KEYS[x], (int) v.getStackSize() );
this.tagCompound.setInteger( itemSlotCount[x], (int) v.getStackSize() );
x++; x++;
} }
@@ -192,14 +181,33 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
// clean any old crusty stuff... // clean any old crusty stuff...
for( ; x < oldStoredItems && x < this.maxItemTypes; x++ ) for( ; x < oldStoredItems && x < this.maxItemTypes; x++ )
{ {
this.tagCompound.removeTag( itemSlots[x] ); this.tagCompound.removeTag( ITEM_SLOT_KEYS[x] );
this.tagCompound.removeTag( itemSlotCount[x] ); this.tagCompound.removeTag( ITEM_SLOT_COUNT_KEYS[x] );
} }
this.isPersisted = true;
}
protected void saveChanges()
{
// recalculate values
this.storedItems = (short) this.cellItems.size();
this.storedItemCount = 0;
for( final T v : this.cellItems )
{
this.storedItemCount += v.getStackSize();
}
this.isPersisted = false;
if( this.container != null ) if( this.container != null )
{ {
this.container.saveChanges( this ); this.container.saveChanges( this );
} }
else
{
// if there is no ISaveProvider, store to NBT immediately
this.persist();
}
} }
private void loadCellItems() private void loadCellItems()
@@ -215,8 +223,8 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
for( int slot = 0; slot < types; slot++ ) for( int slot = 0; slot < types; slot++ )
{ {
NBTTagCompound compoundTag = this.tagCompound.getCompoundTag( itemSlots[slot] ); NBTTagCompound compoundTag = this.tagCompound.getCompoundTag( ITEM_SLOT_KEYS[slot] );
int stackSize = this.tagCompound.getInteger( itemSlotCount[slot] ); int stackSize = this.tagCompound.getInteger( ITEM_SLOT_COUNT_KEYS[slot] );
this.loadCellItem( compoundTag, stackSize ); this.loadCellItem( compoundTag, stackSize );
} }
} }
@@ -25,6 +25,7 @@ import appeng.api.AEApi;
import appeng.api.config.AccessRestriction; import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource; import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel; import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.channels.IItemStorageChannel;
@@ -53,7 +54,7 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
} }
} }
public static IMEInventoryHandler getCell( final ItemStack o ) public static ICellInventoryHandler getCell( final ItemStack o )
{ {
return new ItemCellInventoryHandler( new CreativeCellInventory( o ) ); return new ItemCellInventoryHandler( new CreativeCellInventory( o ) );
} }
@@ -45,6 +45,11 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
this.cord = cod; this.cord = cod;
} }
public int getStatus()
{
return this.handler.getStatusForCell( this.is, this.getInternal() );
}
@Override @Override
public T injectItems( final T input, final Actionable type, final IActionSource src ) public T injectItems( final T input, final Actionable type, final IActionSource src )
{ {
@@ -54,7 +59,7 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
if( type == Actionable.MODULATE && ( a == null || a.getStackSize() != size ) ) if( type == Actionable.MODULATE && ( a == null || a.getStackSize() != size ) )
{ {
final int newStatus = this.handler.getStatusForCell( this.is, this.getInternal() ); final int newStatus = this.getStatus();
if( newStatus != this.oldStatus ) if( newStatus != this.oldStatus )
{ {
@@ -73,7 +78,7 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
if( type == Actionable.MODULATE && a != null ) if( type == Actionable.MODULATE && a != null )
{ {
final int newStatus = this.handler.getStatusForCell( this.is, this.getInternal() ); final int newStatus = this.getStatus();
if( newStatus != this.oldStatus ) if( newStatus != this.oldStatus )
{ {
@@ -28,8 +28,8 @@ import appeng.api.config.Actionable;
import appeng.api.exceptions.AppEngException; import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.items.IStorageCell; import appeng.api.implementations.items.IStorageCell;
import appeng.api.networking.security.IActionSource; import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider; import appeng.api.storage.ISaveProvider;
import appeng.api.storage.IStorageChannel; import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.channels.IItemStorageChannel;
@@ -40,17 +40,12 @@ import appeng.core.AELog;
public class ItemCellInventory extends AbstractCellInventory<IAEItemStack> public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
{ {
protected ItemCellInventory( final NBTTagCompound data, final ISaveProvider container )
{
super( data, container, 8 );
}
private ItemCellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException private ItemCellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException
{ {
super( o, container, 8 ); super( o, container, 8 );
} }
public static IMEInventoryHandler getCell( final ItemStack o, final ISaveProvider container2 ) public static ICellInventoryHandler<IAEItemStack> getCell( final ItemStack o, final ISaveProvider container2 )
{ {
try try
{ {
@@ -95,7 +90,7 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
final Item type = i.getItem(); final Item type = i.getItem();
if( type instanceof IStorageCell ) if( type instanceof IStorageCell )
{ {
if ( ( (IStorageCell) type ).getChannel() == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) if( ( (IStorageCell) type ).getChannel() == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{ {
return ( (IStorageCell) type ).isStorageCell( i ); return ( (IStorageCell) type ).isStorageCell( i );
} }
@@ -148,7 +143,6 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
l.setStackSize( l.getStackSize() + remainingItemCount ); l.setStackSize( l.getStackSize() + remainingItemCount );
this.updateItemCount( remainingItemCount );
this.saveChanges(); this.saveChanges();
} }
return r; return r;
@@ -158,7 +152,6 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
l.setStackSize( l.getStackSize() + input.getStackSize() ); l.setStackSize( l.getStackSize() + input.getStackSize() );
this.updateItemCount( input.getStackSize() );
this.saveChanges(); this.saveChanges();
} }
return null; return null;
@@ -180,8 +173,6 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
toWrite.setStackSize( remainingItemCount ); toWrite.setStackSize( remainingItemCount );
this.cellItems.add( toWrite ); this.cellItems.add( toWrite );
this.updateItemCount( toWrite.getStackSize() );
this.saveChanges(); this.saveChanges();
} }
return toReturn; return toReturn;
@@ -189,7 +180,6 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
this.updateItemCount( input.getStackSize() );
this.cellItems.add( input ); this.cellItems.add( input );
this.saveChanges(); this.saveChanges();
} }
@@ -223,7 +213,6 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
Results.setStackSize( l.getStackSize() ); Results.setStackSize( l.getStackSize() );
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
this.updateItemCount( -l.getStackSize() );
l.setStackSize( 0 ); l.setStackSize( 0 );
this.saveChanges(); this.saveChanges();
} }
@@ -234,7 +223,6 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
if( mode == Actionable.MODULATE ) if( mode == Actionable.MODULATE )
{ {
l.setStackSize( l.getStackSize() - size ); l.setStackSize( l.getStackSize() - size );
this.updateItemCount( -size );
this.saveChanges(); this.saveChanges();
} }
} }
@@ -15,6 +15,7 @@ import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper; import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost; import appeng.api.parts.IPartHost;
import appeng.api.storage.ICellContainer; import appeng.api.storage.ICellContainer;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList; import appeng.api.storage.data.IItemList;
@@ -257,7 +258,7 @@ public abstract class PartAbstractFormationPlane<T extends IAEStack<T>> extends
} }
@Override @Override
public void saveChanges( final IMEInventory cell ) public void saveChanges( final ICellInventory<?> cell )
{ {
// nope! // nope!
} }
@@ -61,6 +61,7 @@ import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionSource; import appeng.api.networking.security.IActionSource;
import appeng.api.parts.IPartItem; import appeng.api.parts.IPartItem;
import appeng.api.parts.IPartModel; import appeng.api.parts.IPartModel;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel; import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.channels.IItemStorageChannel;
@@ -39,7 +39,7 @@ import appeng.api.networking.ticking.IGridTickable;
import appeng.api.parts.IPartCollisionHelper; import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartModel; import appeng.api.parts.IPartModel;
import appeng.api.storage.ICellContainer; import appeng.api.storage.ICellContainer;
import appeng.api.storage.IMEInventory; import appeng.api.storage.ICellInventory;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel; import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.channels.IItemStorageChannel;
@@ -126,7 +126,7 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
} }
@Override @Override
public void saveChanges( IMEInventory<?> cellInventory ) public void saveChanges( ICellInventory<?> cellInventory )
{ {
} }
@@ -58,6 +58,7 @@ import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost; import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartModel; import appeng.api.parts.IPartModel;
import appeng.api.storage.ICellContainer; import appeng.api.storage.ICellContainer;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitorHandlerReceiver; import appeng.api.storage.IMEMonitorHandlerReceiver;
@@ -599,7 +600,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
* } * }
*/ */
@Override @Override
public void saveChanges( final IMEInventory cellInventory ) public void saveChanges( final ICellInventory<?> cellInventory )
{ {
// nope! // nope!
} }
+18 -1
View File
@@ -52,6 +52,7 @@ import appeng.core.AELog;
import appeng.core.features.IStackSrc; import appeng.core.features.IStackSrc;
import appeng.helpers.ICustomNameObject; import appeng.helpers.ICustomNameObject;
import appeng.helpers.IPriorityHost; import appeng.helpers.IPriorityHost;
import appeng.hooks.TickHandler;
import appeng.tile.inventory.AppEngInternalAEInventory; import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.SettingsFrom; import appeng.util.SettingsFrom;
@@ -68,6 +69,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
private EnumFacing forward = null; private EnumFacing forward = null;
private EnumFacing up = null; private EnumFacing up = null;
private IBlockState state; private IBlockState state;
private boolean markDirtyQueued = false;
@Override @Override
public boolean shouldRefresh( final World world, final BlockPos pos, final IBlockState oldState, final IBlockState newSate ) public boolean shouldRefresh( final World world, final BlockPos pos, final IBlockState oldState, final IBlockState newSate )
@@ -488,7 +490,22 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
public void saveChanges() public void saveChanges()
{ {
markDirty(); if( this.world != null )
{
this.world.markChunkDirty( this.pos, this );
if( !this.markDirtyQueued )
{
TickHandler.INSTANCE.addCallable( null, this::markDirtyAtEndOfTick );
this.markDirtyQueued = true;
}
}
}
private Object markDirtyAtEndOfTick( final World w )
{
this.markDirty();
this.markDirtyQueued = false;
return null;
} }
public boolean requiresTESR() public boolean requiresTESR()
@@ -159,7 +159,7 @@ public class TileCraftingMonitorTile extends TileCraftingTile implements IColora
} }
this.paintedColor = newPaintedColor; this.paintedColor = newPaintedColor;
this.markDirty(); this.saveChanges();
this.markForUpdate(); this.markForUpdate();
return true; return true;
} }
@@ -133,7 +133,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
} }
this.updateSleepiness(); this.updateSleepiness();
this.markDirty(); this.saveChanges();
return true; return true;
} }
} }
@@ -398,7 +398,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
// did it eject? // did it eject?
if( this.gridInv.getStackInSlot( 9 ).isEmpty() ) if( this.gridInv.getStackInSlot( 9 ).isEmpty() )
{ {
this.markDirty(); this.saveChanges();
} }
this.ejectHeldItems(); this.ejectHeldItems();
@@ -487,7 +487,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
// ;P // ;P
} }
this.markDirty(); this.saveChanges();
this.updateSleepiness(); this.updateSleepiness();
return this.isAwake ? TickRateModulation.IDLE : TickRateModulation.SLEEP; return this.isAwake ? TickRateModulation.IDLE : TickRateModulation.SLEEP;
} }
@@ -509,7 +509,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
{ {
this.gridInv.setStackInSlot( 9, is ); this.gridInv.setStackInSlot( 9, is );
this.gridInv.setStackInSlot( x, ItemStack.EMPTY ); this.gridInv.setStackInSlot( x, ItemStack.EMPTY );
this.markDirty(); this.saveChanges();
return; return;
} }
} }
@@ -580,7 +580,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
if( size != newSize ) if( size != newSize )
{ {
this.markDirty(); this.saveChanges();
} }
return output; return output;
@@ -0,0 +1,119 @@
package appeng.tile.inventory;
import net.minecraft.item.ItemStack;
import appeng.api.storage.ICellInventoryHandler;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.IInternalItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
public class AppEngCellInventory implements IInternalItemHandler
{
private final AppEngInternalInventory inv;
private final ICellInventoryHandler handlerForSlot[];
public AppEngCellInventory( final IAEAppEngInventory host, final int slots )
{
this.inv = new AppEngInternalInventory( host, slots, 1 );
this.handlerForSlot = new ICellInventoryHandler[slots];
}
public void setHandler( final int slot, final ICellInventoryHandler handler )
{
this.handlerForSlot[slot] = handler;
}
public void setFilter( IAEItemFilter filter )
{
this.inv.setFilter( filter );
}
@Override
public void setStackInSlot( int slot, ItemStack stack )
{
this.persist( slot );
this.inv.setStackInSlot( slot, stack );
this.cleanup( slot );
}
@Override
public int getSlots()
{
return this.inv.getSlots();
}
@Override
public ItemStack getStackInSlot( int slot )
{
this.persist( slot );
return this.inv.getStackInSlot( slot );
}
@Override
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
{
this.persist( slot );
final ItemStack ret = inv.insertItem( slot, stack, simulate );
this.cleanup( slot );
return ret;
}
@Override
public ItemStack extractItem( int slot, int amount, boolean simulate )
{
this.persist( slot );
final ItemStack ret = inv.extractItem( slot, amount, simulate );
this.cleanup( slot );
return ret;
}
@Override
public int getSlotLimit( int slot )
{
return inv.getSlotLimit( slot );
}
@Override
public boolean isItemValidForSlot( int slot, ItemStack stack )
{
return inv.isItemValidForSlot( slot, stack );
}
@Override
public void markDirty( int slot )
{
this.persist( slot );
this.inv.markDirty( slot );
this.cleanup( slot );
}
public void persist()
{
for( int i = 0; i < this.getSlots(); ++i )
{
this.persist( i );
}
}
private void persist( int slot )
{
if( this.handlerForSlot[slot] != null )
{
this.handlerForSlot[slot].getCellInv().persist();
}
}
private void cleanup( int slot )
{
if( this.handlerForSlot[slot] != null )
{
if( this.handlerForSlot[slot].getCellInv().getItemStack() != this.inv.getStackInSlot( slot ) )
{
this.handlerForSlot[slot] = null;
}
}
}
}
@@ -185,7 +185,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
this.config.setStackInSlot( x, ItemStack.EMPTY ); this.config.setStackInSlot( x, ItemStack.EMPTY );
} }
this.markDirty(); this.saveChanges();
} }
this.locked = false; this.locked = false;
@@ -380,7 +380,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
this.sideItemHandler.setStackInSlot( 0, ItemStack.EMPTY ); this.sideItemHandler.setStackInSlot( 0, ItemStack.EMPTY );
} }
} }
this.markDirty(); this.saveChanges();
} }
else if( this.finalStep == 16 ) else if( this.finalStep == 16 )
{ {
@@ -130,7 +130,7 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, II
this.configureNodeSides(); this.configureNodeSides();
this.markForUpdate(); this.markForUpdate();
this.markDirty(); this.saveChanges();
} }
private void configureNodeSides() private void configureNodeSides()
@@ -145,12 +145,6 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, II
} }
} }
@Override
public void markDirty()
{
this.duality.markDirty();
}
@Override @Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops ) public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{ {
@@ -191,7 +191,7 @@ public class TilePaint extends AEBaseTile
} }
this.markForUpdate(); this.markForUpdate();
this.markDirty(); this.saveChanges();
} }
private void updateData() private void updateData()
@@ -265,7 +265,7 @@ public class TilePaint extends AEBaseTile
this.maxLit(); this.maxLit();
this.markForUpdate(); this.markForUpdate();
this.markDirty(); this.saveChanges();
} }
} }
@@ -363,7 +363,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost,
} }
this.paintedColor = newPaintedColor; this.paintedColor = newPaintedColor;
this.markDirty(); this.saveChanges();
this.markForUpdate(); this.markForUpdate();
return true; return true;
} }
@@ -261,7 +261,7 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
this.inv.setStackInSlot( 0, is ); this.inv.setStackInSlot( 0, is );
} }
this.markDirty(); this.saveChanges();
} }
} }
@@ -312,7 +312,7 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl
@Override @Override
public void markForSave() public void markForSave()
{ {
super.markDirty(); this.saveChanges();
} }
@Override @Override
@@ -163,9 +163,10 @@ public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoi
} }
@Override @Override
public void markDirty() public void saveChanges()
{ {
this.updatePower(); this.updatePower();
super.saveChanges();
} }
@Override @Override
@@ -69,6 +69,8 @@ import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.storage.IBaseMonitor; import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStorageGrid; import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ICellHandler; import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor; import appeng.api.storage.IMEMonitor;
@@ -121,7 +123,6 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
private boolean wasActive = false; private boolean wasActive = false;
private AEColor paintedColor = AEColor.TRANSPARENT; private AEColor paintedColor = AEColor.TRANSPARENT;
private boolean isCached = false; private boolean isCached = false;
private ICellHandler cellHandler;
private MEMonitorHandler<IAEItemStack> itemCell; private MEMonitorHandler<IAEItemStack> itemCell;
private MEMonitorHandler<IAEFluidStack> fluidCell; private MEMonitorHandler<IAEFluidStack> fluidCell;
private Accessor accessor; private Accessor accessor;
@@ -226,23 +227,23 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
if( !is.isEmpty() ) if( !is.isEmpty() )
{ {
this.isCached = true; this.isCached = true;
this.cellHandler = AEApi.instance().registries().cell().getHandler( is ); ICellHandler cellHandler = AEApi.instance().registries().cell().getHandler( is );
if( this.cellHandler != null ) if( cellHandler != null )
{ {
double power = 1.0; double power = 1.0;
final IMEInventoryHandler<IAEItemStack> itemCell = this.cellHandler.getCellInventory( is, this, final ICellInventoryHandler<IAEItemStack> itemCell = cellHandler.getCellInventory( is, this,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ); AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IMEInventoryHandler<IAEFluidStack> fluidCell = this.cellHandler.getCellInventory( is, this, final ICellInventoryHandler<IAEFluidStack> fluidCell = cellHandler.getCellInventory( is, this,
AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ); AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
if( itemCell != null ) if( itemCell != null )
{ {
power += this.cellHandler.cellIdleDrain( is, itemCell ); power += cellHandler.cellIdleDrain( is, itemCell );
} }
else if( fluidCell != null ) else if( fluidCell != null )
{ {
power += this.cellHandler.cellIdleDrain( is, fluidCell ); power += cellHandler.cellIdleDrain( is, fluidCell );
} }
this.getProxy().setIdlePowerUsage( power ); this.getProxy().setIdlePowerUsage( power );
@@ -766,15 +767,16 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
} }
this.paintedColor = newPaintedColor; this.paintedColor = newPaintedColor;
this.markDirty(); this.saveChanges();
this.markForUpdate(); this.markForUpdate();
return true; return true;
} }
@Override @Override
public void saveChanges( final IMEInventory cellInventory ) public void saveChanges( final ICellInventory<?> cellInventory )
{ {
this.markDirty(); cellInventory.persist();
this.world.markChunkDirty( this.pos, this );
} }
private static class ChestNoHandler extends Exception private static class ChestNoHandler extends Exception
@@ -43,7 +43,8 @@ import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionSource; import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageGrid; import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ICellHandler; import appeng.api.storage.ICellHandler;
import appeng.api.storage.IMEInventory; import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel; import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
@@ -56,9 +57,8 @@ import appeng.helpers.IPriorityHost;
import appeng.me.GridAccessException; import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource; import appeng.me.helpers.MachineSource;
import appeng.me.storage.DriveWatcher; import appeng.me.storage.DriveWatcher;
import appeng.me.storage.MEInventoryHandler;
import appeng.tile.grid.AENetworkInvTile; import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.AppEngCellInventory;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.inv.InvOperation; import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter; import appeng.util.inv.filter.IAEItemFilter;
@@ -71,7 +71,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
private static final int BIT_BLINK_MASK = 0x24924924; private static final int BIT_BLINK_MASK = 0x24924924;
private static final int BIT_STATE_MASK = 0xDB6DB6DB; private static final int BIT_STATE_MASK = 0xDB6DB6DB;
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 10, 1 ); private final AppEngCellInventory inv = new AppEngCellInventory( this, 10 );
private final ICellHandler[] handlersBySlot = new ICellHandler[10]; private final ICellHandler[] handlersBySlot = new ICellHandler[10];
private final DriveWatcher<IAEItemStack>[] invBySlot = new DriveWatcher[10]; private final DriveWatcher<IAEItemStack>[] invBySlot = new DriveWatcher[10];
private final IActionSource mySrc; private final IActionSource mySrc;
@@ -145,21 +145,13 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
return ( this.state >> ( slot * 3 ) ) & 3; return ( this.state >> ( slot * 3 ) ) & 3;
} }
final ItemStack cell = this.inv.getStackInSlot( 2 ); final DriveWatcher handler = this.invBySlot[slot];
final ICellHandler ch = this.handlersBySlot[slot];
final MEInventoryHandler handler = this.invBySlot[slot];
if( handler == null ) if( handler == null )
{ {
return 0; return 0;
} }
if( ch != null ) return handler.getStatus();
{
return ch.getStatusForCell( cell, handler.getInternal() );
}
return 0;
} }
@Override @Override
@@ -307,10 +299,11 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
for( IStorageChannel<? extends IAEStack<?>> channel : storageChannels ) for( IStorageChannel<? extends IAEStack<?>> channel : storageChannels )
{ {
IMEInventoryHandler cell = this.handlersBySlot[x].getCellInventory( is, this, channel ); ICellInventoryHandler cell = this.handlersBySlot[x].getCellInventory( is, this, channel );
if( cell != null ) if( cell != null )
{ {
this.inv.setHandler( x, cell );
power += this.handlersBySlot[x].cellIdleDrain( is, cell ); power += this.handlersBySlot[x].cellIdleDrain( is, cell );
final DriveWatcher<IAEItemStack> ih = new DriveWatcher( cell, is, this.handlersBySlot[x], this ); final DriveWatcher<IAEItemStack> ih = new DriveWatcher( cell, is, this.handlersBySlot[x], this );
@@ -360,7 +353,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
public void setPriority( final int newValue ) public void setPriority( final int newValue )
{ {
this.priority = newValue; this.priority = newValue;
this.markDirty(); this.saveChanges();
this.isCached = false; // recalculate the storage cell. this.isCached = false; // recalculate the storage cell.
this.updateState(); this.updateState();
@@ -384,7 +377,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
} }
@Override @Override
public void saveChanges( final IMEInventory cellInventory ) public void saveChanges( final ICellInventory<?> cellInventory )
{ {
this.world.markChunkDirty( this.pos, this ); this.world.markChunkDirty( this.pos, this );
} }