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
@@ -283,7 +283,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
IInventory inv = myte.getInventoryByName( "config" ); IInventory inv = myte.getInventoryByName( "config" );
IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell() 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>(); Iterator<IAEItemStack> i = new NullIterator<IAEItemStack>();
if ( cellInv != null ) if ( cellInv != null )
+3 -2
View File
@@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import appeng.api.storage.ICellHandler; import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellRegistry; import appeng.api.storage.ICellRegistry;
import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
public class CellRegistry implements ICellRegistry public class CellRegistry implements ICellRegistry
@@ -52,7 +53,7 @@ public class CellRegistry implements ICellRegistry
} }
@Override @Override
public IMEInventoryHandler getCellInventory(ItemStack is, StorageChannel chan) public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel chan)
{ {
if ( is == null ) if ( is == null )
return null; return null;
@@ -60,7 +61,7 @@ public class CellRegistry implements ICellRegistry
{ {
if ( ch.isCell( is ) ) if ( ch.isCell( is ) )
{ {
return ch.getCellInventory( is, chan ); return ch.getCellInventory( is, container, chan );
} }
} }
return null; return null;
@@ -9,6 +9,7 @@ import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler; 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.StorageChannel; import appeng.api.storage.StorageChannel;
import appeng.client.texture.ExtraBlockTextures; import appeng.client.texture.ExtraBlockTextures;
import appeng.core.sync.GuiBridge; import appeng.core.sync.GuiBridge;
@@ -27,10 +28,10 @@ public class BasicCellHandler implements ICellHandler
} }
@Override @Override
public IMEInventoryHandler getCellInventory(ItemStack is, StorageChannel channel) public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel channel)
{ {
if ( channel == StorageChannel.ITEMS ) if ( channel == StorageChannel.ITEMS )
return CellInventory.getCell( is ); return CellInventory.getCell( is, container );
return null; return null;
} }
@@ -7,6 +7,7 @@ import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellHandler; import appeng.api.storage.ICellHandler;
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.StorageChannel; import appeng.api.storage.StorageChannel;
import appeng.client.texture.ExtraBlockTextures; import appeng.client.texture.ExtraBlockTextures;
import appeng.core.sync.GuiBridge; import appeng.core.sync.GuiBridge;
@@ -25,7 +26,7 @@ public class CreativeCellHandler implements ICellHandler
} }
@Override @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 ) if ( channel == StorageChannel.ITEMS && is != null && is.getItem() instanceof ItemCreativeStorageCell )
return CreativeCellInventory.getCell( is ); return CreativeCellInventory.getCell( is );
+1 -1
View File
@@ -27,7 +27,7 @@ public class PortableCellViewer extends MEMonitorHandler<IAEItemStack> implement
private IAEItemPowerStorage ips; private IAEItemPowerStorage ips;
public PortableCellViewer(ItemStack is) { public PortableCellViewer(ItemStack is) {
super( CellInventory.getCell( is ) ); super( CellInventory.getCell( is, null ) );
ips = (IAEItemPowerStorage) is.getItem(); ips = (IAEItemPowerStorage) is.getItem();
target = is; target = is;
} }
+2 -2
View File
@@ -72,7 +72,7 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
@Override @Override
public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b) 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 ) if ( cdi instanceof CellInventoryHandler )
{ {
@@ -187,7 +187,7 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
return false; return false;
InventoryPlayer pinv = player.inventory; 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 ) if ( inv != null && pinv.getCurrentItem() == stack )
{ {
InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN ); InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );
+3 -3
View File
@@ -87,7 +87,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
{ {
ItemStack newColor = null; 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 ) if ( inv != null )
{ {
IItemList<IAEItemStack> itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() ); IItemList<IAEItemStack> itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() );
@@ -163,7 +163,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
ItemStack paintBall = getColor( is ); 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 ) if ( inv != null )
{ {
IAEItemStack option = inv.extractItems( AEItemStack.create( paintBall ), Actionable.SIMULATE, new BaseActionSource() ); 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 ); 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 ) if ( cdi instanceof CellInventoryHandler )
{ {
+2 -2
View File
@@ -75,7 +75,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
{ {
super.addInformation( is, player, lines, advancedItemTooltips ); 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 ) if ( cdi instanceof CellInventoryHandler )
{ {
@@ -99,7 +99,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
if ( cu != null ) if ( cu != null )
shots += cu.getInstalledUpgrades( Upgrades.SPEED ); 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 ) if ( inv != null )
{ {
IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() ); IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() );
+1 -1
View File
@@ -52,7 +52,7 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell,
{ {
super.addInformation( is, player, lines, advancedItemTooltips ); 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 ) if ( cdi instanceof CellInventoryHandler )
{ {
+13 -5
View File
@@ -18,6 +18,7 @@ import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.ICellInventory; 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.ISaveProvider;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList; import appeng.api.storage.data.IItemList;
@@ -48,8 +49,11 @@ public class CellInventory implements ICellInventory
protected ItemStack i; protected ItemStack i;
protected IStorageCell CellType; protected IStorageCell CellType;
protected CellInventory(NBTTagCompound data) { final protected ISaveProvider container;
protected CellInventory(NBTTagCompound data, ISaveProvider container) {
tagCompound = data; tagCompound = data;
this.container = container;
} }
protected void loadCellItems() protected void loadCellItems()
@@ -131,9 +135,12 @@ public class CellInventory implements ICellInventory
tagCompound.removeTag( ITEM_SLOT_ARR[x] ); tagCompound.removeTag( ITEM_SLOT_ARR[x] );
tagCompound.removeTag( ITEM_SLOTCOUNT_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 ) if ( ITEM_SLOT_ARR == null )
{ {
ITEM_SLOT_ARR = new String[MAX_ITEM_TYPES]; ITEM_SLOT_ARR = new String[MAX_ITEM_TYPES];
@@ -176,6 +183,7 @@ public class CellInventory implements ICellInventory
if ( MAX_ITEM_TYPES < 1 ) if ( MAX_ITEM_TYPES < 1 )
MAX_ITEM_TYPES = 1; MAX_ITEM_TYPES = 1;
this.container = container;
tagCompound = Platform.openNbtData( o ); tagCompound = Platform.openNbtData( o );
storedItems = tagCompound.getShort( ITEM_TYPE_TAG ); storedItems = tagCompound.getShort( ITEM_TYPE_TAG );
storedItemCount = tagCompound.getInteger( ITEM_COUNT_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; return (bytesFree > getBytesPerType() || (bytesFree == getBytesPerType() && getUnusedItemCount() > 0)) && getRemainingItemTypes() > 0;
} }
public static IMEInventoryHandler getCell(ItemStack o) public static IMEInventoryHandler getCell(ItemStack o, ISaveProvider container2)
{ {
try try
{ {
return new CellInventoryHandler( new CellInventory( o ) ); return new CellInventoryHandler( new CellInventory( o, container2 ) );
} }
catch (AppEngException e) catch (AppEngException e)
{ {
@@ -361,7 +369,7 @@ public class CellInventory implements ICellInventory
if ( CellInventory.isStorageCell( sharedItemStack ) ) if ( CellInventory.isStorageCell( sharedItemStack ) )
{ {
IMEInventory meinv = getCell( sharedItemStack ); IMEInventory meinv = getCell( sharedItemStack, null );
if ( meinv != null && !isEmpty( meinv ) ) if ( meinv != null && !isEmpty( meinv ) )
return input; return input;
} }
+6
View File
@@ -495,4 +495,10 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
return input; return input;
} }
@Override
public void saveChanges(IMEInventory cellInventory)
{
// nope!
}
} }
+6
View File
@@ -445,4 +445,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
// not used here. // not used here.
} }
@Override
public void saveChanges(IMEInventory cellInventory)
{
// nope!
}
} }
+10 -4
View File
@@ -387,8 +387,8 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
{ {
double power = 1.0; double power = 1.0;
IMEInventoryHandler<IAEItemStack> itemCell = cellHandler.getCellInventory( is, StorageChannel.ITEMS ); IMEInventoryHandler<IAEItemStack> itemCell = cellHandler.getCellInventory( is, this, StorageChannel.ITEMS );
IMEInventoryHandler<IAEFluidStack> fluidCell = cellHandler.getCellInventory( is, StorageChannel.FLUIDS ); IMEInventoryHandler<IAEFluidStack> fluidCell = cellHandler.getCellInventory( is, this, StorageChannel.FLUIDS );
if ( itemCell != null ) if ( itemCell != null )
power += cellHandler.cellIdleDrain( is, itemCell ); power += cellHandler.cellIdleDrain( is, itemCell );
@@ -494,9 +494,9 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
{ {
if ( i == 1 ) 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; 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; return true;
} }
else else
@@ -838,4 +838,10 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
markForUpdate(); markForUpdate();
return true; return true;
} }
@Override
public void saveChanges(IMEInventory cellInventory)
{
worldObj.markTileEntityChunkModified( this.xCoord, this.yCoord, this.zCoord, this );
}
} }
+9 -2
View File
@@ -22,6 +22,7 @@ import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.MachineSource; import appeng.api.networking.security.MachineSource;
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.IMEInventoryHandler; import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
@@ -218,7 +219,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
if ( handlersBySlot[x] != null ) if ( handlersBySlot[x] != null )
{ {
IMEInventoryHandler cell = handlersBySlot[x].getCellInventory( is, StorageChannel.ITEMS ); IMEInventoryHandler cell = handlersBySlot[x].getCellInventory( is, this, StorageChannel.ITEMS );
if ( cell != null ) if ( cell != null )
{ {
@@ -231,7 +232,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
} }
else else
{ {
cell = handlersBySlot[x].getCellInventory( is, StorageChannel.FLUIDS ); cell = handlersBySlot[x].getCellInventory( is, this, StorageChannel.FLUIDS );
if ( cell != null ) if ( cell != null )
{ {
@@ -359,4 +360,10 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
{ {
return itemstack != null && AEApi.instance().registries().cell().isCellHandled( itemstack ); return itemstack != null && AEApi.instance().registries().cell().isCellHandled( itemstack );
} }
@Override
public void saveChanges(IMEInventory cellInventory)
{
worldObj.markTileEntityChunkModified( this.xCoord, this.yCoord, this.zCoord, this );
}
} }
+2 -2
View File
@@ -326,8 +326,8 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
if ( currentCell != is ) if ( currentCell != is )
{ {
currentCell = is; currentCell = is;
cachedFluid = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.FLUIDS ); cachedFluid = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.FLUIDS );
cachedItem = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS ); cachedItem = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
} }
if ( StorageChannel.ITEMS == chan ) if ( StorageChannel.ITEMS == chan )
+4 -4
View File
@@ -1374,7 +1374,7 @@ public class Platform
{ {
if ( removed != null ) 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 ) 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 ) if ( myFluids != null )
{ {
@@ -1399,7 +1399,7 @@ public class Platform
if ( added != null ) 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 ) 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 ) if ( myFluids != null )
{ {