Skip to content

Commit

Permalink
Merge branch 'fastutil' into AE2-Omnifactory
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Jun 14, 2021
2 parents 7b91da5 + 08952b4 commit 6f42876
Show file tree
Hide file tree
Showing 13 changed files with 1,118 additions and 1,047 deletions.
9 changes: 9 additions & 0 deletions src/api/java/appeng/api/storage/data/IAEItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,13 @@ public interface IAEItemStack extends IAEStack<IAEItemStack>
* @return definition stack
*/
ItemStack getDefinition();

/**
* Compare this AE item stack to another item stack, but ignores
* the amount. It checks the item type, NBT and damage values.
*
* @param is An item stack
*/
boolean equals(ItemStack is);

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map.Entry;
import java.util.stream.Collectors;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import net.minecraft.inventory.InventoryCrafting;
Expand Down Expand Up @@ -233,8 +234,9 @@ public boolean canAccept( final IAEItemStack input )

public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
{
if( !( input instanceof IAEItemStack ) )
{
// also stop accepting items when the job is complete, i.e. to prevent re-insertion when pushing out
// items during storeItems
if (input == null || isComplete) {
return input;
}

Expand Down Expand Up @@ -431,6 +433,11 @@ private void completeJob()
AELog.crafting( LOG_MARK_AS_COMPLETE, logStack );
}

// Waiting for can potentially contain items at this point, if the user has a 64xplank->64xbutton processing
// recipe for example, but only requested 1xbutton. We just ignore the rest since it will be dumped
// back into the network inventory regardless. For this to work it's important that injectItems in this CPU
// does not accept any further items if isComplete is true.
this.waitingFor.resetStatus();
this.remainingItemCount = 0;
this.startItemCount = 0;
this.lastTime = 0;
Expand Down Expand Up @@ -828,6 +835,7 @@ private void executeCrafting( final IEnergyGrid eg, final CraftingGridCache cc )

private void storeItems()
{
Preconditions.checkState(isComplete, "CPU should be complete to prevent re-insertion when dumping items");
final IGrid g = this.getGrid();

if( g == null )
Expand All @@ -838,23 +846,24 @@ private void storeItems()
final IStorageGrid sg = g.getCache( IStorageGrid.class );
final IMEInventory<IAEItemStack> ii = sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );

for( IAEItemStack is : this.inventory.getItemList() )
IItemList<IAEItemStack> itemList = this.inventory.getItemList();
for( IAEItemStack is : itemList )
{
is = this.inventory.extractItems( is.copy(), Actionable.MODULATE, this.machineSrc );
this.postChange( is, this.machineSrc );
IAEItemStack remainder = ii.injectItems( is.copy(), Actionable.MODULATE, this.machineSrc );

if( is != null )
// The network was unable to receive all of the items, i.e. no or not enough storage space left
if( remainder != null )
{
this.postChange( is, this.machineSrc );
is = ii.injectItems( is, Actionable.MODULATE, this.machineSrc );
is.setStackSize( remainder.getStackSize() );
}

if( is != null )
else
{
this.inventory.injectItems( is, Actionable.MODULATE, this.machineSrc );
is.reset();
}
}

if( this.inventory.getItemList().isEmpty() )
if( itemList.isEmpty() )
{
this.inventory = new MECraftingInventory();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/appeng/me/storage/BasicCellInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ protected boolean loadCellItem( NBTTagCompound compoundTag, int stackSize )
}

t.setStackSize( stackSize );
t.setCraftable( false );

if( stackSize > 0 )
{
Expand Down
1 change: 0 additions & 1 deletion src/main/java/appeng/parts/misc/ItemHandlerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ public List<IAEItemStack> update()
if( storedStack == null )
{
changes.add( cachedStack.setStackSize( -cachedStack.getStackSize() ) );
cachedAeStacksIterator.remove();
}
else if( cachedStack.getStackSize() != storedStack.getStackSize() )
{
Expand Down
Loading

0 comments on commit 6f42876

Please sign in to comment.