Generic ICellInventoryHandler (#3624)

Allows addons who register a custom IStorageChannel to use the IStorageCell interface without registering a cell handler. Also adds some helpers (poweredInsert/poweredExtract).
This breaks API!
This commit is contained in:
fscan
2018-07-22 19:20:47 +02:00
committed by GitHub
parent 85dec35366
commit c1c7e94cf6
41 changed files with 630 additions and 842 deletions
@@ -38,13 +38,10 @@ import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.exceptions.MissingDefinitionException;
import appeng.api.implementations.items.IItemGroup;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
@@ -81,34 +78,9 @@ public abstract class AbstractStorageCell<T extends IAEStack<T>> extends AEBaseI
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
final IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell().getCellInventory( stack, null, getChannel() );
if( inventory instanceof ICellInventoryHandler )
{
final ICellInventoryHandler handler = (ICellInventoryHandler) inventory;
final ICellInventory cellInventory = handler.getCellInv();
if( cellInventory != null )
{
lines.add( cellInventory.getUsedBytes() + " " + GuiText.Of.getLocal() + ' ' + cellInventory.getTotalBytes() + ' ' + GuiText.BytesUsed.getLocal() );
lines.add( cellInventory.getStoredItemTypes() + " " + GuiText.Of.getLocal() + ' ' + cellInventory.getTotalItemTypes() + ' ' + GuiText.Types.getLocal() );
if( handler.isPreformatted() )
{
final String list = ( handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included : GuiText.Excluded ).getLocal();
if( handler.isFuzzy() )
{
lines.add( GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Fuzzy.getLocal() );
}
else
{
lines.add( GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal() );
}
}
}
}
AEApi.instance()
.client()
.addCellInformation( AEApi.instance().registries().cell().getCellInventory( stack, null, this.getChannel() ), lines );
}
@Override
@@ -256,7 +228,12 @@ public abstract class AbstractStorageCell<T extends IAEStack<T>> extends AEBaseI
@Override
public ItemStack getContainerItem( final ItemStack itemStack )
{
return AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).orElseThrow( () -> new MissingDefinitionException( "Tried to use empty storage cells while basic storage cells are defined." ) );
return AEApi.instance()
.definitions()
.materials()
.emptyStorageCell()
.maybeStack( 1 )
.orElseThrow( () -> new MissingDefinitionException( "Tried to use empty storage cells while basic storage cells are defined." ) );
}
@Override
@@ -33,12 +33,12 @@ import appeng.util.InventoryAdaptor;
public final class BasicItemStorageCell extends AbstractStorageCell<IAEItemStack>
{
protected final int perType;
protected final double idleDrain;
public BasicItemStorageCell( final MaterialType whichCell, final int kilobytes )
{
super(whichCell, kilobytes);
super( whichCell, kilobytes );
switch( whichCell )
{
case CELL1K_PART:
@@ -85,7 +85,8 @@ public final class BasicItemStorageCell extends AbstractStorageCell<IAEItemStack
@Override
protected void dropEmptyStorageCellCase( final InventoryAdaptor ia, final EntityPlayer player )
{
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).ifPresent( is -> {
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).ifPresent( is ->
{
final ItemStack extraA = ia.addItems( is );
if( !extraA.isEmpty() )
{