Initial Fluid Integration (#3510)

* Added Fluid Storage Cells

* Added Fluid Import Bus

* Added Fluid Export Bus

* Added Fluid Storage Bus

* Added Fluid Terminal.
While holding a item with the FLUID_HANDLER_ITEM_CAPABILITY, such as a tank
Left click on a fluid to extract the fluid
Right click to insert the fluid
This commit is contained in:
Brock
2018-06-12 03:55:33 +10:00
committed by yueh
parent 89bebc4385
commit d16677224a
126 changed files with 8031 additions and 778 deletions
@@ -0,0 +1,267 @@
/*
* 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.items.storage;
import java.util.List;
import java.util.Set;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
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;
import appeng.api.storage.data.IItemList;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.items.materials.MaterialType;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
/**
* @author DrummerMC
* @version rv6 - 2018-01-17
* @since rv6 2018-01-17
*/
public abstract class AbstractStorageCell<T extends IAEStack<T>> extends AEBaseItem implements IStorageCell<T>, IItemGroup
{
protected final MaterialType component;
protected final int totalBytes;
public AbstractStorageCell( final MaterialType whichCell, final int kilobytes )
{
this.setMaxStackSize( 1 );
this.totalBytes = kilobytes * 1024;
this.component = whichCell;
}
@SideOnly( Side.CLIENT )
@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() );
}
}
}
}
}
@Override
public int getBytes( final ItemStack cellItem )
{
return this.totalBytes;
}
@Override
public int getTotalTypes( final ItemStack cellItem )
{
return 63;
}
@Override
public boolean isBlackListed( final ItemStack cellItem, final T requestedAddition )
{
return false;
}
@Override
public boolean storableInStorageCell()
{
return false;
}
@Override
public boolean isStorageCell( final ItemStack i )
{
return true;
}
@Override
public String getUnlocalizedGroupName( final Set<ItemStack> others, final ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override
public boolean isEditable( final ItemStack is )
{
return true;
}
@Override
public IItemHandler getUpgradesInventory( final ItemStack is )
{
return new CellUpgrades( is, 2 );
}
@Override
public IItemHandler getConfigInventory( final ItemStack is )
{
return new CellConfig( is );
}
@Override
public FuzzyMode getFuzzyMode( final ItemStack is )
{
final String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
try
{
return FuzzyMode.valueOf( fz );
}
catch( final Throwable t )
{
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
{
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World world, final EntityPlayer player, final EnumHand hand )
{
this.disassembleDrive( player.getHeldItem( hand ), world, player );
return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
}
private boolean disassembleDrive( final ItemStack stack, final World world, final EntityPlayer player )
{
if( player.isSneaking() )
{
if( Platform.isClient() )
{
return false;
}
final InventoryPlayer playerInventory = player.inventory;
final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory( stack, null, getChannel() );
if( inv != null && playerInventory.getCurrentItem() == stack )
{
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player );
final IItemList<IAEItemStack> list = inv.getAvailableItems( getChannel().createList() );
if( list.isEmpty() && ia != null )
{
playerInventory.setInventorySlotContents( playerInventory.currentItem, ItemStack.EMPTY );
// drop core
final ItemStack extraB = ia.addItems( this.component.stack( 1 ) );
if( !extraB.isEmpty() )
{
player.dropItem( extraB, false );
}
// drop upgrades
final IItemHandler upgradesInventory = this.getUpgradesInventory( stack );
for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++ )
{
final ItemStack upgradeStack = upgradesInventory.getStackInSlot( upgradeIndex );
final ItemStack leftStack = ia.addItems( upgradeStack );
if( !leftStack.isEmpty() && upgradeStack.getItem() instanceof IUpgradeModule )
{
player.dropItem( upgradeStack, false );
}
}
// drop empty storage cell case
dropEmptyStorageCellCase( ia, player );
if( player.inventoryContainer != null )
{
player.inventoryContainer.detectAndSendChanges();
}
return true;
}
}
}
return false;
}
protected abstract void dropEmptyStorageCellCase( final InventoryAdaptor ia, final EntityPlayer player );
@Override
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
{
return this.disassembleDrive( player.getHeldItem( hand ), world, player ) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
@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." ) );
}
@Override
public boolean hasContainerItem( final ItemStack stack )
{
return AEConfig.instance().isFeatureEnabled( AEFeature.ENABLE_DISASSEMBLY_CRAFTING );
}
}