Remove External Storage Handler (#2417) (#2508)

* Implemented an adapter for IItemHandler so it can be used by the Storage Bus.
* Added update hook for inject/extract to ItemHandlerAdapter.
* Implemented ItemHandler and FluidHandler capabilities for the condenser, as replacement for the Void Inventories.
* Removed external storage handler, added capability-based way of accessing a monitorable ME network via the storage bus. Removed special case inventories for the matter condenser.
* Implemented InventoryAdaptor for IItemHandler. This also now fixes molecular assemblers interaction with part interfaces.
This commit is contained in:
shartte
2016-10-26 22:58:23 +02:00
committed by yueh
parent 057754c851
commit b977ee89ee
34 changed files with 1203 additions and 1065 deletions
@@ -0,0 +1,129 @@
/*
* 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.tile.misc;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.util.item.FluidList;
class CondenserFluidInventory implements IMEMonitor<IAEFluidStack>
{
private final TileCondenser target;
CondenserFluidInventory( final TileCondenser te )
{
this.target = te;
}
@Override
public IAEFluidStack injectItems( final IAEFluidStack input, final Actionable mode, final BaseActionSource src )
{
if( mode == Actionable.SIMULATE )
{
return null;
}
if( input != null )
{
this.target.addPower( input.getStackSize() / 1000.0 );
}
return null;
}
@Override
public IAEFluidStack extractItems( final IAEFluidStack request, final Actionable mode, final BaseActionSource src )
{
return null;
}
@Override
public IItemList<IAEFluidStack> getAvailableItems( final IItemList out )
{
return out;
}
@Override
public IItemList<IAEFluidStack> getStorageList()
{
return new FluidList();
}
@Override
public StorageChannel getChannel()
{
return StorageChannel.FLUIDS;
}
@Override
public AccessRestriction getAccess()
{
return AccessRestriction.WRITE;
}
@Override
public boolean isPrioritized( final IAEFluidStack input )
{
return false;
}
@Override
public boolean canAccept( final IAEFluidStack input )
{
return true;
}
@Override
public int getPriority()
{
return 0;
}
@Override
public int getSlot()
{
return 0;
}
@Override
public boolean validForPass( final int i )
{
return i == 2;
}
@Override
public void addListener( IMEMonitorHandlerReceiver<IAEFluidStack> l, Object verificationToken )
{
// Not implemented since the Condenser automatically voids everything, and there are no updates
}
@Override
public void removeListener( IMEMonitorHandlerReceiver<IAEFluidStack> l )
{
// Not implemented since we don't remember registered listeners anyway
}
}
@@ -0,0 +1,125 @@
/*
* 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.tile.misc;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.util.item.ItemList;
class CondenserItemInventory implements IMEMonitor<IAEItemStack>
{
private final TileCondenser target;
CondenserItemInventory( final TileCondenser te )
{
this.target = te;
}
@Override
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final BaseActionSource src )
{
if( mode == Actionable.MODULATE && input != null )
{
this.target.addPower( input.getStackSize() );
}
return null;
}
@Override
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src )
{
return null;
}
@Override
public IItemList<IAEItemStack> getAvailableItems( final IItemList out )
{
return out;
}
@Override
public IItemList<IAEItemStack> getStorageList()
{
return new ItemList();
}
@Override
public StorageChannel getChannel()
{
return StorageChannel.ITEMS;
}
@Override
public AccessRestriction getAccess()
{
return AccessRestriction.WRITE;
}
@Override
public boolean isPrioritized( final IAEItemStack input )
{
return false;
}
@Override
public boolean canAccept( final IAEItemStack input )
{
return true;
}
@Override
public int getPriority()
{
return 0;
}
@Override
public int getSlot()
{
return 0;
}
@Override
public boolean validForPass( final int i )
{
return i == 2;
}
@Override
public void addListener( IMEMonitorHandlerReceiver<IAEItemStack> l, Object verificationToken )
{
// Not implemented since the Condenser automatically voids everything, and there are no updates
}
@Override
public void removeListener( IMEMonitorHandlerReceiver<IAEItemStack> l )
{
// Not implemented since we don't remember registered listeners anyway
}
}
+174 -47
View File
@@ -19,22 +19,35 @@
package appeng.tile.misc;
import javax.annotation.Nullable;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.FluidTankProperties;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IStorageComponent;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.IStorageMonitorableAccessor;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.capabilities.Capabilities;
import appeng.tile.AEBaseInvTile;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
@@ -45,15 +58,20 @@ import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
public class TileCondenser extends AEBaseInvTile implements IFluidHandler, IConfigManagerHost, IConfigurableObject
public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, IConfigurableObject
{
public static final int BYTE_MULTIPLIER = 8;
private static final FluidTankInfo[] EMPTY = { new FluidTankInfo( null, 10 ) };
private final int[] sides = { 0, 1 };
private final int[] sides = {
0,
1
};
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 3 );
private final ConfigManager cm = new ConfigManager( this );
private final IItemHandler itemHandler = new ItemHandler();
private final IFluidHandler fluidHandler = new FluidHandler();
private final MEHandler meHandler = new MEHandler();
private double storedPower = 0;
@@ -222,47 +240,6 @@ public class TileCondenser extends AEBaseInvTile implements IFluidHandler, IConf
return this.sides;
}
@Override
public int fill( final EnumFacing from, final FluidStack resource, final boolean doFill )
{
if( doFill )
{
this.addPower( ( resource == null ? 0.0 : (double) resource.amount ) / 500.0 );
}
return resource == null ? 0 : resource.amount;
}
@Override
public FluidStack drain( final EnumFacing from, final FluidStack resource, final boolean doDrain )
{
return null;
}
@Override
public FluidStack drain( final EnumFacing from, final int maxDrain, final boolean doDrain )
{
return null;
}
@Override
public boolean canFill( final EnumFacing from, final Fluid fluid )
{
return true;
}
@Override
public boolean canDrain( final EnumFacing from, final Fluid fluid )
{
return false;
}
@Override
public FluidTankInfo[] getTankInfo( final EnumFacing from )
{
return EMPTY;
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
@@ -284,4 +261,154 @@ public class TileCondenser extends AEBaseInvTile implements IFluidHandler, IConf
{
this.storedPower = storedPower;
}
@Override
public boolean hasCapability( Capability<?> capability, EnumFacing facing )
{
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
{
return true;
}
else if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
{
return true;
}
else if( capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR )
{
return true;
}
return super.hasCapability( capability, facing );
}
@SuppressWarnings( "unchecked" )
@Override
public <T> T getCapability( Capability<T> capability, @Nullable EnumFacing facing )
{
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
{
return (T) itemHandler;
}
else if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
{
return (T) fluidHandler;
}
else if( capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR )
{
return (T) meHandler;
}
return super.getCapability( capability, facing );
}
private class ItemHandler implements IItemHandler
{
@Override
public int getSlots()
{
// We only expose the void slot
return 1;
}
@Override
public ItemStack getStackInSlot( int slot )
{
// The void slot never has any content
return null;
}
@Override
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
{
if( slot != 0 )
{
return stack;
}
if( !simulate && stack != null )
{
addPower( stack.stackSize );
}
return null;
}
@Override
public ItemStack extractItem( int slot, int amount, boolean simulate )
{
return null;
}
}
private static final IFluidTankProperties[] EMPTY = { new FluidTankProperties( null, 10, true, false ) };
/**
* A fluid handler that exposes a 10 bucket tank that can only be filled, and - when filled - will add power
* to this condenser.
*/
private class FluidHandler implements IFluidHandler
{
@Override
public IFluidTankProperties[] getTankProperties()
{
return EMPTY;
}
@Override
public int fill( FluidStack resource, boolean doFill )
{
if( doFill )
{
addPower( ( resource == null ? 0.0 : (double) resource.amount ) / 500.0 );
}
return resource == null ? 0 : resource.amount;
}
@Nullable
@Override
public FluidStack drain( FluidStack resource, boolean doDrain )
{
return null;
}
@Nullable
@Override
public FluidStack drain( int maxDrain, boolean doDrain )
{
return null;
}
}
/**
* This is used to expose a fake ME subnetwork that is only composed of this condenser tile. The purpose of this is to enable the condenser to
* override the {@link appeng.api.storage.IMEInventoryHandler#validForPass(int)} method to make sure a condenser is only ever used if an item
* can't go anywhere else.
*/
private class MEHandler implements IStorageMonitorableAccessor, IStorageMonitorable
{
private final CondenserFluidInventory fluidInventory = new CondenserFluidInventory( TileCondenser.this );
private final CondenserItemInventory itemInventory = new CondenserItemInventory( TileCondenser.this );
@Nullable
@Override
public IStorageMonitorable getInventory( BaseActionSource src )
{
return this;
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory()
{
return itemInventory;
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
return fluidInventory;
}
}
}
@@ -40,7 +40,6 @@ import net.minecraftforge.common.capabilities.Capability;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
import appeng.api.implementations.tiles.ITileStorageMonitorable;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingPatternDetails;
@@ -71,7 +70,7 @@ import appeng.util.Platform;
import appeng.util.inv.IInventoryDestination;
public class TileInterface extends AENetworkInvTile implements IGridTickable, ITileStorageMonitorable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IPriorityHost
public class TileInterface extends AENetworkInvTile implements IGridTickable, IInventoryDestination, IInterfaceHost, IPriorityHost
{
private final DualityInterface duality = new DualityInterface( this.getProxy(), this );
@@ -223,18 +222,6 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT
return this.duality.canInsert( stack );
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory()
{
return this.duality.getItemInventory();
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
return this.duality.getFluidInventory();
}
@Override
public IInventory getInventoryByName( final String name )
{
@@ -293,12 +280,6 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT
return this;
}
@Override
public IStorageMonitorable getMonitorable( final EnumFacing side, final BaseActionSource src )
{
return this.duality.getMonitorable( side, src, this );
}
@Override
public IConfigManager getConfigManager()
{