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:
@@ -0,0 +1,51 @@
|
||||
|
||||
package appeng.core.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.config.IncludeExclude;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.IClientHelper;
|
||||
import appeng.core.localization.GuiText;
|
||||
|
||||
|
||||
public class ApiClientHelper implements IClientHelper
|
||||
{
|
||||
@Override
|
||||
public <T extends IAEStack<T>> void addCellInformation( ICellInventoryHandler<T> handler, List<String> lines )
|
||||
{
|
||||
if( handler == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,9 @@ import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
@@ -47,6 +49,7 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.crafting.CraftingLink;
|
||||
import appeng.fluids.items.FluidDummyItem;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.fluids.util.FluidList;
|
||||
import appeng.util.Platform;
|
||||
@@ -104,6 +107,18 @@ public class ApiStorage implements IStorageHelper
|
||||
return new CraftingLink( data, req );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> T poweredInsert( IEnergySource energy, IMEInventory<T> inv, T input, IActionSource src, Actionable mode )
|
||||
{
|
||||
return Platform.poweredInsert( energy, inv, input, src, mode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> T poweredExtraction( IEnergySource energy, IMEInventory<T> inv, T request, IActionSource src, Actionable mode )
|
||||
{
|
||||
return Platform.poweredExtraction( energy, inv, request, src, mode );
|
||||
}
|
||||
|
||||
private static final class ItemStorageChannel implements IItemStorageChannel
|
||||
{
|
||||
|
||||
@@ -126,6 +141,13 @@ public class ApiStorage implements IStorageHelper
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack createFromNBT( NBTTagCompound nbt )
|
||||
{
|
||||
Preconditions.checkNotNull( nbt );
|
||||
return AEItemStack.fromNBT( nbt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack readFromPacket( ByteBuf input ) throws IOException
|
||||
{
|
||||
@@ -133,28 +155,6 @@ public class ApiStorage implements IStorageHelper
|
||||
|
||||
return AEItemStack.fromPacket( input );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack poweredExtraction( IEnergySource energy, IMEInventory<IAEItemStack> cell, IAEItemStack request, IActionSource src )
|
||||
{
|
||||
Preconditions.checkNotNull( energy );
|
||||
Preconditions.checkNotNull( cell );
|
||||
Preconditions.checkNotNull( request );
|
||||
Preconditions.checkNotNull( src );
|
||||
|
||||
return Platform.poweredExtraction( energy, cell, request, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack poweredInsert( IEnergySource energy, IMEInventory<IAEItemStack> cell, IAEItemStack input, IActionSource src )
|
||||
{
|
||||
Preconditions.checkNotNull( energy );
|
||||
Preconditions.checkNotNull( cell );
|
||||
Preconditions.checkNotNull( input );
|
||||
Preconditions.checkNotNull( src );
|
||||
|
||||
return Platform.poweredInsert( energy, cell, input, src );
|
||||
}
|
||||
}
|
||||
|
||||
private static final class FluidStorageChannel implements IFluidStorageChannel
|
||||
@@ -166,6 +166,12 @@ public class ApiStorage implements IStorageHelper
|
||||
return 125;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnitsPerByte()
|
||||
{
|
||||
return 8000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEFluidStack> createList()
|
||||
{
|
||||
@@ -181,6 +187,18 @@ public class ApiStorage implements IStorageHelper
|
||||
{
|
||||
return AEFluidStack.fromFluidStack( (FluidStack) input );
|
||||
}
|
||||
if( input instanceof ItemStack )
|
||||
{
|
||||
final ItemStack is = (ItemStack) input;
|
||||
if( is.getItem() instanceof FluidDummyItem )
|
||||
{
|
||||
return AEFluidStack.fromFluidStack( ( (FluidDummyItem) is.getItem() ).getFluidStack( is ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return AEFluidStack.fromFluidStack( FluidUtil.getFluidContained( is ) );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -194,25 +212,10 @@ public class ApiStorage implements IStorageHelper
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack poweredExtraction( IEnergySource energy, IMEInventory<IAEFluidStack> cell, IAEFluidStack request, IActionSource src )
|
||||
public IAEFluidStack createFromNBT( NBTTagCompound nbt )
|
||||
{
|
||||
Preconditions.checkNotNull( energy );
|
||||
Preconditions.checkNotNull( cell );
|
||||
Preconditions.checkNotNull( request );
|
||||
Preconditions.checkNotNull( src );
|
||||
|
||||
return Platform.poweredExtraction( energy, cell, request, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack poweredInsert( IEnergySource energy, IMEInventory<IAEFluidStack> cell, IAEFluidStack input, IActionSource src )
|
||||
{
|
||||
Preconditions.checkNotNull( energy );
|
||||
Preconditions.checkNotNull( cell );
|
||||
Preconditions.checkNotNull( input );
|
||||
Preconditions.checkNotNull( src );
|
||||
|
||||
return Platform.poweredInsert( energy, cell, input, src );
|
||||
Preconditions.checkNotNull( nbt );
|
||||
return AEFluidStack.fromNBT( nbt );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user