API Sync, save drive and chests when modifications are made.

This commit is contained in:
AlgorithmX2 2014-07-28 00:11:34 -05:00
parent 4790ab51e0
commit ea5f49b80b
16 changed files with 68 additions and 32 deletions

View file

@ -283,7 +283,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
IInventory inv = myte.getInventoryByName( "config" );
IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell()
.getCellInventory( myte.getInventoryByName( "cell" ).getStackInSlot( 0 ), StorageChannel.ITEMS );
.getCellInventory( myte.getInventoryByName( "cell" ).getStackInSlot( 0 ), null, StorageChannel.ITEMS );
Iterator<IAEItemStack> i = new NullIterator<IAEItemStack>();
if ( cellInv != null )

View file

@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellRegistry;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.StorageChannel;
public class CellRegistry implements ICellRegistry
@ -52,7 +53,7 @@ public class CellRegistry implements ICellRegistry
}
@Override
public IMEInventoryHandler getCellInventory(ItemStack is, StorageChannel chan)
public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel chan)
{
if ( is == null )
return null;
@ -60,7 +61,7 @@ public class CellRegistry implements ICellRegistry
{
if ( ch.isCell( is ) )
{
return ch.getCellInventory( is, chan );
return ch.getCellInventory( is, container, chan );
}
}
return null;

View file

@ -9,6 +9,7 @@ import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.StorageChannel;
import appeng.client.texture.ExtraBlockTextures;
import appeng.core.sync.GuiBridge;
@ -27,10 +28,10 @@ public class BasicCellHandler implements ICellHandler
}
@Override
public IMEInventoryHandler getCellInventory(ItemStack is, StorageChannel channel)
public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel channel)
{
if ( channel == StorageChannel.ITEMS )
return CellInventory.getCell( is );
return CellInventory.getCell( is, container );
return null;
}

View file

