Skip to content

Commit

Permalink
fix export busses exporting items out of nowhere
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Jan 31, 2022
1 parent af1f5c3 commit c3a608e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ aebuild=7
aegroup=appeng
aebasename=appliedenergistics2
extended=extended_life
extendedversion=v49ab
extendedversion=v49ac
#########################################################
# Versions #
#########################################################
Expand Down
69 changes: 43 additions & 26 deletions src/main/java/appeng/parts/automation/PartExportBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

public class PartExportBus extends PartSharedItemBus implements ICraftingRequester
{
private final int[] failedCraftTriesSlot = {0,0,0,0,0,0,0,0,0};
private final int[] failedCraftTriesSlot = {0, 0, 0, 0, 0, 0, 0, 0, 0};

public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/export_bus_base" );

Expand Down Expand Up @@ -133,10 +133,7 @@ protected TickRateModulation doBusWork()
try
{
final InventoryAdaptor destination = this.getHandler();
final IMEMonitor<IAEItemStack> inv = this.getProxy()
.getStorage()
.getInventory(
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IEnergyGrid energy = this.getProxy().getEnergy();
final ICraftingGrid cg = this.getProxy().getCrafting();
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
Expand All @@ -152,16 +149,26 @@ protected TickRateModulation doBusWork()

final IAEItemStack ais = this.getConfig().getAEStackInSlot( slotToExport );

if( ais == null || this.itemToSend <= 0 ) continue;
if( ais == null || this.itemToSend <= 0 )
{
continue;
}

if ( this.craftOnly() ) {
if (this.failedCraftTriesSlot[x] <= 0) {
if( this.craftOnly() )
{
if( this.failedCraftTriesSlot[x] <= 0 )
{

this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;

if (this.didSomething) this.failedCraftTriesSlot[x] = 0;
else this.failedCraftTriesSlot[x] += 2;
if( this.didSomething )
{
this.failedCraftTriesSlot[x] = 0;
}
else
{
this.failedCraftTriesSlot[x] += 2;
}
}
this.failedCraftTriesSlot[x] -= 1;
continue;
Expand Down Expand Up @@ -190,13 +197,19 @@ protected TickRateModulation doBusWork()

if( this.itemToSend == before && this.isCraftingEnabled() )
{
if (this.failedCraftTriesSlot[x] <= 0) {
if( this.failedCraftTriesSlot[x] <= 0 )
{

this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;

if (this.didSomething) this.failedCraftTriesSlot[x] = 0;
else this.failedCraftTriesSlot[x] += 2;
if( this.didSomething )
{
this.failedCraftTriesSlot[x] = 0;
}
else
{
this.failedCraftTriesSlot[x] += 2;
}
}
this.failedCraftTriesSlot[x] -= 1;
}
Expand Down Expand Up @@ -336,11 +349,19 @@ private boolean isCraftingEnabled()

private void pushItemIntoTarget( final InventoryAdaptor d, final IEnergyGrid energy, final IMEInventory<IAEItemStack> inv, IAEItemStack ais )
{
ItemStack inputStack = ais.createItemStack();
ItemStack inputStack = ais.getCachedItemStack( ais.getStackSize() );

ItemStack toAdd = inputStack;
ItemStack remaining = d.simulateAdd( inputStack );

final ItemStack remaining = d.simulateAdd( inputStack );
// Store the stack in the cache for next time.
if( !remaining.isEmpty() )
{
ais.setCachedItemStack( remaining );
}
else
{
ais.setCachedItemStack( inputStack );
}

final long canFit = remaining.isEmpty() ? this.itemToSend : this.itemToSend - remaining.getCount();

Expand All @@ -354,13 +375,9 @@ private void pushItemIntoTarget( final InventoryAdaptor d, final IEnergyGrid ene
{
this.itemToSend -= itemsToAdd.getStackSize();

if( !remaining.isEmpty() )
{
toAdd = remaining;
}
toAdd.setCount( Ints.saturatedCast( canFit ) );
inputStack.setCount( Ints.saturatedCast( itemsToAdd.getStackSize() ) );

final ItemStack failed = d.addItems( toAdd );
final ItemStack failed = d.addItems( inputStack );
if( !failed.isEmpty() )
{
ais.setStackSize( failed.getCount() );
Expand Down

0 comments on commit c3a608e

Please sign in to comment.