diff --git a/crafting/CraftingJob.java b/crafting/CraftingJob.java index 4709e9d9..f0b608d0 100644 --- a/crafting/CraftingJob.java +++ b/crafting/CraftingJob.java @@ -47,7 +47,8 @@ public class CraftingJob implements Runnable, ICraftingJob return output; } - public CraftingJob(World w, NBTTagCompound data) { + public CraftingJob(World w, NBTTagCompound data) + { world = wrapWorld( w ); storage = AEApi.instance().storage().createItemList(); prophecies = new HashSet(); @@ -65,7 +66,8 @@ public class CraftingJob implements Runnable, ICraftingJob return availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc ); } - public CraftingJob(World w, IGrid grid, BaseActionSource actionSrc, IAEItemStack what, ICraftingCallback callback) { + public CraftingJob(World w, IGrid grid, BaseActionSource actionSrc, IAEItemStack what, ICraftingCallback callback) + { world = wrapWorld( w ); output = what.copy(); storage = AEApi.instance().storage().createItemList(); @@ -76,6 +78,8 @@ public class CraftingJob implements Runnable, ICraftingJob ICraftingGrid cc = grid.getCache( ICraftingGrid.class ); IStorageGrid sg = grid.getCache( IStorageGrid.class ); original = new MECraftingInventory( sg.getItemInventory(), false, false, false ); + original.filterPermissions( actionSrc ); + tree = getCraftingTree( cc, what ); availableCheck = null; } diff --git a/crafting/MECraftingInventory.java b/crafting/MECraftingInventory.java index edb418fc..bfc98694 100644 --- a/crafting/MECraftingInventory.java +++ b/crafting/MECraftingInventory.java @@ -16,6 +16,9 @@ public class MECraftingInventory implements IMEInventory final IMEInventory target; final IItemList localCache; + private BaseActionSource usePermissions = null; + private final IItemList permissionsCache = AEApi.instance().storage().createItemList(); + final boolean logExtracted; final IItemList extractedCache; @@ -25,7 +28,28 @@ public class MECraftingInventory implements IMEInventory final boolean logMissing; final IItemList missingCache; - public MECraftingInventory() { + private void filter(IAEItemStack input, BaseActionSource src) + { + if ( usePermissions != null && input != null ) + { + if ( permissionsCache.findPrecise( input ) == null ) + { + IAEItemStack what = input.copy(); + what.setStackSize( 1 ); + permissionsCache.add( what ); + + IAEItemStack localItem = localCache.findPrecise( input ); + if ( localItem != null ) + { + IAEItemStack realSize = target.extractItems( input, Actionable.SIMULATE, usePermissions ); + localItem.setStackSize( realSize == null ? 0 : realSize.getStackSize() ); + } + } + } + } + + public MECraftingInventory() + { localCache = AEApi.instance().storage().createItemList(); extractedCache = null; injectedCache = null; @@ -37,11 +61,16 @@ public class MECraftingInventory implements IMEInventory par = null; } - public MECraftingInventory(MECraftingInventory parrent) { + public MECraftingInventory(MECraftingInventory parrent) + { this.target = parrent; this.logExtracted = parrent.logExtracted; this.logInjections = parrent.logInjections; this.logMissing = parrent.logMissing; + this.usePermissions = parrent.usePermissions; + + for (IAEItemStack is : parrent.permissionsCache) + permissionsCache.add( is ); if ( logMissing ) missingCache = AEApi.instance().storage().createItemList(); @@ -63,12 +92,21 @@ public class MECraftingInventory implements IMEInventory par = parrent; } - public MECraftingInventory(IMEInventory target, boolean logExtracted, boolean logInjections, boolean logMissing) { + public MECraftingInventory(IMEInventory target, boolean logExtracted, boolean logInjections, boolean logMissing) + { this.target = target; this.logExtracted = logExtracted; this.logInjections = logInjections; this.logMissing = logMissing; + if ( target instanceof MECraftingInventory ) + { + MECraftingInventory parrent = (MECraftingInventory) target; + this.usePermissions = parrent.usePermissions; + for (IAEItemStack is : parrent.permissionsCache) + permissionsCache.add( is ); + } + if ( logMissing ) missingCache = AEApi.instance().storage().createItemList(); else @@ -88,12 +126,19 @@ public class MECraftingInventory implements IMEInventory par = null; } + public void filterPermissions(BaseActionSource src) + { + usePermissions = src; + } + @Override public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src) { if ( input == null ) return null; + filter( input, src ); + if ( mode == Actionable.MODULATE ) { if ( logInjections ) @@ -110,6 +155,8 @@ public class MECraftingInventory implements IMEInventory if ( request == null ) return null; + filter( request, src ); + IAEItemStack list = localCache.findPrecise( request ); if ( list == null || list.getStackSize() == 0 ) return null; @@ -160,7 +207,7 @@ public class MECraftingInventory implements IMEInventory boolean failed = false; if ( logExtracted ) - { + { for (IAEItemStack extra : extractedCache) { IAEItemStack result = null; @@ -227,5 +274,12 @@ public class MECraftingInventory implements IMEInventory IAEItemStack list = localCache.findPrecise( what ); if ( list != null ) list.setStackSize( 0 ); + + if ( usePermissions != null ) + { + IAEItemStack hmm = what.copy(); + hmm.setStackSize( 1 ); + permissionsCache.add( hmm ); + } } }