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
@@ -1,91 +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.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import appeng.api.implementations.tiles.ITileStorageMonitorable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IExternalStorageHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.tile.misc.TileCondenser;
public class AEExternalHandler implements IExternalStorageHandler
{
@Override
public boolean canHandle( final TileEntity te, final EnumFacing d, final StorageChannel channel, final BaseActionSource mySrc )
{
if( channel == StorageChannel.ITEMS && te instanceof ITileStorageMonitorable )
{
return ( (ITileStorageMonitorable) te ).getMonitorable( d, mySrc ) != null;
}
return te instanceof TileCondenser;
}
@Override
public IMEInventory getInventory( final TileEntity te, final EnumFacing d, final StorageChannel channel, final BaseActionSource src )
{
if( te instanceof TileCondenser )
{
if( channel == StorageChannel.ITEMS )
{
return new VoidItemInventory( (TileCondenser) te );
}
else
{
return new VoidFluidInventory( (TileCondenser) te );
}
}
if( te instanceof ITileStorageMonitorable )
{
final ITileStorageMonitorable iface = (ITileStorageMonitorable) te;
final IStorageMonitorable sm = iface.getMonitorable( d, src );
if( channel == StorageChannel.ITEMS && sm != null )
{
final IMEInventory<IAEItemStack> ii = sm.getItemInventory();
if( ii != null )
{
return ii;
}
}
if( channel == StorageChannel.FLUIDS && sm != null )
{
final IMEInventory<IAEFluidStack> fi = sm.getFluidInventory();
if( fi != null )
{
return fi;
}
}
}
return null;
}
}
@@ -0,0 +1,33 @@
/*
* 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 appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.ticking.TickRateModulation;
public interface ITickingMonitor
{
TickRateModulation onTick();
void setActionSource( BaseActionSource actionSource );
}
@@ -1,225 +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.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class MEIInventoryWrapper implements IMEInventory<IAEItemStack>
{
private final IInventory target;
private final InventoryAdaptor adaptor;
public MEIInventoryWrapper( final IInventory m, final InventoryAdaptor ia )
{
this.target = m;
this.adaptor = ia;
}
@Override
public IAEItemStack injectItems( final IAEItemStack iox, final Actionable mode, final BaseActionSource src )
{
final ItemStack input = iox.getItemStack();
if( this.adaptor != null )
{
final ItemStack is = mode == Actionable.SIMULATE ? this.adaptor.simulateAdd( input ) : this.adaptor.addItems( input );
if( is == null )
{
return null;
}
return AEItemStack.create( is );
}
final ItemStack out = Platform.cloneItemStack( input );
if( mode == Actionable.MODULATE ) // absolutely no need for a first run in simulate mode.
{
for( int x = 0; x < this.target.getSizeInventory(); x++ )
{
final ItemStack t = this.target.getStackInSlot( x );
if( Platform.isSameItem( t, input ) )
{
final int oriStack = t.stackSize;
t.stackSize += out.stackSize;
this.target.setInventorySlotContents( x, t );
if( t.stackSize > this.target.getInventoryStackLimit() )
{
t.stackSize = this.target.getInventoryStackLimit();
}
if( t.stackSize > t.getMaxStackSize() )
{
t.stackSize = t.getMaxStackSize();
}
out.stackSize -= t.stackSize - oriStack;
if( out.stackSize <= 0 )
{
return null;
}
}
}
}
for( int x = 0; x < this.target.getSizeInventory(); x++ )
{
ItemStack t = this.target.getStackInSlot( x );
if( t == null )
{
t = Platform.cloneItemStack( input );
t.stackSize = out.stackSize;
if( t.stackSize > this.target.getInventoryStackLimit() )
{
t.stackSize = this.target.getInventoryStackLimit();
}
out.stackSize -= t.stackSize;
if( mode == Actionable.MODULATE )
{
this.target.setInventorySlotContents( x, t );
}
if( out.stackSize <= 0 )
{
return null;
}
}
}
return AEItemStack.create( out );
}
@Override
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src )
{
final ItemStack Req = request.getItemStack();
int request_stackSize = Req.stackSize;
if( request_stackSize > Req.getMaxStackSize() )
{
request_stackSize = Req.getMaxStackSize();
}
Req.stackSize = request_stackSize;
ItemStack Gathered = null;
if( this.adaptor != null )
{
Gathered = this.adaptor.removeItems( Req.stackSize, Req, null );
}
else
{
Gathered = request.getItemStack();
Gathered.stackSize = 0;
// try to find matching inventories that already have it...
for( int x = 0; x < this.target.getSizeInventory(); x++ )
{
final ItemStack sub = this.target.getStackInSlot( x );
if( Platform.isSameItem( sub, Req ) )
{
int reqNum = Req.stackSize;
if( reqNum > sub.stackSize )
{
reqNum = Req.stackSize;
}
ItemStack retrieved = null;
if( sub.stackSize < Req.stackSize )
{
retrieved = Platform.cloneItemStack( sub );
sub.stackSize = 0;
}
else
{
retrieved = sub.splitStack( Req.stackSize );
}
if( sub.stackSize <= 0 )
{
this.target.setInventorySlotContents( x, null );
}
else
{
this.target.setInventorySlotContents( x, sub );
}
if( retrieved != null )
{
Gathered.stackSize += retrieved.stackSize;
Req.stackSize -= retrieved.stackSize;
}
if( request_stackSize == Gathered.stackSize )
{
return AEItemStack.create( Gathered );
}
}
}
if( Gathered.stackSize == 0 )
{
return null;
}
}
return AEItemStack.create( Gathered );
}
@Override
public IItemList<IAEItemStack> getAvailableItems( final IItemList<IAEItemStack> out )
{
for( int x = 0; x < this.target.getSizeInventory(); x++ )
{
out.addStorage( AEItemStack.create( this.target.getStackInSlot( x ) ) );
}
return out;
}
@Override
public StorageChannel getChannel()
{
return StorageChannel.ITEMS;
}
}
@@ -44,7 +44,7 @@ import appeng.util.Platform;
import appeng.util.inv.ItemSlot;
public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMonitor
{
private final InventoryAdaptor adaptor;
@@ -139,6 +139,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
return StorageChannel.ITEMS;
}
@Override
public TickRateModulation onTick()
{
@@ -329,6 +330,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
return this.mySource;
}
@Override
public void setActionSource( final BaseActionSource mySource )
{
this.mySource = mySource;
@@ -49,18 +49,11 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
private static final ThreadLocal<LinkedList> DEPTH_MOD = new ThreadLocal<LinkedList>();
private static final ThreadLocal<LinkedList> DEPTH_SIM = new ThreadLocal<LinkedList>();
private static final Comparator<Integer> PRIORITY_SORTER = new Comparator<Integer>(){
private static final Comparator<Integer> PRIORITY_SORTER = ( o1, o2 ) -> ItemSorters.compareInt( o2, o1 );
@Override
public int compare( final Integer o1, final Integer o2 )
{
return ItemSorters.compareInt( o2, o1 );
}
};
private static int currentPass = 0;
private final StorageChannel myChannel;
private final SecurityCache security;
// final TreeMultimap<Integer, IMEInventoryHandler<T>> priorityInventory;
private final NavigableMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory;
private int myPass = 0;
@@ -68,9 +61,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
{
this.myChannel = chan;
this.security = security;
this.priorityInventory = new TreeMap<Integer, List<IMEInventoryHandler<T>>>( PRIORITY_SORTER ); // TreeMultimap.create(
// prioritySorter,
// hashSorter );
this.priorityInventory = new TreeMap<>( PRIORITY_SORTER );
}
public void addNewStorage( final IMEInventoryHandler<T> h )
@@ -79,7 +70,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
List<IMEInventoryHandler<T>> list = this.priorityInventory.get( priority );
if( list == null )
{
this.priorityInventory.put( priority, list = new ArrayList<IMEInventoryHandler<T>>() );
this.priorityInventory.put( priority, list = new ArrayList<>() );
}
list.add( h );
@@ -1,110 +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 appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.tile.misc.TileCondenser;
public class VoidFluidInventory implements IMEInventoryHandler<IAEFluidStack>
{
private final TileCondenser target;
public VoidFluidInventory( 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 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;
}
}
@@ -1,110 +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 appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.tile.misc.TileCondenser;
public class VoidItemInventory implements IMEInventoryHandler<IAEItemStack>
{
private final TileCondenser target;
public VoidItemInventory( final TileCondenser te )
{
this.target = te;
}
@Override
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final BaseActionSource src )
{
if( mode == Actionable.SIMULATE )
{
return null;
}
if( 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 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;
}
}