Some more crafting work.
This commit is contained in:
parent
141be04aaf
commit
ea52fb5ebc
3 changed files with 72 additions and 5 deletions
|
@ -6,10 +6,15 @@ import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.Actionable;
|
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.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
|
import appeng.me.cache.CraftingCache;
|
||||||
|
|
||||||
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
public class CraftingJob implements ICraftingParent
|
public class CraftingJob implements ICraftingParent
|
||||||
|
@ -27,11 +32,48 @@ public class CraftingJob implements ICraftingParent
|
||||||
ICraftingHost jobHost;
|
ICraftingHost jobHost;
|
||||||
|
|
||||||
public CraftingJob(ICraftingHost host, NBTTagCompound data) {
|
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<IAEItemStack> available = AEApi.instance().storage().createItemList();
|
||||||
|
IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
|
||||||
|
|
||||||
|
calculateCrafting( cc, this, sg.getItemInventory().getAvailableItems( available ), missing, what, mode );
|
||||||
|
|
||||||
|
if ( ! missing.isEmpty() )
|
||||||
|
{
|
||||||
|
if ( mode == Actionable.MODULATE )
|
||||||
|
{
|
||||||
|
IMEInventory<IAEItemStack> netStorage = sg.getItemInventory();
|
||||||
|
|
||||||
|
Iterator<IAEItemStack> 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<IAEItemStack> available, IItemList<IAEItemStack> missing, IAEItemStack what, Actionable mode) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<CraftingTask> getBottom()
|
public Collection<CraftingTask> getBottom()
|
||||||
|
|
17
crafting/CraftingMissingItemsException.java
Normal file
17
crafting/CraftingMissingItemsException.java
Normal file
|
@ -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<IAEItemStack> missingItems;
|
||||||
|
|
||||||
|
public CraftingMissingItemsException( IItemList<IAEItemStack> missing )
|
||||||
|
{
|
||||||
|
missingItems = missing;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,15 +1,16 @@
|
||||||
package appeng.crafting;
|
package appeng.crafting;
|
||||||
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import appeng.me.cache.CraftingCache;
|
import appeng.api.networking.IGrid;
|
||||||
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
|
|
||||||
public interface ICraftingHost
|
public interface ICraftingHost
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Crasfting cache for the host.
|
* Get Crafting cache for the host.
|
||||||
*/
|
*/
|
||||||
CraftingCache getCraftingCache();
|
IGrid getGrid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* required for crafting calculations.
|
* required for crafting calculations.
|
||||||
|
@ -18,4 +19,11 @@ public interface ICraftingHost
|
||||||
*/
|
*/
|
||||||
World getWorld();
|
World getWorld();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get source of moving items around.
|
||||||
|
*
|
||||||
|
* @return {@link BaseActionSource} of host.
|
||||||
|
*/
|
||||||
|
BaseActionSource getActionSrc();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue