wip
This commit is contained in:
+14
-27
@@ -70,7 +70,6 @@ public class GridStorageCache implements IStorageGrid
|
|||||||
private final Map<IStorageChannel<? extends IAEStack>, NetworkInventoryHandler<?>> storageNetworks;
|
private final Map<IStorageChannel<? extends IAEStack>, NetworkInventoryHandler<?>> storageNetworks;
|
||||||
private final Map<IStorageChannel<? extends IAEStack>, NetworkMonitor<?>> storageMonitors;
|
private final Map<IStorageChannel<? extends IAEStack>, NetworkMonitor<?>> storageMonitors;
|
||||||
private MECraftingInventory localCache = null;
|
private MECraftingInventory localCache = null;
|
||||||
private final Int2ObjectMap<MECraftingInventory> extractableItemPriorityMap = new Int2ObjectOpenHashMap<>();
|
|
||||||
private int localDepth;
|
private int localDepth;
|
||||||
|
|
||||||
public GridStorageCache( final IGrid g )
|
public GridStorageCache( final IGrid g )
|
||||||
@@ -86,7 +85,6 @@ public class GridStorageCache implements IStorageGrid
|
|||||||
public void onUpdateTick()
|
public void onUpdateTick()
|
||||||
{
|
{
|
||||||
this.localCache = null;
|
this.localCache = null;
|
||||||
this.extractableItemPriorityMap.clear();
|
|
||||||
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.onTick() );
|
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.onTick() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,19 +174,6 @@ public class GridStorageCache implements IStorageGrid
|
|||||||
|
|
||||||
public MECraftingInventory getExtractableList( IActionSource src )
|
public MECraftingInventory getExtractableList( IActionSource src )
|
||||||
{
|
{
|
||||||
if( src instanceof MachineSource )
|
|
||||||
{
|
|
||||||
if( src.machine().isPresent() )
|
|
||||||
{
|
|
||||||
IActionHost machine = src.machine().get();
|
|
||||||
if( machine instanceof IInterfaceHost )
|
|
||||||
{
|
|
||||||
extractableItemPriorityMap.putIfAbsent( ( (IPriorityHost) machine ).getPriority(), new MECraftingInventory( getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), src, false, false, false ) );
|
|
||||||
return extractableItemPriorityMap.get( ( (IPriorityHost) machine ).getPriority() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( localCache == null )
|
if( localCache == null )
|
||||||
{
|
{
|
||||||
localCache = new MECraftingInventory( getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), src, false, false, false );
|
localCache = new MECraftingInventory( getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), src, false, false, false );
|
||||||
@@ -205,12 +190,13 @@ public class GridStorageCache implements IStorageGrid
|
|||||||
|
|
||||||
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource();
|
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource();
|
||||||
|
|
||||||
this.storageMonitors.forEach( ( channel, monitor ) -> {
|
this.storageMonitors.forEach( ( channel, monitor ) ->
|
||||||
for( final IMEInventoryHandler<?> h : cc.getCellArray( channel ) )
|
{
|
||||||
{
|
for( final IMEInventoryHandler<?> h : cc.getCellArray( channel ) )
|
||||||
tracker.postChanges( channel, 1, h, actionSrc );
|
{
|
||||||
}
|
tracker.postChanges( channel, 1, h, actionSrc );
|
||||||
} );
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
return tracker;
|
return tracker;
|
||||||
@@ -225,12 +211,13 @@ public class GridStorageCache implements IStorageGrid
|
|||||||
|
|
||||||
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource();
|
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource();
|
||||||
|
|
||||||
this.storageMonitors.forEach( ( channel, monitor ) -> {
|
this.storageMonitors.forEach( ( channel, monitor ) ->
|
||||||
for( final IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( channel ) )
|
{
|
||||||
{
|
for( final IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( channel ) )
|
||||||
tracker.postChanges( channel, -1, h, actionSrc );
|
{
|
||||||
}
|
tracker.postChanges( channel, -1, h, actionSrc );
|
||||||
} );
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
return tracker;
|
return tracker;
|
||||||
|
|||||||
@@ -19,14 +19,13 @@
|
|||||||
package appeng.util.inv;
|
package appeng.util.inv;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
|
||||||
|
|
||||||
import appeng.api.config.FuzzyMode;
|
import appeng.api.config.FuzzyMode;
|
||||||
import appeng.util.InventoryAdaptor;
|
import appeng.util.InventoryAdaptor;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
|
||||||
public class AdaptorItemHandler extends InventoryAdaptor
|
public class AdaptorItemHandler extends InventoryAdaptor
|
||||||
@@ -60,13 +59,13 @@ public class AdaptorItemHandler extends InventoryAdaptor
|
|||||||
|
|
||||||
if( destination != null )
|
if( destination != null )
|
||||||
{
|
{
|
||||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
if( !destination.canInsert( is ) )
|
||||||
if( extracted.isEmpty() )
|
|
||||||
{
|
{
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !destination.canInsert( extracted ) )
|
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||||
|
if( extracted.isEmpty() )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -109,21 +108,20 @@ public class AdaptorItemHandler extends InventoryAdaptor
|
|||||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||||
{
|
{
|
||||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
if( destination != null )
|
||||||
|
{
|
||||||
|
if( !destination.canInsert( is ) )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||||
if( extracted.isEmpty() )
|
if( extracted.isEmpty() )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( destination != null )
|
|
||||||
{
|
|
||||||
if( !destination.canInsert( extracted ) )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( rv.isEmpty() )
|
if( rv.isEmpty() )
|
||||||
{
|
{
|
||||||
// Use the first stack as a template for the result
|
// Use the first stack as a template for the result
|
||||||
@@ -163,13 +161,13 @@ public class AdaptorItemHandler extends InventoryAdaptor
|
|||||||
|
|
||||||
if( destination != null )
|
if( destination != null )
|
||||||
{
|
{
|
||||||
ItemStack simulated = this.itemHandler.extractItem( slot, amount, true );
|
if( !destination.canInsert( is ) )
|
||||||
if( simulated.isEmpty() )
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !destination.canInsert( simulated ) )
|
ItemStack simulated = this.itemHandler.extractItem( slot, amount, true );
|
||||||
|
if( simulated.isEmpty() )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -177,6 +175,10 @@ public class AdaptorItemHandler extends InventoryAdaptor
|
|||||||
|
|
||||||
// Attempt extracting it
|
// Attempt extracting it
|
||||||
extracted = this.itemHandler.extractItem( slot, amount, false );
|
extracted = this.itemHandler.extractItem( slot, amount, false );
|
||||||
|
if( !extracted.isEmpty() )
|
||||||
|
{
|
||||||
|
return extracted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return extracted;
|
return extracted;
|
||||||
@@ -196,15 +198,16 @@ public class AdaptorItemHandler extends InventoryAdaptor
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( destination != null && !destination.canInsert( is ) )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt extracting it
|
// Attempt extracting it
|
||||||
extracted = this.itemHandler.extractItem( slot, amount, true );
|
extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||||
|
if( !extracted.isEmpty() )
|
||||||
if( !extracted.isEmpty() && destination != null )
|
|
||||||
{
|
{
|
||||||
if( !destination.canInsert( extracted ) )
|
return extracted;
|
||||||
{
|
|
||||||
extracted = ItemStack.EMPTY; // Keep on looking...
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user