diff --git a/me/storage/NetworkInventoryHandler.java b/me/storage/NetworkInventoryHandler.java index 224fe21a2..f65db1a74 100644 --- a/me/storage/NetworkInventoryHandler.java +++ b/me/storage/NetworkInventoryHandler.java @@ -59,10 +59,13 @@ public class NetworkInventoryHandler> implements IMEInvent static int currentPass = 0; int myPass = 0; - static final ThreadLocal depth = new ThreadLocal(); + static final ThreadLocal depthMod = new ThreadLocal(); + static final ThreadLocal depthSim = new ThreadLocal(); - private LinkedList getDepth() + private LinkedList getDepth(Actionable type) { + ThreadLocal depth = type == Actionable.MODULATE ? depthMod : depthSim; + LinkedList s = depth.get(); if ( s == null ) @@ -71,9 +74,9 @@ public class NetworkInventoryHandler> implements IMEInvent return s; } - private boolean diveList(NetworkInventoryHandler networkInventoryHandler) + private boolean diveList(NetworkInventoryHandler networkInventoryHandler, Actionable type) { - LinkedList cDepth = getDepth(); + LinkedList cDepth = getDepth( type ); if ( cDepth.contains( networkInventoryHandler ) ) return true; @@ -81,9 +84,10 @@ public class NetworkInventoryHandler> implements IMEInvent return false; } - private boolean diveIteration(NetworkInventoryHandler networkInventoryHandler) + private boolean diveIteration(NetworkInventoryHandler networkInventoryHandler, Actionable type) { - if ( getDepth().isEmpty() ) + LinkedList cDepth = getDepth( type ); + if ( cDepth.isEmpty() ) { currentPass++; myPass = currentPass; @@ -96,13 +100,13 @@ public class NetworkInventoryHandler> implements IMEInvent myPass = currentPass; } - getDepth().push( this ); + cDepth.push( this ); return false; } - private void surface(NetworkInventoryHandler networkInventoryHandler) + private void surface(NetworkInventoryHandler networkInventoryHandler, Actionable type) { - if ( getDepth().pop() != this ) + if ( getDepth( type ).pop() != this ) throw new RuntimeException( "Invalid Access to Networked Storage API detected." ); } @@ -141,12 +145,12 @@ public class NetworkInventoryHandler> implements IMEInvent @Override public T injectItems(T input, Actionable type, BaseActionSource src) { - if ( diveList( this ) ) + if ( diveList( this, type ) ) return input; if ( testPermission( src, SecurityPermissions.INJECT ) ) { - surface( this ); + surface( this, type ); return input; } @@ -175,7 +179,7 @@ public class NetworkInventoryHandler> implements IMEInvent } } - surface( this ); + surface( this, type ); return input; } @@ -183,12 +187,12 @@ public class NetworkInventoryHandler> implements IMEInvent @Override public T extractItems(T request, Actionable mode, BaseActionSource src) { - if ( diveList( this ) ) + if ( diveList( this, mode ) ) return null; if ( testPermission( src, SecurityPermissions.EXTRACT ) ) { - surface( this ); + surface( this, mode ); return null; } @@ -213,7 +217,7 @@ public class NetworkInventoryHandler> implements IMEInvent } } - surface( this ); + surface( this, mode ); if ( output.getStackSize() <= 0 ) return null; @@ -224,7 +228,7 @@ public class NetworkInventoryHandler> implements IMEInvent @Override public IItemList getAvailableItems(IItemList out) { - if ( diveIteration( this ) ) + if ( diveIteration( this, Actionable.SIMULATE ) ) return out; // for (Entry> h : prorityInventory.entries()) @@ -232,7 +236,7 @@ public class NetworkInventoryHandler> implements IMEInvent for (IMEInventoryHandler j : i) out = j.getAvailableItems( out ); - surface( this ); + surface( this, Actionable.SIMULATE ); return out; }