Fuzzy support for Import and Export Buses.

This commit is contained in:
AlgorithmX2 2014-01-06 00:56:16 -06:00
parent 623b6e06d6
commit 5652ec30ec
2 changed files with 61 additions and 33 deletions

View file

@ -18,6 +18,7 @@ import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.parts.IPartCollsionHelper;
import appeng.api.parts.IPartRenderHelper;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.texture.CableBusTextures;
import appeng.core.sync.GuiBridge;
@ -110,10 +111,14 @@ public class PartExportBus extends PartSharedItemBus implements IGridTickable
bch.addBox( 6, 6, 11, 10, 10, 12 );
}
int itemToSend = 1;
boolean didSomething = false;
@Override
TickRateModulation doBusWork()
{
int itemToSend = 1;
itemToSend = 1;
didSomething = false;
switch (getInstalledUpgrades( Upgrades.SPEED ))
{
@ -140,20 +145,47 @@ public class PartExportBus extends PartSharedItemBus implements IGridTickable
try
{
InventoryAdaptor d = getHandler();
IMEInventory<IAEItemStack> inv = proxy.getStorage().getItemInventory();
IMEMonitor<IAEItemStack> inv = proxy.getStorage().getItemInventory();
IEnergyGrid energy = proxy.getEnergy();
FuzzyMode fzMode = (FuzzyMode) getConfigManager().getSetting( Settings.FUZZY_MODE );
if ( d != null )
{
for (int x = 0; x < availableSlots(); x++)
for (int x = 0; x < availableSlots() && itemToSend > 0; x++)
{
IAEItemStack ais = config.getAEStackInSlot( x );
if ( ais != null && itemToSend > 0 )
if ( ais == null || itemToSend <= 0 )
continue;
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
for (IAEItemStack o : inv.getStorageList().findFuzzy( ais, fzMode ))
{
pushItemIntoTarget( d, energy, fzMode, inv, o );
if ( itemToSend <= 0 )
break;
}
}
else
pushItemIntoTarget( d, energy, fzMode, inv, ais );
}
}
}
catch (GridAccessException e)
{
// :P
}
return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
private void pushItemIntoTarget(InventoryAdaptor d, IEnergyGrid energy, FuzzyMode fzMode, IMEInventory<IAEItemStack> inv, IAEItemStack ais)
{
ItemStack is = ais.getItemStack();
is.stackSize = itemToSend;
ItemStack o = d.simulateAdd( ais.getItemStack() );
ItemStack o = d.simulateAdd( is );
int canFit = o == null ? itemToSend : itemToSend - o.stackSize;
if ( canFit > 0 )
@ -178,17 +210,6 @@ public class PartExportBus extends PartSharedItemBus implements IGridTickable
}
}
}
}
}
catch (GridAccessException e)
{
// :P
}
return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)

View file

@ -145,6 +145,8 @@ public class PartImportBus extends PartSharedItemBus implements IGridTickable, I
worked = false;
InventoryAdaptor myAdaptor = getHandler();
FuzzyMode fzMode = (FuzzyMode) getConfigManager().getSetting( Settings.FUZZY_MODE );
if ( myAdaptor != null )
{
try
@ -182,7 +184,7 @@ public class PartImportBus extends PartSharedItemBus implements IGridTickable, I
Configured = true;
while (itemToSend > 0)
{
if ( importStuff( myAdaptor, ais, inv, energy ) )
if ( importStuff( myAdaptor, ais, inv, energy, fzMode ) )
break;
}
}
@ -192,7 +194,7 @@ public class PartImportBus extends PartSharedItemBus implements IGridTickable, I
{
while (itemToSend > 0)
{
if ( importStuff( myAdaptor, null, inv, energy ) )
if ( importStuff( myAdaptor, null, inv, energy, fzMode ) )
break;
}
}
@ -214,12 +216,17 @@ public class PartImportBus extends PartSharedItemBus implements IGridTickable, I
return doBusWork();
}
private boolean importStuff(InventoryAdaptor myAdaptor, IAEItemStack whatToImport, IMEMonitor<IAEItemStack> inv, IEnergySource energy)
private boolean importStuff(InventoryAdaptor myAdaptor, IAEItemStack whatToImport, IMEMonitor<IAEItemStack> inv, IEnergySource energy, FuzzyMode fzMode)
{
if ( itemToSend > 64 )
itemToSend = 64;
ItemStack newItems = myAdaptor.removeItems( itemToSend, whatToImport == null ? null : whatToImport.getItemStack(), configDest( inv ) );
ItemStack newItems;
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
newItems = myAdaptor.removeSimilarItems( itemToSend, whatToImport == null ? null : whatToImport.getItemStack(), fzMode, configDest( inv ) );
else
newItems = myAdaptor.removeItems( itemToSend, whatToImport == null ? null : whatToImport.getItemStack(), configDest( inv ) );
if ( newItems != null )
{
newItems.stackSize = (int) (Math.min( newItems.stackSize, energy.extractAEPower( newItems.stackSize, Actionable.SIMULATE, PowerMultiplier.CONFIG ) ) + 0.01);