@ -7,6 +7,7 @@ import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.StorageChannel;
import appeng.client.texture.ExtraBlockTextures;
import appeng.core.sync.GuiBridge;
@ -25,7 +26,7 @@ public class CreativeCellHandler implements ICellHandler
}
@Override
public IMEInventoryHandler getCellInventory(ItemStack is, StorageChannel channel)
public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel channel)
{
if ( channel == StorageChannel.ITEMS && is != null && is.getItem() instanceof ItemCreativeStorageCell )
return CreativeCellInventory.getCell( is );

View file

@ -27,7 +27,7 @@ public class PortableCellViewer extends MEMonitorHandler<IAEItemStack> implement
private IAEItemPowerStorage ips;
public PortableCellViewer(ItemStack is) {
super( CellInventory.getCell( is ) );
super( CellInventory.getCell( is, null ) );
ips = (IAEItemPowerStorage) is.getItem();
target = is;
}

View file

@ -72,7 +72,7 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
@Override
public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b)
{
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( i, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( i, null, StorageChannel.ITEMS );
if ( cdi instanceof CellInventoryHandler )
{
@ -187,7 +187,7 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
return false;
InventoryPlayer pinv = player.inventory;
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( stack, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( stack, null, StorageChannel.ITEMS );
if ( inv != null && pinv.getCurrentItem() == stack )
{
InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );

View file

@ -87,7 +87,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
{
ItemStack newColor = null;
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( inv != null )
{
IItemList<IAEItemStack> itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() );
@ -163,7 +163,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
ItemStack paintBall = getColor( is );
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( inv != null )
{
IAEItemStack option = inv.extractItems( AEItemStack.create( paintBall ), Actionable.SIMULATE, new BaseActionSource() );
@ -317,7 +317,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
{
super.addInformation( is, player, lines, advancedItemTooltips );
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( cdi instanceof CellInventoryHandler )
{

View file

@ -75,7 +75,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
{
super.addInformation( is, player, lines, advancedItemTooltips );
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( cdi instanceof CellInventoryHandler )
{
@ -99,7 +99,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
if ( cu != null )
shots += cu.getInstalledUpgrades( Upgrades.SPEED );
IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( item, StorageChannel.ITEMS );
IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( item, null, StorageChannel.ITEMS );
if ( inv != null )
{
IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() );

View file

@ -52,7 +52,7 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell,
{
super.addInformation( is, player, lines, advancedItemTooltips );
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( cdi instanceof CellInventoryHandler )
{

View file

@ -18,6 +18,7 @@ import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
@ -48,8 +49,11 @@ public class CellInventory implements ICellInventory
protected ItemStack i;
protected IStorageCell CellType;
protected CellInventory(NBTTagCompound data) {
final protected ISaveProvider container;
protected CellInventory(NBTTagCompound data, ISaveProvider container) {
tagCompound = data;
this.container = container;
}
protected void loadCellItems()
@ -131,9 +135,12 @@ public class CellInventory implements ICellInventory
tagCompound.removeTag( ITEM_SLOT_ARR[x] );
tagCompound.removeTag( ITEM_SLOTCOUNT_ARR[x] );
}
if ( container != null )
container.saveChanges( this );
}
protected CellInventory(ItemStack o) throws AppEngException {
protected CellInventory(ItemStack o, ISaveProvider container) throws AppEngException {
if ( ITEM_SLOT_ARR == null )
{
ITEM_SLOT_ARR = new String[MAX_ITEM_TYPES];
@ -176,6 +183,7 @@ public class CellInventory implements ICellInventory
if ( MAX_ITEM_TYPES < 1 )
MAX_ITEM_TYPES = 1;
this.container = container;
tagCompound = Platform.openNbtData( o );
storedItems = tagCompound.getShort( ITEM_TYPE_TAG );
storedItemCount = tagCompound.getInteger( ITEM_COUNT_TAG );
@ -206,11 +214,11 @@ public class CellInventory implements ICellInventory
return (bytesFree > getBytesPerType() || (bytesFree == getBytesPerType() && getUnusedItemCount() > 0)) && getRemainingItemTypes() > 0;
}
public static IMEInventoryHandler getCell(ItemStack o)
public static IMEInventoryHandler getCell(ItemStack o, ISaveProvider container2)
{
try
{
return new CellInventoryHandler( new CellInventory( o ) );
return new CellInventoryHandler( new CellInventory( o, container2 ) );
}
catch (AppEngException e)
{
@ -361,7 +369,7 @@ public class CellInventory implements ICellInventory
if ( CellInventory.isStorageCell( sharedItemStack ) )
{
IMEInventory meinv = getCell( sharedItemStack );
IMEInventory meinv = getCell( sharedItemStack, null );
if ( meinv != null && !isEmpty( meinv ) )
return input;
}

View file

@ -495,4 +495,10 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
return input;
}
@Override
public void saveChanges(IMEInventory cellInventory)
{
// nope!
}
}

View file

@ -445,4 +445,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
// not used here.
}
@Override
public void saveChanges(IMEInventory cellInventory)
{
// nope!
}
}

View file

@ -387,8 +387,8 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
{
double power = 1.0;
IMEInventoryHandler<IAEItemStack> itemCell = cellHandler.getCellInventory( is, StorageChannel.ITEMS );
IMEInventoryHandler<IAEFluidStack> fluidCell = cellHandler.getCellInventory( is, StorageChannel.FLUIDS );
IMEInventoryHandler<IAEItemStack> itemCell = cellHandler.getCellInventory( is, this, StorageChannel.ITEMS );
IMEInventoryHandler<IAEFluidStack> fluidCell = cellHandler.getCellInventory( is, this, StorageChannel.FLUIDS );
if ( itemCell != null )
power += cellHandler.cellIdleDrain( is, itemCell );
@ -494,9 +494,9 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
{
if ( i == 1 )
{
if ( AEApi.instance().registries().cell().getCellInventory( itemstack, StorageChannel.ITEMS ) != null )
if ( AEApi.instance().registries().cell().getCellInventory( itemstack, this, StorageChannel.ITEMS ) != null )
return true;
if ( AEApi.instance().registries().cell().getCellInventory( itemstack, StorageChannel.FLUIDS ) != null )
if ( AEApi.instance().registries().cell().getCellInventory( itemstack, this, StorageChannel.FLUIDS ) != null )
return true;
}
else
@ -838,4 +838,10 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
markForUpdate();
return true;
}
@Override
public void saveChanges(IMEInventory cellInventory)
{
worldObj.markTileEntityChunkModified( this.xCoord, this.yCoord, this.zCoord, this );
}
}

View file

@ -22,6 +22,7 @@ import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
@ -218,7 +219,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
if ( handlersBySlot[x] != null )
{
IMEInventoryHandler cell = handlersBySlot[x].getCellInventory( is, StorageChannel.ITEMS );
IMEInventoryHandler cell = handlersBySlot[x].getCellInventory( is, this, StorageChannel.ITEMS );
if ( cell != null )
{
@ -231,7 +232,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
}
else
{
cell = handlersBySlot[x].getCellInventory( is, StorageChannel.FLUIDS );
cell = handlersBySlot[x].getCellInventory( is, this, StorageChannel.FLUIDS );
if ( cell != null )
{
@ -359,4 +360,10 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
{
return itemstack != null && AEApi.instance().registries().cell().isCellHandled( itemstack );
}
@Override
public void saveChanges(IMEInventory cellInventory)
{
worldObj.markTileEntityChunkModified( this.xCoord, this.yCoord, this.zCoord, this );
}
}

View file

@ -326,8 +326,8 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
if ( currentCell != is )
{
currentCell = is;
cachedFluid = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.FLUIDS );
cachedItem = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS );
cachedFluid = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.FLUIDS );
cachedItem = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
}
if ( StorageChannel.ITEMS == chan )

View file

@ -1374,7 +1374,7 @@ public class Platform
{
if ( removed != null )
{
IMEInventory<IAEItemStack> myItems = AEApi.instance().registries().cell().getCellInventory( removed, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> myItems = AEApi.instance().registries().cell().getCellInventory( removed, null, StorageChannel.ITEMS );
if ( myItems != null )
{
@ -1385,7 +1385,7 @@ public class Platform
}
}
IMEInventory<IAEFluidStack> myFluids = AEApi.instance().registries().cell().getCellInventory( removed, StorageChannel.FLUIDS );
IMEInventory<IAEFluidStack> myFluids = AEApi.instance().registries().cell().getCellInventory( removed, null, StorageChannel.FLUIDS );
if ( myFluids != null )
{
@ -1399,7 +1399,7 @@ public class Platform
if ( added != null )
{
IMEInventory<IAEItemStack> myItems = AEApi.instance().registries().cell().getCellInventory( added, StorageChannel.ITEMS );
IMEInventory<IAEItemStack> myItems = AEApi.instance().registries().cell().getCellInventory( added, null, StorageChannel.ITEMS );
if ( myItems != null )
{
@ -1409,7 +1409,7 @@ public class Platform
}
}
IMEInventory<IAEFluidStack> myFluids = AEApi.instance().registries().cell().getCellInventory( added, StorageChannel.FLUIDS );
IMEInventory<IAEFluidStack> myFluids = AEApi.instance().registries().cell().getCellInventory( added, null, StorageChannel.FLUIDS );
if ( myFluids != null )
{