Slowly working towards crafting.

Merge branch 'master' of https://bitbucket.org/AlgorithmX2/appliedenergistics2 into rv1

Conflicts:
	client/gui/widgets/GuiImgButton.java
	core/localization/ButtonToolTips.java
This commit is contained in:
AlgorithmX2
2014-05-18 20:05:03 -05:00
10 changed files with 312 additions and 45 deletions
+131 -7
View File
@@ -1,35 +1,57 @@
package appeng.me.cache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridCache;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.IGridStorage;
import appeng.api.networking.crafting.ICraftingMedium;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.events.MENetworkCraftingCpuChange;
import appeng.api.networking.events.MENetworkCraftingPatternChange;
import appeng.api.networking.events.MENetworkPostCacheConstruction;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ICellProvider;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.crafting.TileCraftingStorageTile;
import appeng.tile.crafting.TileCraftingTile;
public class CraftingCache implements IGridCache, ICraftingProviderHelper
public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler
{
HashSet<CraftingCPUCluster> cpuClusters = new HashSet();
HashSet<ICraftingProvider> providers = new HashSet();
IGrid grid;
HashMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap();
boolean updateList = false;
public CraftingCache(IGrid g) {
grid = g;
}
public void afterCacheConstruction(MENetworkPostCacheConstruction cc)
{
IStorageGrid sg = grid.getCache( IStorageGrid.class );
sg.addCellProvider( this );
}
@Override
public void onUpdateTick()
{
@@ -85,18 +107,46 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper
}
@Override
public void addCraftingOption(ICraftingPatternDetails api)
public void addCraftingOption(ICraftingMedium medium, ICraftingPatternDetails api)
{
// TODO Auto-generated method stub
List<ICraftingMedium> details = craftingMethods.get( api );
if ( details == null )
{
details = new ArrayList<ICraftingMedium>();
details.add( medium );
craftingMethods.put( api, details );
}
else
details.add( medium );
}
private void updatePatterns()
{
IStorageGrid sg = grid.getCache( IStorageGrid.class );
// update the stuff that was in the list...
for (ICraftingPatternDetails details : craftingMethods.keySet())
for (IAEItemStack out : details.getOutputs())
{
out.reset();
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, out, new BaseActionSource() );
}
// erase list.
craftingMethods.clear();
// re-create list..
for (ICraftingProvider cp : providers)
{
cp.provideCrafting( this );
}
// new craftables!
for (ICraftingPatternDetails details : craftingMethods.keySet())
for (IAEItemStack out : details.getOutputs())
{
out.reset();
out.setCraftable( true );
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, out, new BaseActionSource() );
}
}
@Override
@@ -116,4 +166,78 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper
// nothing!
}
@Override
public List<IMEInventoryHandler> getCellArray(StorageChannel channel)
{
ArrayList<IMEInventoryHandler> list = new ArrayList<IMEInventoryHandler>( 1 );
list.add( this );
return list;
}
@Override
public int getPriority()
{
return Integer.MAX_VALUE;
}
@Override
public IAEStack extractItems(IAEStack request, Actionable mode, BaseActionSource src)
{
return null;
}
@Override
public IItemList getAvailableItems(IItemList out)
{
// add craftable items!
for (ICraftingPatternDetails details : craftingMethods.keySet())
for (IAEItemStack st : details.getOutputs())
out.addCrafting( st );
return out;
}
@Override
public StorageChannel getChannel()
{
return StorageChannel.ITEMS;
}
@Override
public AccessRestriction getAccess()
{
return AccessRestriction.WRITE;
}
@Override
public boolean isPrioritized(IAEStack input)
{
return true;
}
@Override
public IAEStack injectItems(IAEStack input, Actionable type, BaseActionSource src)
{
for (CraftingCPUCluster cpu : cpuClusters)
input = cpu.injectItems( input, type, src );
return input;
}
@Override
public boolean canAccept(IAEStack input)
{
for (CraftingCPUCluster cpu : cpuClusters)
if ( cpu.canAccept( (IAEItemStack) input ) )
return true;
return false;
}
@Override
public int getSlot()
{
return 0;
}
}
+49 -29
View File
@@ -12,12 +12,14 @@ import appeng.api.networking.IGridStorage;
import appeng.api.networking.events.MENetworkCellArrayUpdate;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.storage.IStackWatcher;
import appeng.api.networking.storage.IStackWatcherHost;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ICellContainer;
import appeng.api.storage.ICellProvider;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.StorageChannel;
@@ -36,8 +38,8 @@ public class GridStorageCache implements IStorageGrid
public SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
final HashSet<ICellContainer> activeCellContainers = new HashSet();
final HashSet<ICellContainer> inactiveCellContainers = new HashSet();
final HashSet<ICellProvider> activeCellProviders = new HashSet();
final HashSet<ICellProvider> inactiveCellProviders = new HashSet();
final public IGrid myGrid;
private NetworkInventoryHandler<IAEItemStack> myItemNetwork;
@@ -59,40 +61,50 @@ public class GridStorageCache implements IStorageGrid
fluidMonitor.onTick();
}
private void addCell(IGridNode node, ICellContainer cc)
@Override
public void addCellProvider(ICellProvider cc)
{
if ( node.isActive() && inactiveCellContainers.contains( cc ) )
if ( inactiveCellProviders.contains( cc ) )
{
inactiveCellContainers.remove( cc );
activeCellContainers.add( cc );
inactiveCellProviders.remove( cc );
activeCellProviders.add( cc );
BaseActionSource actionSrc = new BaseActionSource();
if ( cc instanceof IActionHost )
actionSrc = new MachineSource( (IActionHost) cc );
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
{
postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( AEApi.instance().storage().createItemList() ), new MachineSource( cc ) );
postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( AEApi.instance().storage().createItemList() ), actionSrc );
}
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ))
{
postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( AEApi.instance().storage().createFluidList() ), new MachineSource( cc ) );
postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( AEApi.instance().storage().createFluidList() ), actionSrc );
}
}
}
private void rmvCell(IGridNode node, ICellContainer cc)
@Override
public void removeCellProvider(ICellProvider cc)
{
if ( activeCellContainers.contains( cc ) )
if ( activeCellProviders.contains( cc ) )
{
inactiveCellContainers.add( cc );
activeCellContainers.remove( cc );
inactiveCellProviders.add( cc );
activeCellProviders.remove( cc );
BaseActionSource actionSrc = new BaseActionSource();
if ( cc instanceof IActionHost )
actionSrc = new MachineSource( (IActionHost) cc );
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
{
postChanges( StorageChannel.ITEMS, -1, h.getAvailableItems( AEApi.instance().storage().createItemList() ), new MachineSource( cc ) );
postChanges( StorageChannel.ITEMS, -1, h.getAvailableItems( AEApi.instance().storage().createItemList() ), actionSrc );
}
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ))
{
postChanges( StorageChannel.FLUIDS, -1, h.getAvailableItems( AEApi.instance().storage().createFluidList() ), new MachineSource( cc ) );
postChanges( StorageChannel.FLUIDS, -1, h.getAvailableItems( AEApi.instance().storage().createFluidList() ), actionSrc );
}
}
}
@@ -103,20 +115,27 @@ public class GridStorageCache implements IStorageGrid
myItemNetwork = null;
myFluidNetwork = null;
LinkedList<ICellContainer> ll = new LinkedList();
ll.addAll( inactiveCellContainers );
ll.addAll( activeCellContainers );
LinkedList<ICellProvider> ll = new LinkedList();
ll.addAll( inactiveCellProviders );
ll.addAll( activeCellProviders );
for (ICellContainer cc : ll)
for (ICellProvider cc : ll)
{
IGridNode node = cc.getActionableNode();
if ( node != null )
boolean Active = true;
if ( cc instanceof IActionHost )
{
if ( node.isActive() )
addCell( node, cc );
IGridNode node = ((IActionHost) cc).getActionableNode();
if ( node != null && node.isActive() )
Active = true;
else
rmvCell( node, cc );
Active = false;
}
if ( Active )
addCellProvider( cc );
else
removeCellProvider( cc );
}
itemMonitor.forceUpdate();
@@ -131,8 +150,8 @@ public class GridStorageCache implements IStorageGrid
ICellContainer cc = (ICellContainer) machine;
myGrid.postEvent( new MENetworkCellArrayUpdate() );
rmvCell( node, cc );
inactiveCellContainers.remove( cc );
removeCellProvider( cc );
inactiveCellProviders.remove( cc );
}
if ( machine instanceof IStackWatcherHost )
@@ -152,10 +171,11 @@ public class GridStorageCache implements IStorageGrid
if ( machine instanceof ICellContainer )
{
ICellContainer cc = (ICellContainer) machine;
inactiveCellContainers.add( cc );
inactiveCellProviders.add( cc );
myGrid.postEvent( new MENetworkCellArrayUpdate() );
addCell( node, cc );
if ( node.isActive() )
addCellProvider( cc );
}
if ( machine instanceof IStackWatcherHost )
@@ -175,7 +195,7 @@ public class GridStorageCache implements IStorageGrid
{
case FLUIDS:
myFluidNetwork = new NetworkInventoryHandler<IAEFluidStack>( StorageChannel.FLUIDS, security );
for (ICellContainer cc : activeCellContainers)
for (ICellProvider cc : activeCellProviders)
{
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( chan ))
myFluidNetwork.addNewStorage( h );
@@ -183,7 +203,7 @@ public class GridStorageCache implements IStorageGrid
break;
case ITEMS:
myItemNetwork = new NetworkInventoryHandler<IAEItemStack>( StorageChannel.ITEMS, security );
for (ICellContainer cc : activeCellContainers)
for (ICellProvider cc : activeCellProviders)
{
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( chan ))
myItemNetwork.addNewStorage( h );