2013-12-27 23:59:59 +01:00
|
|
|
package appeng.items.storage;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
2014-07-13 03:02:40 +02:00
|
|
|
import java.util.Set;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-25 04:55:09 +01:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-25 04:55:09 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.FuzzyMode;
|
2014-09-08 21:22:15 +02:00
|
|
|
import appeng.api.config.IncludeExclude;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IItemGroup;
|
|
|
|
import appeng.api.implementations.items.IStorageCell;
|
2014-03-28 01:48:38 +01:00
|
|
|
import appeng.api.storage.ICellInventory;
|
|
|
|
import appeng.api.storage.ICellInventoryHandler;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.storage.IMEInventory;
|
|
|
|
import appeng.api.storage.StorageChannel;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
2014-02-25 04:55:09 +01:00
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-07-30 04:27:37 +02:00
|
|
|
import appeng.core.AEConfig;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.core.localization.GuiText;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.items.AEBaseItem;
|
2014-01-26 07:48:09 +01:00
|
|
|
import appeng.items.contents.CellConfig;
|
|
|
|
import appeng.items.contents.CellUpgrades;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.items.materials.MaterialType;
|
2014-02-25 04:55:09 +01:00
|
|
|
import appeng.util.InventoryAdaptor;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.util.Platform;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, IItemGroup
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
final MaterialType component;
|
|
|
|
final int totalBytes;
|
2014-06-12 16:37:08 +02:00
|
|
|
final int perType;
|
2013-12-27 23:59:59 +01:00
|
|
|
final double idleDrain;
|
|
|
|
|
|
|
|
public ItemBasicStorageCell(MaterialType whichCell, int Kilobytes) {
|
|
|
|
super( ItemBasicStorageCell.class, Kilobytes + "k" );
|
2014-09-20 23:26:30 +02:00
|
|
|
setFeature( EnumSet.of( AEFeature.StorageCells ) );
|
2014-01-20 17:41:37 +01:00
|
|
|
setMaxStackSize( 1 );
|
2013-12-27 23:59:59 +01:00
|
|
|
totalBytes = Kilobytes * 1024;
|
|
|
|
component = whichCell;
|
|
|
|
|
|
|
|
switch (component)
|
|
|
|
{
|
|
|
|
case Cell1kPart:
|
2014-02-07 20:30:08 +01:00
|
|
|
idleDrain = 0.5;
|
2014-06-12 16:37:08 +02:00
|
|
|
perType = 8;
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
case Cell4kPart:
|
|
|
|
idleDrain = 1.0;
|
2014-06-12 16:37:08 +02:00
|
|
|
perType = 32;
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
case Cell16kPart:
|
|
|
|
idleDrain = 1.5;
|
2014-06-12 16:37:08 +02:00
|
|
|
perType = 128;
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
case Cell64kPart:
|
|
|
|
idleDrain = 2.0;
|
2014-06-12 16:37:08 +02:00
|
|
|
perType = 512;
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
idleDrain = 0.0;
|
2014-06-12 16:37:08 +02:00
|
|
|
perType = 8;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b)
|
|
|
|
{
|
2014-07-28 07:11:34 +02:00
|
|
|
IMEInventory<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( i, null, StorageChannel.ITEMS );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-09-08 21:22:15 +02:00
|
|
|
if ( cdi instanceof ICellInventoryHandler )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-09-08 21:22:15 +02:00
|
|
|
ICellInventoryHandler CI = (ICellInventoryHandler) cdi;
|
|
|
|
|
2014-03-28 01:48:38 +01:00
|
|
|
ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv();
|
2014-09-08 21:22:15 +02:00
|
|
|
if (cd != null)
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-09-08 21:22:15 +02:00
|
|
|
l.add(cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " "
|
|
|
|
+ cd.getTotalBytes() + " "
|
|
|
|
+ GuiText.BytesUsed.getLocal());
|
|
|
|
|
|
|
|
l.add(cd.getStoredItemTypes() + " " + GuiText.Of.getLocal()
|
|
|
|
+ " " + cd.getTotalItemTypes() + " "
|
|
|
|
+ GuiText.Types.getLocal());
|
|
|
|
|
|
|
|
if ( CI.isPreformatted() )
|
|
|
|
{
|
|
|
|
String List = (CI.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included
|
|
|
|
: GuiText.Excluded ).getLocal();
|
|
|
|
|
|
|
|
if ( CI.isFuzzy() )
|
|
|
|
l.add( GuiText.Partitioned.getLocal() + " - " + List + " " + GuiText.Fuzzy.getLocal() );
|
|
|
|
else
|
|
|
|
l.add( GuiText.Partitioned.getLocal() + " - " + List + " " + GuiText.Precise.getLocal() );
|
|
|
|
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-08 21:22:15 +02:00
|
|
|
public int getBytes(ItemStack cellItem) {
|
2013-12-27 23:59:59 +01:00
|
|
|
return totalBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int BytePerType(ItemStack iscellItem)
|
|
|
|
{
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getTotalTypes(ItemStack cellItem)
|
|
|
|
{
|
|
|
|
return 63;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBlackListed(ItemStack cellItem, IAEItemStack requsetedAddition)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean storableInStorageCell()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isStorageCell(ItemStack i)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getIdleDrain()
|
|
|
|
{
|
|
|
|
return idleDrain;
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getUpgradesInventory(ItemStack is)
|
|
|
|
{
|
|
|
|
return new CellUpgrades( is, 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getConfigInventory(ItemStack is)
|
|
|
|
{
|
|
|
|
return new CellConfig( is );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FuzzyMode getFuzzyMode(ItemStack is)
|
|
|
|
{
|
|
|
|
String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return FuzzyMode.valueOf( fz );
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
return FuzzyMode.IGNORE_ALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode)
|
|
|
|
{
|
|
|
|
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-13 03:02:40 +02:00
|
|
|
public String getUnlocalizedGroupName(Set<ItemStack> others, ItemStack is)
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
return GuiText.StorageCells.getUnlocalized();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEditable(ItemStack is)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-29 19:43:09 +02:00
|
|
|
private boolean dissassembleDrive(ItemStack stack, World world, EntityPlayer player)
|
2014-02-25 04:55:09 +01:00
|
|
|
{
|
|
|
|
if ( player.isSneaking() )
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
InventoryPlayer pinv = player.inventory;
|
2014-07-28 07:11:34 +02:00
|
|
|
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( stack, null, StorageChannel.ITEMS );
|
2014-02-25 04:55:09 +01:00
|
|
|
if ( inv != null && pinv.getCurrentItem() == stack )
|
|
|
|
{
|
2014-06-26 04:57:49 +02:00
|
|
|
InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );
|
2014-02-25 04:55:09 +01:00
|
|
|
IItemList<IAEItemStack> list = inv.getAvailableItems( StorageChannel.ITEMS.createList() );
|
|
|
|
if ( list.isEmpty() && ia != null )
|
|
|
|
{
|
|
|
|
pinv.setInventorySlotContents( pinv.currentItem, null );
|
|
|
|
|
|
|
|
ItemStack extraB = ia.addItems( component.stack( 1 ) );
|
2014-06-26 04:57:49 +02:00
|
|
|
ItemStack extraA = ia.addItems( AEApi.instance().materials().materialEmptyStorageCell.stack( 1 ) );
|
2014-02-25 04:55:09 +01:00
|
|
|
|
|
|
|
if ( extraA != null )
|
|
|
|
player.dropPlayerItemWithRandomChoice( extraA, false );
|
|
|
|
if ( extraB != null )
|
|
|
|
player.dropPlayerItemWithRandomChoice( extraB, false );
|
|
|
|
|
2014-06-26 04:57:49 +02:00
|
|
|
if ( player.inventoryContainer != null )
|
|
|
|
player.inventoryContainer.detectAndSendChanges();
|
|
|
|
|
2014-02-25 04:55:09 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-29 19:43:09 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
|
|
|
{
|
|
|
|
dissassembleDrive( stack, world, player );
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
|
|
|
return dissassembleDrive( stack, world, player );
|
|
|
|
}
|
2014-07-30 04:27:37 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasContainerItem()
|
|
|
|
{
|
|
|
|
return AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getContainerItem(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
return AEApi.instance().materials().materialEmptyStorageCell.stack( 1 );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|