fix #16
This commit is contained in:
@@ -71,23 +71,28 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSource src )
|
||||
{
|
||||
if( this.cache.cachedAeStacks.length == 0 ) this.cache.update();
|
||||
|
||||
ItemStack orgInput = iox.createItemStack();
|
||||
ItemStack remaining = orgInput;
|
||||
|
||||
int slotCount = this.itemHandler.getSlots();
|
||||
boolean simulate = ( type == Actionable.SIMULATE );
|
||||
List<Pair<Integer,Integer>> injectedList = new ArrayList<>();
|
||||
List<Pair<Integer, Integer>> injectedList = new ArrayList<>();
|
||||
// This uses a brute force approach and tries to jam it in every slot the inventory exposes.
|
||||
for( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
|
||||
{
|
||||
int countPre = remaining.getCount();
|
||||
remaining = this.itemHandler.insertItem( i, remaining, simulate );
|
||||
int countPos = remaining.getCount();
|
||||
if (remaining.isEmpty()){
|
||||
injectedList.add( Pair.of( i,countPre ) );
|
||||
if( remaining.isEmpty() )
|
||||
{
|
||||
injectedList.add( Pair.of( i, countPre ) );
|
||||
break;
|
||||
}
|
||||
else if (countPos > countPre) {
|
||||
injectedList.add( Pair.of( i,countPos - countPre ) );
|
||||
else if( countPos > countPre )
|
||||
{
|
||||
injectedList.add( Pair.of( i, countPos - countPre ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,8 +105,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
|
||||
for ( Pair<Integer, Integer> pair : injectedList )
|
||||
for( Pair<Integer, Integer> pair : injectedList )
|
||||
{
|
||||
if( this.cache.cachedAeStacks[pair.getKey()] == null )
|
||||
{
|
||||
@@ -112,6 +116,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
this.cache.cachedAeStacks[pair.getKey()].incStackSize( pair.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( remaining );
|
||||
@@ -161,8 +166,6 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
extracted.setCount( remainingCurrentSlot );
|
||||
}
|
||||
|
||||
extractedList.add( Pair.of( i, extracted.getCount() ) );
|
||||
|
||||
// We're just gonna use the first stack we get our hands on as the template for the rest.
|
||||
// In case some stupid itemhandler (aka forge) returns an internal state we have to do a second
|
||||
// expensive copy again.
|
||||
@@ -181,6 +184,11 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
|
||||
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
||||
|
||||
if (!gathered.isEmpty())
|
||||
{
|
||||
extractedList.add( Pair.of( i, gathered.getCount() ) );
|
||||
}
|
||||
|
||||
// Done?
|
||||
if( remainingSize <= 0 )
|
||||
{
|
||||
@@ -192,13 +200,21 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
{
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
|
||||
|
||||
for ( Pair<Integer, Integer> pair : extractedList )
|
||||
{
|
||||
this.cache.cachedAeStacks[pair.getKey()].decStackSize( pair.getValue() );
|
||||
if( this.cache.cachedAeStacks[pair.getKey()].getStackSize() == 0 )
|
||||
if (pair.getKey() >= this.cache.cachedAeStacks.length)
|
||||
{
|
||||
this.cache.cachedAeStacks[pair.getKey()] = null;
|
||||
this.cache.update();
|
||||
break;
|
||||
}
|
||||
if( this.cache.cachedAeStacks[pair.getKey()] != null )
|
||||
{
|
||||
this.cache.cachedAeStacks[pair.getKey()].decStackSize( pair.getValue() );
|
||||
if( this.cache.cachedAeStacks[pair.getKey()].getStackSize() == 0 )
|
||||
{
|
||||
this.cache.cachedAeStacks[pair.getKey()] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
@@ -71,9 +66,9 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
|
||||
if( this.cache.cachedAeStacks.length == 0 ) this.cache.update();
|
||||
boolean found = false;
|
||||
for (IAEItemStack iaeItemStack : this.cache.cachedAeStacks)
|
||||
for( IAEItemStack iaeItemStack : this.cache.cachedAeStacks )
|
||||
{
|
||||
if( iaeItemStack == null )
|
||||
{
|
||||
@@ -85,11 +80,18 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
iaeItemStack.incStackSize( iox.getStackSize() );
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
if( !found )
|
||||
{
|
||||
this.cache.cachedAeStacks = Arrays.copyOf( this.cache.cachedAeStacks, this.cache.cachedAeStacks.length + 1 );
|
||||
this.cache.cachedAeStacks[this.cache.cachedAeStacks.length - 1] = iox.copy();
|
||||
IAEItemStack inserted = iox.copy();
|
||||
if (remaining.isEmpty())
|
||||
{
|
||||
this.cache.cachedAeStacks[this.cache.cachedAeStacks.length - 1] = inserted;
|
||||
} else {
|
||||
this.cache.cachedAeStacks[this.cache.cachedAeStacks.length - 1] = inserted.setStackSize( iox.getStackSize() - remaining.getCount() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( remaining );
|
||||
@@ -99,8 +101,8 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
ItemStack requestedItemStack = request.createItemStack();
|
||||
int remainingSize = requestedItemStack.getCount();
|
||||
ItemStack requestedItemStack = request.getDefinition();
|
||||
int remainingSize = (int) Math.min( Integer.MAX_VALUE, request.getStackSize());
|
||||
|
||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||
|
||||
@@ -126,7 +128,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
for ( int i = 0; i < this.cache.cachedAeStacks.length; i++ )
|
||||
{
|
||||
IAEItemStack iaeItemStack = this.cache.cachedAeStacks[i];
|
||||
if( iaeExtracted.equals( iaeItemStack ) )
|
||||
if( iaeExtracted.isSameType( iaeItemStack ) )
|
||||
{
|
||||
if( iaeExtracted.getStackSize() >= iaeItemStack.getStackSize() )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user