diff --git a/crafting/CraftingJob.java b/crafting/CraftingJob.java index b485ff0f..ac51afff 100644 --- a/crafting/CraftingJob.java +++ b/crafting/CraftingJob.java @@ -6,10 +6,15 @@ import java.util.HashSet; import java.util.Iterator; import net.minecraft.nbt.NBTTagCompound; +import appeng.api.AEApi; import appeng.api.config.Actionable; +import appeng.api.networking.storage.IStorageGrid; +import appeng.api.storage.IMEInventory; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.me.cache.CraftingCache; +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; public class CraftingJob implements ICraftingParent @@ -27,11 +32,48 @@ public class CraftingJob implements ICraftingParent ICraftingHost jobHost; public CraftingJob(ICraftingHost host, NBTTagCompound data) { - // TODO Auto-generated constructor stub + jobHost = host; + storage = AEApi.instance().storage().createItemList(); + prophecies = new HashSet(); + bottom = ArrayListMultimap.create(); } - public CraftingJob(ICraftingHost host, IAEItemStack what, Actionable mode) { + public CraftingJob(ICraftingHost host, IAEItemStack what, Actionable mode) throws CraftingMissingItemsException { + jobHost = host; + output = what.copy(); + storage = AEApi.instance().storage().createItemList(); + prophecies = new HashSet(); + bottom = ArrayListMultimap.create(); + CraftingCache cc = host.getGrid().getCache( CraftingCache.class ); + IStorageGrid sg = host.getGrid().getCache( IStorageGrid.class ); + + + IItemList available = AEApi.instance().storage().createItemList(); + IItemList missing = AEApi.instance().storage().createItemList(); + + calculateCrafting( cc, this, sg.getItemInventory().getAvailableItems( available ), missing, what, mode ); + + if ( ! missing.isEmpty() ) + { + if ( mode == Actionable.MODULATE ) + { + IMEInventory netStorage = sg.getItemInventory(); + + Iterator i = storage.iterator(); + while ( i.hasNext() ) + { + IAEItemStack item = i.next(); + netStorage.injectItems( item, mode, host.getActionSrc() ); + } + } + + throw new CraftingMissingItemsException( missing ); + } + } + + public void calculateCrafting( CraftingCache cc, ICraftingParent parent, IItemList available, IItemList missing, IAEItemStack what, Actionable mode) { + } public Collection getBottom() diff --git a/crafting/CraftingMissingItemsException.java b/crafting/CraftingMissingItemsException.java new file mode 100644 index 00000000..f1461fa0 --- /dev/null +++ b/crafting/CraftingMissingItemsException.java @@ -0,0 +1,17 @@ +package appeng.crafting; + +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; + +public class CraftingMissingItemsException extends Exception { + + private static final long serialVersionUID = -7517510681369528425L; + + final public IItemList missingItems; + + public CraftingMissingItemsException( IItemList missing ) + { + missingItems = missing; + } + +} diff --git a/crafting/ICraftingHost.java b/crafting/ICraftingHost.java index 6464c6d6..880afedc 100644 --- a/crafting/ICraftingHost.java +++ b/crafting/ICraftingHost.java @@ -1,15 +1,16 @@ package appeng.crafting; import net.minecraft.world.World; -import appeng.me.cache.CraftingCache; +import appeng.api.networking.IGrid; +import appeng.api.networking.security.BaseActionSource; public interface ICraftingHost { /** - * Get Crasfting cache for the host. + * Get Crafting cache for the host. */ - CraftingCache getCraftingCache(); + IGrid getGrid(); /** * required for crafting calculations. @@ -18,4 +19,11 @@ public interface ICraftingHost */ World getWorld(); + /** + * get source of moving items around. + * + * @return {@link BaseActionSource} of host. + */ + BaseActionSource getActionSrc(); + }