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
+6
View File
@@ -30,6 +30,7 @@ import appeng.api.networking.IGridHelper;
import appeng.api.networking.IGridNode;
import appeng.api.parts.IPartHelper;
import appeng.api.storage.IStorageHelper;
import appeng.api.util.IClientHelper;
@AEInjectable
@@ -60,4 +61,9 @@ public interface IAppEngApi
*/
IDefinitions definitions();
/**
* @return Utility methods primarily useful for client side stuff
*/
IClientHelper client();
}
@@ -0,0 +1,47 @@
package appeng.api.storage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.data.IAEStack;
public interface ICellGuiHandler
{
/**
* Return true if this handler can show GUI for this channel.
*
* @param channel Storage channel
* @return True if handled, else false.
*/
<T extends IAEStack<T>> boolean isHandlerFor( IStorageChannel<T> channel );
/**
* Return true to prioritize this handler for the provided {@link ItemStack}.
*
* @param is Cell ItemStack
* @return True, if specialized else false.
*/
default boolean isSpecializedFor( ItemStack is )
{
return false;
}
/**
* Called when the storage cell is placed in an ME Chest and the user tries to open the terminal side, if your item
* is not available via ME Chests simply tell the user they can't use it, or something, other wise you should open
* your gui and display the cell to the user.
*
* @param player player opening chest gui
* @param chest to be opened chest
* @param cellHandler cell handler
* @param inv inventory handler
* @param is item
* @param chan storage channel
*/
<T extends IAEStack<T>> void openChestGui( EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler<T> inv, ItemStack is, IStorageChannel<T> chan );
}
@@ -24,10 +24,8 @@
package appeng.api.storage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.data.IAEStack;
@@ -59,20 +57,6 @@ public interface ICellHandler
*/
<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
* is not available via ME Chests simply tell the user they can't use it, or something, other wise you should open
* your gui and display the cell to the user.
*
* @param player player opening chest gui
* @param chest to be opened chest
* @param cellHandler cell handler
* @param inv inventory handler
* @param is item
* @param chan storage channel
*/
<T extends IAEStack<T>> void openChestGui( EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler<T> inv, ItemStack is, IStorageChannel<T> chan );
/**
* 0 - cell is missing.
*
@@ -87,10 +71,31 @@ public interface ICellHandler
*
* @return get the status of the cell based on its contents.
*/
<T extends IAEStack<T>> int getStatusForCell( ItemStack is, IMEInventory<T> handler );
default <T extends IAEStack<T>> int getStatusForCell( ItemStack is, ICellInventoryHandler<T> handler )
{
if( handler.getCellInv() != null )
{
int val = handler.getCellInv().getStatusForCell();
if( val == 1 && handler.isPreformatted() )
{
val = 2;
}
return val;
}
return 0;
}
/**
* @return the ae/t to drain for this storage cell inside a chest/drive.
*/
<T extends IAEStack<T>> double cellIdleDrain( ItemStack is, IMEInventory<T> handler );
default <T extends IAEStack<T>> double cellIdleDrain( ItemStack is, ICellInventoryHandler<T> handler )
{
if( handler.getCellInv() != null )
{
return handler.getCellInv().getIdleDrain();
}
return 1.0;
}
}
@@ -40,7 +40,7 @@ public interface ICellInventory<T extends IAEStack<T>> extends IMEInventory<T>
ItemStack getItemStack();
/**
* @return idle cost for this Storage Cell
* @return the ae/t to drain for this storage cell inside a chest/drive.
*/
double getIdleDrain();
@@ -115,7 +115,15 @@ public interface ICellInventory<T extends IAEStack<T>> extends IMEInventory<T>
int getUnusedItemCount();
/**
* @return the status number for this drive.
* 0 - cell is missing.
*
* 1 - green, ( usually means available room for types or items. )
*
* 2 - orange, ( usually means available room for items, but not types. )
*
* 3 - red, ( usually means the cell is 100% full )
*
* @return get the status of the cell based on its contents.
*/
int getStatusForCell();
@@ -24,6 +24,8 @@
package appeng.api.storage;
import javax.annotation.Nullable;
import appeng.api.config.IncludeExclude;
import appeng.api.storage.data.IAEStack;
@@ -32,8 +34,11 @@ public interface ICellInventoryHandler<T extends IAEStack<T>> extends IMEInvento
{
/**
* Get access to the ICellInventory. Can be null for custom cells.
*
* @return get access to the Cell Inventory.
*/
@Nullable
ICellInventory<T> getCellInv();
boolean isPreformatted();
@@ -53,6 +53,13 @@ public interface ICellRegistry
*/
void addCellHandler( @Nonnull ICellHandler handler );
/**
* Register a new handler
*
* @param handler cell gui handler
*/
void addCellGuiHandler( @Nonnull ICellGuiHandler handler );
/**
* return true, if you can get a InventoryHandler for the item passed.
*
@@ -64,7 +71,7 @@ public interface ICellRegistry
boolean isCellHandled( ItemStack is );
/**
* get the handler, for the requested type.
* get the handler, for the requested item.
*
* @param is to be checked item
*
@@ -74,13 +81,23 @@ public interface ICellRegistry
ICellHandler getHandler( ItemStack is );
/**
* returns an IMEInventoryHandler for the provided item.
* get the handler, for the requested channel.
*
* @param channel requested channel
* @param Cell ItemStack
* @return the handler registered for this channel.
*/
@Nullable
<T extends IAEStack<T>> ICellGuiHandler getGuiHandler( IStorageChannel<T> channel, ItemStack is );
/**
* returns an ICellInventoryHandler for the provided item by querying all registered handlers.
*
* @param is item with inventory handler
* @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.
*
* @return new IMEInventoryHandler, or null if there isn't one.
* @return new ICellInventoryHandler, or null if there isn't one.
*/
@Nullable
<T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( ItemStack is, ISaveProvider host, IStorageChannel<T> chan );
@@ -24,11 +24,19 @@
package appeng.api.storage;
import javax.annotation.Nullable;
/**
* Tells the cell provider that changes have been made an the cell must be persisted
*
*/
public interface ISaveProvider
{
void saveChanges( ICellInventory<?> cellInventory );
/**
* Cell has changed and needs to be changed.
*
* @param cellInventory can be null for custom cells.
*/
void saveChanges( @Nullable ICellInventory<?> cellInventory );
}
@@ -32,10 +32,9 @@ import javax.annotation.Nullable;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
@@ -56,6 +55,17 @@ public interface IStorageChannel<T extends IAEStack<T>>
return 1;
}
/**
* The number of units (eg item count, or millibuckets) that can be stored per byte in a storage cell.
* Standard value for items is 8, and for fluids it's 8000
*
* @return number of units
*/
default int getUnitsPerByte()
{
return 8;
}
/**
* Create a new {@link IItemList} of the specific type.
*
@@ -68,9 +78,12 @@ public interface IStorageChannel<T extends IAEStack<T>>
* Create a new {@link IAEStack} subtype of the specific object.
*
* The parameter is unbound to allow a slightly more flexible approach.
* But the general intention is about converting an {@link ItemStack} into the corresponding {@link IAEItemStack}.
* But the general intention is about converting an {@link ItemStack} or {@link FluidStack} into the corresponding
* {@link IAEStack}.
* Another valid case might be to use it instead of {@link IAEStack#copy()}, but this might not be supported by all
* types.
* IAEStacks that use custom items for {@link IAEStack#asItemStackRepresentation()} must also be able to convert
* these.
*
* @param input The object to turn into an {@link IAEStack}
* @return The converted stack or null
@@ -88,29 +101,11 @@ public interface IStorageChannel<T extends IAEStack<T>>
T readFromPacket( @Nonnull ByteBuf input ) throws IOException;
/**
* use energy from energy, to remove request items from cell, at the request of src.
*
* @param energy to be drained energy source
* @param cell cell of requested items
* @param request requested items
* @param src action source
*
* @return items that successfully extracted.
* create from nbt data
*
* @param nbt
* @return
*/
@Nullable
T poweredExtraction( @Nonnull IEnergySource energy, @Nonnull IMEInventory<T> cell, @Nonnull T request, @Nonnull IActionSource src );
/**
* use energy from energy, to inject input items into cell, at the request of src
*
* @param energy to be added energy source
* @param cell injected cell
* @param input to be injected items
* @param src action source
*
* @return items that failed to insert.
*/
@Nullable
T poweredInsert( @Nonnull IEnergySource energy, @Nonnull IMEInventory<T> cell, @Nonnull T input, @Nonnull IActionSource src );
T createFromNBT( @Nonnull NBTTagCompound nbt );
}
@@ -30,8 +30,11 @@ import javax.annotation.Nonnull;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.config.Actionable;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingRequester;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
@@ -90,4 +93,27 @@ public interface IStorageHelper
*/
ICraftingLink loadCraftingLink( NBTTagCompound data, ICraftingRequester req );
/**
* Extracts items from a {@link IMEInventory} respecting power requirements.
*
* @param energy Energy source.
* @param inv Inventory to extract from.
* @param request Requested item and count.
* @param src Action source.
* @param mode Simulate or modulate
* @return extracted items or {@code null} of nothing was extracted.
*/
<T extends IAEStack<T>> T poweredExtraction( final IEnergySource energy, final IMEInventory<T> inv, final T request, final IActionSource src, final Actionable mode );
/**
* Inserts items into a {@link IMEInventory} respecting power requirements.
*
* @param energy Energy source.
* @param inv Inventory to insert into.
* @param request Items to insert.
* @param src Action source.
* @param mode Simulate or modulate
* @return items not inserted or {@code null} if everything was inserted.
*/
<T extends IAEStack<T>> T poweredInsert( final IEnergySource energy, final IMEInventory<T> inv, final T input, final IActionSource src, final Actionable mode );
}
@@ -0,0 +1,21 @@
package appeng.api.util;
import java.util.List;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.data.IAEStack;
public interface IClientHelper
{
/**
* Add cell information to the provided list. Used for tooltip content.
*
* @param handler Cell handler.
* @param lines List of lines to add to.
*/
<T extends IAEStack<T>> void addCellInformation( ICellInventoryHandler<T> handler, List<String> lines );
}
@@ -34,8 +34,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.storage.ICellHandler;
import appeng.api.util.AEPartLocation;
import appeng.block.AEBaseTileBlock;
import appeng.core.localization.PlayerMessages;
@@ -108,14 +106,7 @@ public class BlockChest extends AEBaseTileBlock
}
else
{
final ItemStack cell = tg.getCell();
if( !cell.isEmpty() )
{
final ICellHandler ch = AEApi.instance().registries().cell().getHandler( cell );
tg.openGui( p, ch, cell, side );
}
else
if( !tg.openGui( p ) )
{
p.sendMessage( PlayerMessages.ChestCannotReadStorageCell.get() );
}
+10
View File
@@ -23,6 +23,8 @@ import appeng.api.IAppEngApi;
import appeng.api.features.IRegistryContainer;
import appeng.api.networking.IGridHelper;
import appeng.api.storage.IStorageHelper;
import appeng.api.util.IClientHelper;
import appeng.core.api.ApiClientHelper;
import appeng.core.api.ApiGrid;
import appeng.core.api.ApiPart;
import appeng.core.api.ApiStorage;
@@ -41,6 +43,7 @@ public final class Api implements IAppEngApi
private final IStorageHelper storageHelper;
private final IGridHelper networkHelper;
private final ApiDefinitions definitions;
private final IClientHelper client;
private Api()
{
@@ -49,6 +52,7 @@ public final class Api implements IAppEngApi
this.registryContainer = new RegistryContainer();
this.partHelper = new ApiPart();
this.definitions = new ApiDefinitions( (PartModels) this.registryContainer.partModels() );
this.client = new ApiClientHelper();
}
public PartModels getPartModels()
@@ -85,4 +89,10 @@ public final class Api implements IAppEngApi
{
return this.definitions;
}
@Override
public IClientHelper client()
{
return this.client;
}
}
+10 -8
View File
@@ -91,7 +91,8 @@ import appeng.bootstrap.components.IRecipeRegistrationComponent;
import appeng.capabilities.Capabilities;
import appeng.core.features.AEFeature;
import appeng.core.features.registries.P2PTunnelRegistry;
import appeng.core.features.registries.cell.BasicItemCellHandler;
import appeng.core.features.registries.cell.BasicCellHandler;
import appeng.core.features.registries.cell.BasicItemCellGuiHandler;
import appeng.core.features.registries.cell.CreativeCellHandler;
import appeng.core.localization.GuiText;
import appeng.core.localization.PlayerMessages;
@@ -99,7 +100,7 @@ import appeng.core.stats.AdvancementTriggers;
import appeng.core.stats.PartItemPredicate;
import appeng.core.stats.Stats;
import appeng.core.worlddata.SpatialDimensionManager;
import appeng.fluids.registries.BasicFluidCellHandler;
import appeng.fluids.registries.BasicFluidCellGuiHandler;
import appeng.hooks.TickHandler;
import appeng.items.materials.ItemMaterial;
import appeng.items.parts.ItemFacade;
@@ -236,9 +237,10 @@ final class Registration
gcr.registerGridCache( ISecurityGrid.class, SecurityCache.class );
gcr.registerGridCache( ICraftingGrid.class, CraftingGridCache.class );
registries.cell().addCellHandler( new BasicItemCellHandler() );
registries.cell().addCellHandler( new BasicCellHandler() );
registries.cell().addCellHandler( new CreativeCellHandler() );
registries.cell().addCellHandler( new BasicFluidCellHandler() );
registries.cell().addCellGuiHandler( new BasicItemCellGuiHandler() );
registries.cell().addCellGuiHandler( new BasicFluidCellGuiHandler() );
api.definitions().materials().matterBall().maybeStack( 1 ).ifPresent( ammoStack ->
{
@@ -286,7 +288,7 @@ final class Registration
final Side side = FMLCommonHandler.instance().getEffectiveSide();
definitions.getRegistry().getBootstrapComponents( IItemRegistrationComponent.class ).forEachRemaining( b -> b.itemRegistration( side, registry ) );
// register oredicts
definitions.getRegistry().getBootstrapComponents( IOreDictComponent.class ).forEachRemaining( b -> b.oreRegistration( side ) );
definitions.getRegistry().getBootstrapComponents( IOreDictComponent.class ).forEachRemaining( b -> b.oreRegistration( side ) );
ItemMaterial.instance.registerOredicts();
ItemPart.instance.registerOreDicts();
}
@@ -320,15 +322,15 @@ final class Registration
final AERecipeLoader ldr = new AERecipeLoader();
ldr.loadProcessingRecipes();
}
@SubscribeEvent
public void registerEntities( RegistryEvent.Register<EntityEntry> event)
public void registerEntities( RegistryEvent.Register<EntityEntry> event )
{
final IForgeRegistry<EntityEntry> registry = event.getRegistry();
final ApiDefinitions definitions = Api.INSTANCE.definitions();
definitions.getRegistry().getBootstrapComponents( IEntityRegistrationComponent.class ).forEachRemaining( b -> b.entityRegistration( registry ) );
}
@SubscribeEvent
public void attachSpatialDimensionManager( AttachCapabilitiesEvent<World> event )
{
@@ -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() );
}
}
}
}
+43 -40
View File
@@ -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 );
}
}
@@ -0,0 +1,54 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core.features.registries.cell;
import net.minecraft.item.ItemStack;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.me.storage.BasicCellInventory;
import appeng.me.storage.BasicCellInventoryHandler;
public class BasicCellHandler implements ICellHandler
{
@Override
public boolean isCell( final ItemStack is )
{
return BasicCellInventory.isCell( is );
}
@Override
public <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> channel )
{
final ICellInventory<T> inv = BasicCellInventory.createInventory( is, container );
if( inv == null || inv.getChannel() != channel )
{
return null;
}
return new BasicCellInventoryHandler<>( inv, channel );
}
}
@@ -0,0 +1,35 @@
package appeng.core.features.registries.cell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.AEApi;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellGuiHandler;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AEPartLocation;
import appeng.core.sync.GuiBridge;
import appeng.util.Platform;
public class BasicItemCellGuiHandler implements ICellGuiHandler
{
@Override
public <T extends IAEStack<T>> boolean isHandlerFor( final IStorageChannel<T> channel )
{
return channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public void openChestGui( final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan )
{
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_ME );
}
}
@@ -1,90 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core.features.registries.cell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.AEApi;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellHandler;
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.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AEPartLocation;
import appeng.core.sync.GuiBridge;
import appeng.me.storage.ItemCellInventory;
import appeng.me.storage.ItemCellInventoryHandler;
import appeng.util.Platform;
public class BasicItemCellHandler implements ICellHandler
{
@Override
public boolean isCell( final ItemStack is )
{
return ItemCellInventory.isCell( is );
}
@Override
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 ) )
{
return (ICellInventoryHandler<T>) ItemCellInventory.getCell( is, container );
}
return null;
}
@Override
public void openChestGui( final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan )
{
if( chan == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_ME );
}
}
@Override
public int getStatusForCell( final ItemStack is, final IMEInventory handler )
{
if( handler instanceof ItemCellInventoryHandler )
{
final ItemCellInventoryHandler ci = (ItemCellInventoryHandler) handler;
return ci.getStatusForCell();
}
return 0;
}
@Override
public double cellIdleDrain( final ItemStack is, final IMEInventory handler )
{
final ICellInventory inv = ( (ICellInventoryHandler) handler ).getCellInv();
return inv.getIdleDrain();
}
}
@@ -27,6 +27,7 @@ import com.google.common.base.Verify;
import net.minecraft.item.ItemStack;
import appeng.api.storage.ICellGuiHandler;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.ICellRegistry;
@@ -39,10 +40,12 @@ public class CellRegistry implements ICellRegistry
{
private final List<ICellHandler> handlers;
private final List<ICellGuiHandler> guiHandlers;
public CellRegistry()
{
this.handlers = new ArrayList<>();
this.guiHandlers = new ArrayList<>();
}
@Override
@@ -54,7 +57,7 @@ public class CellRegistry implements ICellRegistry
this.handlers.add( handler );
// Verify that the first entry is always our own handler.
Verify.verify( this.handlers.get( 0 ) instanceof BasicItemCellHandler );
Verify.verify( this.handlers.get( 0 ) instanceof BasicCellHandler );
}
@Override
@@ -107,4 +110,33 @@ public class CellRegistry implements ICellRegistry
}
return null;
}
@Override
public void addCellGuiHandler( ICellGuiHandler handler )
{
this.guiHandlers.add( handler );
}
@Override
public <T extends IAEStack<T>> ICellGuiHandler getGuiHandler( final IStorageChannel<T> channel, final ItemStack is )
{
ICellGuiHandler fallBack = null;
for( final ICellGuiHandler ch : this.guiHandlers )
{
if( ch.isHandlerFor( channel ) )
{
if( ch.isSpecializedFor( is ) )
{
return ch;
}
if( fallBack == null )
{
fallBack = ch;
}
}
}
return fallBack;
}
}
@@ -19,24 +19,16 @@
package appeng.core.features.registries.cell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.AEApi;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.util.AEPartLocation;
import appeng.core.sync.GuiBridge;
import appeng.items.storage.ItemCreativeStorageCell;
import appeng.me.storage.CreativeCellInventory;
import appeng.util.Platform;
public final class CreativeCellHandler implements ICellHandler
@@ -60,19 +52,13 @@ public final class CreativeCellHandler implements ICellHandler
}
@Override
public void openChestGui( final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan )
{
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_ME );
}
@Override
public int getStatusForCell( final ItemStack is, final IMEInventory handler )
public int getStatusForCell( final ItemStack is, final ICellInventoryHandler handler )
{
return 2;
}
@Override
public double cellIdleDrain( final ItemStack is, final IMEInventory handler )
public double cellIdleDrain( final ItemStack is, final ICellInventoryHandler handler )
{
return 0;
}
@@ -105,7 +105,8 @@ public final class BasicFluidStorageCell extends AbstractStorageCell<IAEFluidSta
@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() )
{
@@ -25,66 +25,29 @@ import net.minecraft.tileentity.TileEntity;
import appeng.api.AEApi;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellGuiHandler;
import appeng.api.storage.ICellHandler;
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.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AEPartLocation;
import appeng.core.sync.GuiBridge;
import appeng.fluids.storage.FluidCellInventory;
import appeng.fluids.storage.FluidCellInventoryHandler;
import appeng.util.Platform;
public class BasicFluidCellHandler implements ICellHandler
public class BasicFluidCellGuiHandler implements ICellGuiHandler
{
@Override
public boolean isCell( final ItemStack is )
public <T extends IAEStack<T>> boolean isHandlerFor( final IStorageChannel<T> channel )
{
return FluidCellInventory.isCell( is );
}
@Override
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 ) )
{
return (ICellInventoryHandler<T>) FluidCellInventory.getCell( is, container );
}
return null;
return channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
}
@Override
public void openChestGui( final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan )
{
if( chan == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
{
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_FLUID_TERMINAL );
}
}
@Override
public int getStatusForCell( final ItemStack is, final IMEInventory handler )
{
if( handler instanceof FluidCellInventoryHandler )
{
final FluidCellInventoryHandler ci = (FluidCellInventoryHandler) handler;
return ci.getStatusForCell();
}
return 0;
}
@Override
public double cellIdleDrain( final ItemStack is, final IMEInventory handler )
{
final ICellInventory inv = ( (ICellInventoryHandler) handler ).getCellInv();
return inv.getIdleDrain();
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_FLUID_TERMINAL );
}
}
@@ -1,258 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.storage;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.fluids.util.AEFluidStack;
import appeng.me.storage.AbstractCellInventory;
/**
* @author DrummerMC
* @version rv6 - 2018-01-16
* @since rv6 2018-01-16
*/
public class FluidCellInventory extends AbstractCellInventory<IAEFluidStack>
{
private FluidCellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException
{
super( o, container, 8000 );
}
public static ICellInventoryHandler<IAEFluidStack> getCell( final ItemStack o, final ISaveProvider container2 )
{
try
{
return new FluidCellInventoryHandler( new FluidCellInventory( o, container2 ) );
}
catch( final AppEngException e )
{
return null;
}
}
public static boolean isCell( final ItemStack i )
{
if( i == null )
{
return false;
}
final Item type = i.getItem();
if( type instanceof IStorageCell )
{
if( ( (IStorageCell) type ).getChannel() == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
{
return ( (IStorageCell) type ).isStorageCell( i );
}
}
return false;
}
@Override
public IAEFluidStack injectItems( final IAEFluidStack input, final Actionable mode, final IActionSource src )
{
if( input == null )
{
return null;
}
if( input.getStackSize() == 0 )
{
return null;
}
if( this.cellType.isBlackListed( this.i, input ) )
{
return input;
}
final FluidStack sharedFluidStack = input.getFluidStack();
final IAEFluidStack l = this.getCellItems().findPrecise( input );
if( l != null )
{
final long remainingItemSlots = this.getRemainingItemCount();
if( remainingItemSlots <= 0 )
{
return input;
}
if( input.getStackSize() > remainingItemSlots )
{
final IAEFluidStack r = input.copy();
r.setStackSize( r.getStackSize() - remainingItemSlots );
if( mode == Actionable.MODULATE )
{
l.setStackSize( l.getStackSize() + remainingItemSlots );
this.saveChanges();
}
return r;
}
else
{
if( mode == Actionable.MODULATE )
{
l.setStackSize( l.getStackSize() + input.getStackSize() );
this.saveChanges();
}
return null;
}
}
if( this.canHoldNewItem() ) // room for new type, and for at least one item!
{
final int remainingItemCount = (int) this.getRemainingItemCount() - this.getBytesPerType() * itemsPerByte;
if( remainingItemCount > 0 )
{
if( input.getStackSize() > remainingItemCount )
{
final FluidStack toReturn = sharedFluidStack.copy();
toReturn.amount = sharedFluidStack.amount - remainingItemCount;
if( mode == Actionable.MODULATE )
{
final FluidStack toWrite = sharedFluidStack.copy();
toWrite.amount = remainingItemCount;
this.cellItems.add( AEFluidStack.fromFluidStack( toWrite ) );
this.saveChanges();
}
return AEFluidStack.fromFluidStack( toReturn );
}
if( mode == Actionable.MODULATE )
{
this.cellItems.add( input );
this.saveChanges();
}
return null;
}
}
return input;
}
@Override
public IAEFluidStack extractItems( final IAEFluidStack request, final Actionable mode, final IActionSource src )
{
if( request == null )
{
return null;
}
final long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );
IAEFluidStack results = null;
final IAEFluidStack l = this.getCellItems().findPrecise( request );
if( l != null )
{
results = l.copy();
if( l.getStackSize() <= size )
{
results.setStackSize( l.getStackSize() );
if( mode == Actionable.MODULATE )
{
l.setStackSize( 0 );
this.saveChanges();
}
}
else
{
results.setStackSize( size );
if( mode == Actionable.MODULATE )
{
l.setStackSize( l.getStackSize() - size );
this.saveChanges();
}
}
}
return results;
}
@Override
public IStorageChannel getChannel()
{
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
}
protected void loadCellItem( NBTTagCompound compoundTag, int stackSize )
{
// Now load the fluid stack
final FluidStack t;
try
{
t = FluidStack.loadFluidStackFromNBT( compoundTag );
if( t == null )
{
AELog.warn( "Removing item " + compoundTag + " from storage cell because the associated item type couldn't be found." );
return;
}
}
catch( Throwable ex )
{
if( AEConfig.instance().isRemoveCrashingItemsOnLoad() )
{
AELog.warn( ex, "Removing item " + compoundTag + " from storage cell because loading the ItemStack crashed." );
return;
}
throw ex;
}
t.amount = stackSize;
if( t.amount > 0 )
{
try
{
this.cellItems.add( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createStack( t ) );
}
catch( Throwable ex )
{
if( AEConfig.instance().isRemoveCrashingItemsOnLoad() )
{
AELog.warn( ex, "Removing item " + t + " from storage cell because processing the loaded item crashed." );
return;
}
throw ex;
}
}
}
}
@@ -1,52 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.storage;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.AEApi;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.fluids.items.FluidDummyItem;
import appeng.fluids.util.AEFluidStack;
import appeng.me.storage.AbstractCellInventoryHandler;
public class FluidCellInventoryHandler extends AbstractCellInventoryHandler<IAEFluidStack>
{
public FluidCellInventoryHandler( IMEInventory c )
{
super( c, AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
}
@Override
protected IAEFluidStack createConfigStackFromItem( ItemStack is )
{
if( is.getItem() instanceof FluidDummyItem )
{
FluidStack fs = ( (FluidDummyItem) is.getItem() ).getFluidStack( is );
return fs != null ? AEFluidStack.fromFluidStack( fs ) : null;
}
return null;
}
}
@@ -39,7 +39,6 @@ import appeng.api.storage.data.IAEStack;
import appeng.api.util.IConfigManager;
import appeng.container.interfaces.IInventorySlotAware;
import appeng.me.helpers.MEMonitorHandler;
import appeng.me.storage.ItemCellInventory;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
@@ -54,7 +53,7 @@ public class PortableCellViewer extends MEMonitorHandler<IAEItemStack> implement
public PortableCellViewer( final ItemStack is, final int slot )
{
super( ItemCellInventory.getCell( is, null ) );
super( AEApi.instance().registries().cell().getCellInventory( is, null, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
this.ips = (IAEItemPowerStorage) is.getItem();
this.target = is;
this.inventorySlot = slot;
@@ -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() )
{
@@ -58,7 +58,6 @@ import appeng.api.config.FuzzyMode;
import appeng.api.implementations.items.IItemGroup;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.implementations.tiles.IColorableTile;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IStorageChannel;
@@ -78,7 +77,6 @@ import appeng.items.contents.CellUpgrades;
import appeng.items.misc.ItemPaintBall;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.me.helpers.BaseActionSource;
import appeng.me.storage.ItemCellInventoryHandler;
import appeng.tile.misc.TilePaint;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
@@ -119,8 +117,11 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
ItemStack paintBall = this.getColor( is );
final IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IMEInventory<IAEItemStack> inv = AEApi.instance()
.registries()
.cell()
.getCellInventory( is, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( inv != null )
{
final IAEItemStack option = inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.SIMULATE, new BaseActionSource() );
@@ -266,8 +267,11 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
{
ItemStack newColor = ItemStack.EMPTY;
final IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IMEInventory<IAEItemStack> inv = AEApi.instance()
.registries()
.cell()
.getCellInventory( is, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( inv != null )
{
final IItemList<IAEItemStack> itemList = inv
@@ -432,18 +436,13 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
{
super.addCheckedInformation( stack, world, lines, advancedTooltips );
final IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
.registries()
.cell()
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( cdi instanceof ItemCellInventoryHandler )
{
final ICellInventory cd = ( (ICellInventoryHandler) cdi ).getCellInv();
if( cd != null )
{
lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + ' ' + cd.getTotalBytes() + ' ' + GuiText.BytesUsed.getLocal() );
lines.add( cd.getStoredItemTypes() + " " + GuiText.Of.getLocal() + ' ' + cd.getTotalItemTypes() + ' ' + GuiText.Types.getLocal() );
}
}
AEApi.instance().client().addCellInformation( cdi, lines );
}
@Override
@@ -52,7 +52,6 @@ import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
@@ -64,7 +63,6 @@ import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.core.localization.PlayerMessages;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMatterCannon;
@@ -100,15 +98,7 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell<
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( cdi != null )
{
final ICellInventory<IAEItemStack> cd = cdi.getCellInv();
if( cd != null )
{
lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + ' ' + cd.getTotalBytes() + ' ' + GuiText.BytesUsed.getLocal() );
lines.add( cd.getStoredItemTypes() + " " + GuiText.Of.getLocal() + ' ' + cd.getTotalItemTypes() + ' ' + GuiText.Types.getLocal() );
}
}
AEApi.instance().client().addCellInformation( cdi, lines );
}
@Override
@@ -40,9 +40,7 @@ import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.items.IItemGroup;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
@@ -54,7 +52,6 @@ import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.items.contents.PortableCellViewer;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.me.storage.ItemCellInventoryHandler;
import appeng.util.Platform;
@@ -85,18 +82,13 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<
{
super.addCheckedInformation( stack, world, lines, advancedTooltips );
final IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
.registries()
.cell()
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( cdi instanceof ItemCellInventoryHandler )
{
final ICellInventory cd = ( (ICellInventoryHandler) cdi ).getCellInv();
if( cd != null )
{
lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + ' ' + cd.getTotalBytes() + ' ' + GuiText.BytesUsed.getLocal() );
lines.add( cd.getStoredItemTypes() + " " + GuiText.Of.getLocal() + ' ' + cd.getTotalItemTypes() + ' ' + GuiText.Types.getLocal() );
}
}
AEApi.instance().client().addCellInformation( cdi, lines );
}
@Override
@@ -19,16 +19,13 @@
package appeng.me.storage;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
@@ -59,7 +56,7 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
private short storedItems = 0;
private int storedItemCount = 0;
protected IItemList<T> cellItems;
protected final ItemStack i;
private final ItemStack i;
protected final IStorageCell<T> cellType;
protected final int itemsPerByte;
private boolean isPersisted = true;
@@ -73,32 +70,12 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
}
}
protected AbstractCellInventory( final ItemStack o, final ISaveProvider container, final int itemsPerByte ) throws AppEngException
protected AbstractCellInventory( final IStorageCell<T> cellType, final ItemStack o, final ISaveProvider container )
{
this.itemsPerByte = itemsPerByte;
if( o == null )
{
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
}
this.i = o;
final Item type = this.i.getItem();
if( type instanceof IStorageCell )
{
this.cellType = (IStorageCell<T>) this.i.getItem();
this.maxItemTypes = this.cellType.getTotalTypes( this.i );
}
else
{
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
}
if( !this.cellType.isStorageCell( this.i ) )
{
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
}
this.cellType = cellType;
this.itemsPerByte = this.cellType.getChannel().getUnitsPerByte();
this.maxItemTypes = this.cellType.getTotalTypes( this.i );
if( this.maxItemTypes > MAX_ITEM_TYPES )
{
@@ -116,11 +93,6 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
this.cellItems = null;
}
protected boolean isEmpty( final IMEInventory<T> meInventory )
{
return meInventory.getAvailableItems( getChannel().createList() ).isEmpty();
}
protected IItemList<T> getCellItems()
{
if( this.cellItems == null )
@@ -1,20 +1,3 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.storage;
@@ -23,50 +6,90 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.util.item.AEStack;
public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
public class BasicCellInventory<T extends IAEStack<T>> extends AbstractCellInventory<T>
{
private ItemCellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException
private final IStorageChannel<T> channel;
private BasicCellInventory( final IStorageCell<T> cellType, final ItemStack o, final ISaveProvider container )
{
super( o, container, 8 );
super( cellType, o, container );
this.channel = cellType.getChannel();
}
public static ICellInventoryHandler<IAEItemStack> getCell( final ItemStack o, final ISaveProvider container2 )
public static <T extends IAEStack<T>> ICellInventory<T> createInventory( final ItemStack o, final ISaveProvider container )
{
try
{
return new ItemCellInventoryHandler( new ItemCellInventory( o, container2 ) );
if( o == null )
{
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
}
final Item type = o.getItem();
final IStorageCell<T> cellType;
if( type instanceof IStorageCell )
{
cellType = (IStorageCell<T>) type;
}
else
{
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
}
if( !cellType.isStorageCell( o ) )
{
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
}
return new BasicCellInventory<T>( cellType, o, container );
}
catch( final AppEngException e )
{
AELog.error( e );
return null;
}
}
private static boolean isStorageCell( final ItemStack i )
public static <T extends AEStack<T>> boolean isCellOfType( final ItemStack input, IStorageChannel channel )
{
if( i == null )
if( input == null )
{
return false;
}
final Item type = input.getItem();
if( type instanceof IStorageCell )
{
return ( (IStorageCell) type ).getChannel() == channel;
}
return false;
}
public static boolean isCell( final ItemStack input )
{
if( input == null )
{
return false;
}
try
{
final Item type = i.getItem();
final Item type = input.getItem();
if( type instanceof IStorageCell )
{
return !( (IStorageCell) type ).storableInStorageCell();
@@ -80,27 +103,27 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
return false;
}
public static boolean isCell( final ItemStack i )
private boolean isStorageCell( final T input )
{
if( i == null )
if( !input.isItem() )
{
return false;
}
return isCell( ( (IAEItemStack) input ).getDefinition() );
}
final Item type = i.getItem();
if( type instanceof IStorageCell )
@SuppressWarnings( { "rawtypes", "unchecked" } )
private static boolean isCellEmpty( ICellInventory inv )
{
if( inv != null )
{
if( ( (IStorageCell) type ).getChannel() == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
return ( (IStorageCell) type ).isStorageCell( i );
}
return inv.getAvailableItems( inv.getChannel().createList() ).isEmpty();
}
return false;
return true;
}
@Override
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final IActionSource src )
public T injectItems( T input, Actionable mode, IActionSource src )
{
if( input == null )
{
@@ -111,23 +134,23 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
return null;
}
if( this.cellType.isBlackListed( this.i, input ) )
if( this.cellType.isBlackListed( this.getItemStack(), input ) )
{
return input;
}
// This is slightly hacky as it expects a read-only access, but fine for now.
// TODO: Guarantee a read-only access. E.g. provide an isEmpty() method and ensure CellInventory does not write
// any NBT data for empty cells instead of relying on an empty IItemContainer
if( ItemCellInventory.isStorageCell( input.getDefinition() ) )
if( this.isStorageCell( input ) )
{
final IMEInventory meInventory = getCell( input.createItemStack(), null );
if( meInventory != null && !this.isEmpty( meInventory ) )
final ICellInventory<?> meInventory = createInventory( ( (IAEItemStack) input ).createItemStack(), null );
if( !isCellEmpty( meInventory ) )
{
return input;
}
}
final IAEItemStack l = this.getCellItems().findPrecise( input );
final T l = this.getCellItems().findPrecise( input );
if( l != null )
{
final long remainingItemCount = this.getRemainingItemCount();
@@ -138,7 +161,7 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
if( input.getStackSize() > remainingItemCount )
{
final IAEItemStack r = input.copy();
final T r = input.copy();
r.setStackSize( r.getStackSize() - remainingItemCount );
if( mode == Actionable.MODULATE )
{
@@ -165,11 +188,11 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
{
if( input.getStackSize() > remainingItemCount )
{
final IAEItemStack toReturn = input.copy();
final T toReturn = input.copy();
toReturn.setStackSize( input.getStackSize() - remainingItemCount );
if( mode == Actionable.MODULATE )
{
final IAEItemStack toWrite = input.copy();
final T toWrite = input.copy();
toWrite.setStackSize( remainingItemCount );
this.cellItems.add( toWrite );
@@ -192,7 +215,7 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
}
@Override
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final IActionSource src )
public T extractItems( T request, Actionable mode, IActionSource src )
{
if( request == null )
{
@@ -201,9 +224,9 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
final long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );
IAEItemStack Results = null;
T Results = null;
final IAEItemStack l = this.getCellItems().findPrecise( request );
final T l = this.getCellItems().findPrecise( request );
if( l != null )
{
Results = l.copy();
@@ -232,20 +255,20 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
}
@Override
public IStorageChannel getChannel()
public IStorageChannel<T> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
return this.channel;
}
@Override
protected void loadCellItem( NBTTagCompound compoundTag, int stackSize )
{
// Now load the item stack
final ItemStack t;
final T t;
try
{
t = new ItemStack( compoundTag );
if( t.isEmpty() )
t = getChannel().createFromNBT( compoundTag );
if( t == null )
{
AELog.warn( "Removing item " + compoundTag + " from storage cell because the associated item type couldn't be found." );
return;
@@ -261,23 +284,11 @@ public class ItemCellInventory extends AbstractCellInventory<IAEItemStack>
throw ex;
}
t.setCount( stackSize );
t.setStackSize( stackSize );
if( t.getCount() > 0 )
if( stackSize > 0 )
{
try
{
this.cellItems.add( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( t ) );
}
catch( Throwable ex )
{
if( AEConfig.instance().isRemoveCrashingItemsOnLoad() )
{
AELog.warn( ex, "Removing item " + t + " from storage cell because processing the loaded item crashed." );
return;
}
throw ex;
}
this.cellItems.add( t );
}
}
}
@@ -43,9 +43,9 @@ import appeng.util.prioritylist.PrecisePriorityList;
* @version rv6 - 2018-01-23
* @since rv6 2018-01-23
*/
public abstract class AbstractCellInventoryHandler<T extends IAEStack<T>> extends MEInventoryHandler<T> implements ICellInventoryHandler<T>
public class BasicCellInventoryHandler<T extends IAEStack<T>> extends MEInventoryHandler<T> implements ICellInventoryHandler<T>
{
public AbstractCellInventoryHandler( final IMEInventory c, final IStorageChannel<T> channel )
public BasicCellInventoryHandler( final IMEInventory c, final IStorageChannel<T> channel )
{
super( c, channel );
@@ -88,7 +88,11 @@ public abstract class AbstractCellInventoryHandler<T extends IAEStack<T>> extend
final ItemStack is = config.getStackInSlot( x );
if( !is.isEmpty() )
{
priorityList.add( createConfigStackFromItem( is ) );
final T configItem = channel.createStack( is );
if( configItem != null )
{
priorityList.add( configItem );
}
}
}
@@ -108,8 +112,6 @@ public abstract class AbstractCellInventoryHandler<T extends IAEStack<T>> extend
}
}
protected abstract T createConfigStackFromItem( ItemStack is );
@Override
public ICellInventory getCellInv()
{
@@ -145,16 +147,4 @@ public abstract class AbstractCellInventoryHandler<T extends IAEStack<T>> extend
{
return Platform.openNbtData( this.getCellInv().getItemStack() );
}
public int getStatusForCell()
{
int val = this.getCellInv().getStatusForCell();
if( val == 1 && this.isPreformatted() )
{
val = 2;
}
return val;
}
}
@@ -56,7 +56,7 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
public static ICellInventoryHandler getCell( final ItemStack o )
{
return new ItemCellInventoryHandler( new CreativeCellInventory( o ) );
return new BasicCellInventoryHandler( new CreativeCellInventory( o ), AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
}
@Override
@@ -25,7 +25,7 @@ import appeng.api.config.Actionable;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.data.IAEStack;
@@ -37,7 +37,7 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
private final ICellHandler handler;
private final IChestOrDrive cord;
public DriveWatcher( final IMEInventory<T> i, final ItemStack is, final ICellHandler han, final IChestOrDrive cod )
public DriveWatcher( final ICellInventoryHandler<T> i, final ItemStack is, final ICellHandler han, final IChestOrDrive cod )
{
super( i, i.getChannel() );
this.is = is;
@@ -47,7 +47,7 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
public int getStatus()
{
return this.handler.getStatusForCell( this.is, this.getInternal() );
return this.handler.getStatusForCell( this.is, (ICellInventoryHandler) this.getInternal() );
}
@Override
@@ -1,44 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.storage;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEItemStack;
public class ItemCellInventoryHandler extends AbstractCellInventoryHandler<IAEItemStack>
{
public ItemCellInventoryHandler( IMEInventory c )
{
super( c, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
}
@Override
protected IAEItemStack createConfigStackFromItem( ItemStack is )
{
return AEItemStack.fromItemStack( is );
}
}
@@ -129,7 +129,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
}
@Override
public IStorageChannel getChannel()
public IStorageChannel<T> getChannel()
{
return this.internal.getChannel();
}
@@ -4,6 +4,7 @@ package appeng.tile.inventory;
import net.minecraft.item.ItemStack;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.IInternalItemHandler;
@@ -102,7 +103,11 @@ public class AppEngCellInventory implements IInternalItemHandler
{
if( this.handlerForSlot[slot] != null )
{
this.handlerForSlot[slot].getCellInv().persist();
final ICellInventory ci = this.handlerForSlot[slot].getCellInv();
if( ci != null )
{
ci.persist();
}
}
}
@@ -110,7 +115,9 @@ public class AppEngCellInventory implements IInternalItemHandler
{
if( this.handlerForSlot[slot] != null )
{
if( this.handlerForSlot[slot].getCellInv().getItemStack() != this.inv.getStackInSlot( slot ) )
final ICellInventory ci = this.handlerForSlot[slot].getCellInv();
if( ci == null || ci.getItemStack() != this.inv.getStackInSlot( slot ) )
{
this.handlerForSlot[slot] = null;
}
@@ -68,6 +68,7 @@ import appeng.api.networking.security.IActionSource;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ICellGuiHandler;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
@@ -123,8 +124,8 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
private boolean wasActive = false;
private AEColor paintedColor = AEColor.TRANSPARENT;
private boolean isCached = false;
private MEMonitorHandler<IAEItemStack> itemCell;
private MEMonitorHandler<IAEFluidStack> fluidCell;
private ChestMonitorHandler<IAEItemStack> itemCell;
private ChestMonitorHandler<IAEFluidStack> fluidCell;
private Accessor accessor;
private IFluidHandler fluidHandler;
@@ -282,7 +283,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
return null;
}
private <T extends IAEStack<T>> MEMonitorHandler<T> wrap( final IMEInventoryHandler<T> h )
private <T extends IAEStack<T>> ChestMonitorHandler<T> wrap( final IMEInventoryHandler<T> h )
{
if( h == null )
{
@@ -292,7 +293,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
final MEInventoryHandler<T> ih = new MEInventoryHandler<T>( h, h.getChannel() );
ih.setPriority( this.priority );
final MEMonitorHandler<T> g = new ChestMonitorHandler<T>( ih );
final ChestMonitorHandler<T> g = new ChestMonitorHandler<T>( ih );
g.addListener( new ChestNetNotifier<T>( h.getChannel() ), g );
return g;
@@ -719,15 +720,24 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
}
public boolean openGui( final EntityPlayer p, final ICellHandler ch, final ItemStack cell, final EnumFacing side )
public boolean openGui( final EntityPlayer p )
{
final ICellHandler ch = AEApi.instance().registries().cell().getHandler( this.getCell() );
try
{
final IMEInventoryHandler<IAEItemStack> invHandler = this.getHandler( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( ch != null && invHandler != null )
{
ch.openChestGui( p, this, ch, invHandler, cell, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
return true;
final ICellGuiHandler chg = AEApi.instance()
.registries()
.cell()
.getGuiHandler( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), this.getCell() );
if( chg != null )
{
chg.openChestGui( p, this, ch, invHandler, this.getCell(), AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
return true;
}
}
}
catch( final ChestNoHandler e )
@@ -740,8 +750,15 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
final IMEInventoryHandler<IAEFluidStack> invHandler = this.getHandler( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
if( ch != null && invHandler != null )
{
ch.openChestGui( p, this, ch, invHandler, cell, AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
return true;
final ICellGuiHandler chg = AEApi.instance()
.registries()
.cell()
.getGuiHandler( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), this.getCell() );
if( chg != null )
{
chg.openChestGui( p, this, ch, invHandler, this.getCell(), AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
return true;
}
}
}
catch( final ChestNoHandler e )
@@ -775,7 +792,10 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
@Override
public void saveChanges( final ICellInventory<?> cellInventory )
{
cellInventory.persist();
if( cellInventory != null )
{
cellInventory.persist();
}
this.world.markChunkDirty( this.pos, this );
}
@@ -844,14 +864,14 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
super( t );
}
private IMEInventoryHandler<T> getInternalHandler()
private ICellInventoryHandler<T> getInternalHandler()
{
final IMEInventoryHandler<T> h = this.getHandler();
if( h instanceof MEInventoryHandler )
{
return (IMEInventoryHandler<T>) ( (MEInventoryHandler<T>) h ).getInternal();
return (ICellInventoryHandler<T>) ( (MEInventoryHandler<T>) h ).getInternal();
}
return this.getHandler();
return (ICellInventoryHandler<T>) this.getHandler();
}
@Override
@@ -66,6 +66,7 @@ import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.InvOperation;
@@ -424,7 +425,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
if( extracted != null )
{
possible = extracted.getStackSize();
final IAEStack failed = chan.poweredInsert( energy, destination, extracted, this.mySrc );
final IAEStack failed = Platform.poweredInsert( energy, destination, extracted, this.mySrc );
if( failed != null )
{
+14 -7
View File
@@ -32,6 +32,7 @@ import java.util.WeakHashMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -1165,13 +1166,6 @@ public class Platform
return pos;
}
public static long nanoTime()
{
// if ( Configuration.INSTANCE.enableNetworkProfiler )
// return System.nanoTime();
return 0;
}
public static <T extends IAEStack<T>> T poweredExtraction( final IEnergySource energy, final IMEInventory<T> cell, final T request, final IActionSource src )
{
return poweredExtraction( energy, cell, request, src, Actionable.MODULATE );
@@ -1179,6 +1173,12 @@ public class Platform
public static <T extends IAEStack<T>> T poweredExtraction( final IEnergySource energy, final IMEInventory<T> cell, final T request, final IActionSource src, final Actionable mode )
{
Preconditions.checkNotNull( energy );
Preconditions.checkNotNull( cell );
Preconditions.checkNotNull( request );
Preconditions.checkNotNull( src );
Preconditions.checkNotNull( mode );
final T possible = cell.extractItems( request.copy(), Actionable.SIMULATE, src );
long retrieved = 0;
@@ -1221,6 +1221,12 @@ public class Platform
public static <T extends IAEStack<T>> T poweredInsert( final IEnergySource energy, final IMEInventory<T> cell, final T input, final IActionSource src, final Actionable mode )
{
Preconditions.checkNotNull( energy );
Preconditions.checkNotNull( cell );
Preconditions.checkNotNull( input );
Preconditions.checkNotNull( src );
Preconditions.checkNotNull( mode );
final T possible = cell.injectItems( input.copy(), Actionable.SIMULATE, src );
long stored = input.getStackSize();
@@ -1562,6 +1568,7 @@ public class Platform
return ItemStack.EMPTY;
}
// TODO wtf is this?
public static ItemStack getContainerItem( final ItemStack stackInSlot )
{
if( stackInSlot == null )