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
commit 68993534d9
10 changed files with 312 additions and 45 deletions

View file

@ -27,7 +27,7 @@ public class GuiCraftingTerm extends GuiMEMonitorable
public void initGui()
{
super.initGui();
buttonList.add( clearBtn = new GuiImgButton( this.guiLeft + 92, this.guiTop + this.ySize - 156, Settings.ACTIONS, ActionItems.CLOSE ) );
buttonList.add( clearBtn = new GuiImgButton( this.guiLeft + 92, this.guiTop + this.ySize - 156, Settings.ACTIONS, ActionItems.STASH ) );
clearBtn.halfSize = true;
}

View file

@ -156,6 +156,8 @@ public class GuiImgButton extends GuiButton implements ITooltip
registerApp( 66, Settings.ACTIONS, ActionItems.WRENCH, ButtonToolTips.PartitionStorage, ButtonToolTips.PartitionStorageHint );
registerApp( 6, Settings.ACTIONS, ActionItems.CLOSE, ButtonToolTips.Clear, ButtonToolTips.ClearSettings );
registerApp( 6, Settings.ACTIONS, ActionItems.STASH, ButtonToolTips.Stash, ButtonToolTips.StashDesc );
registerApp( 8, Settings.ACTIONS, ActionItems.ENCODE, ButtonToolTips.Encode, ButtonToolTips.EncodeDescription );
registerApp( 4 + 3 * 16, Settings.ACTIONS, ActionItems.SUBSTITUTION, ButtonToolTips.Substitutions, ButtonToolTips.SubstitutionsDesc );

View file

@ -34,7 +34,7 @@ public enum ButtonToolTips
LevelType, LevelType_Energy, LevelType_Item, InventoryTweaks, TerminalStyle, TerminalStyle_Full, TerminalStyle_Tall, TerminalStyle_Small,
Encode, EncodeDescription, Substitutions, SubstitutionsOn, SubstitutionsOff, SubstitutionsDesc;
Stash, StashDesc, Encode, EncodeDescription, Substitutions, SubstitutionsOn, SubstitutionsOff, SubstitutionsDesc;
String root;

View file

@ -79,6 +79,38 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
return waitingToSend != null && !waitingToSend.isEmpty();
}
public void updateCraftingList()
{
Boolean accountedFor[] = new Boolean[patterns.getSizeInventory()];
if ( craftingList != null )
{
Iterator<ICraftingPatternDetails> i = craftingList.iterator();
while (i.hasNext())
{
ICraftingPatternDetails details = i.next();
boolean found = false;
for (int x = 0; x < accountedFor.length; x++)
{
ItemStack is = patterns.getStackInSlot( x );
if ( details.getPattern() == is )
{
accountedFor[x] = found = true;
}
}
if ( !found )
i.remove();
}
}
for (int x = 0; x < accountedFor.length; x++)
{
if ( accountedFor[x] == false )
addToCraftingList( patterns.getStackInSlot( x ) );
}
}
public void addToCraftingList(ItemStack is)
{
if ( is == null )
@ -673,7 +705,7 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
public void provideCrafting(ICraftingProviderHelper craftingTracker)
{
for (ICraftingPatternDetails details : craftingList)
craftingTracker.addCraftingOption( details );
craftingTracker.addCraftingOption( this, details );
}
}

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;
}
}

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 );

View file

@ -3,10 +3,14 @@ package appeng.me.cluster.implementations;
import java.util.Iterator;
import java.util.LinkedList;
import appeng.api.config.Actionable;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkCraftingCpuChange;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.WorldCoord;
import appeng.me.cluster.IAECluster;
import appeng.tile.crafting.TileCraftingTile;
@ -82,4 +86,22 @@ public class CraftingCPUCluster implements IAECluster
accelerator++;
}
public boolean canAccept(IAEStack input)
{
if ( input instanceof IAEItemStack )
{
// TODO Auto-generated method stub
}
return false;
}
public IAEStack injectItems(IAEStack input, Actionable type, BaseActionSource src)
{
if ( input instanceof IAEItemStack )
{
// TODO Auto-generated method stub
}
return input;
}
}

View file

@ -24,7 +24,7 @@ public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFl
private final static FluidTankInfo[] activeTank = new FluidTankInfo[] { new FluidTankInfo( null, 10000 ) };
private final static FluidTankInfo[] inactiveTank = new FluidTankInfo[] { new FluidTankInfo( null, 0 ) };
public TunnelType getTunnelType()
{
return TunnelType.FLUID;
@ -92,7 +92,7 @@ public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFl
{
for (PartP2PLiquids l : getOutputs())
{
IFluidHandler targ = getTarget();
IFluidHandler targ = l.getTarget();
if ( targ != null )
{
if ( targ.canFill( side.getOpposite(), input ) )
@ -128,6 +128,9 @@ public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFl
IFluidHandler getTarget()
{
if ( !proxy.isActive() )
return null;
if ( cachedTank != null )
return cachedTank;

View file

@ -92,12 +92,14 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock
int newmeta = (current & 3) | (formed ? 8 : 0) | (power ? 4 : 0);
if ( current != newmeta )
{
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, newmeta, 3 );
if ( isFormed() )
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
else
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
if ( isFormed() )
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
else
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
}
}
private void dropAndBreak()

View file

@ -0,0 +1,62 @@
package appeng.util.item;
import java.util.Collection;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemContainer;
public class ItemModList implements IItemContainer<IAEItemStack>
{
final IItemContainer<IAEItemStack> backingStore;
final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().createItemList();
public ItemModList(IItemContainer<IAEItemStack> backend) {
backingStore = backend;
}
@Override
public void add(IAEItemStack option)
{
IAEItemStack over = overrides.findPrecise( option );
if ( over == null )
{
over = backingStore.findPrecise( option );
if ( over == null )
overrides.add( option );
else
{
option.add( over );
overrides.add( option );
}
}
else
overrides.add( option );
}
@Override
public IAEItemStack findPrecise(IAEItemStack i)
{
IAEItemStack over = overrides.findPrecise( i );
if ( over == null )
return backingStore.findPrecise( i );
return over;
}
@Override
public Collection<IAEItemStack> findFuzzy(IAEItemStack input, FuzzyMode fuzzy)
{
Collection<IAEItemStack> overrrides = overrides.findFuzzy( input, fuzzy );
return overrrides;
}
@Override
public boolean isEmpty()
{
return overrides.isEmpty() && backingStore.isEmpty();
}
}