Expose CraftingTask#missing
This commit is contained in:
		@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternContainer;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.api.util.IItemStackList;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.nbt.NBTTagCompound;
 | 
			
		||||
 | 
			
		||||
@@ -45,11 +46,6 @@ public interface ICraftingTask {
 | 
			
		||||
     */
 | 
			
		||||
    void reschedule();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Clear out missing items. Tasks will run all possible tasks, before reporting missing items again.
 | 
			
		||||
     */
 | 
			
		||||
    void clearMissing();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return the amount of items that have to be crafted
 | 
			
		||||
     */
 | 
			
		||||
@@ -108,18 +104,17 @@ public interface ICraftingTask {
 | 
			
		||||
    List<ICraftingStep> getSteps();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Used to check if the crafting task has recursive elements
 | 
			
		||||
     * (eg. block needs 9 ingots, ingots are crafted by a block)
 | 
			
		||||
     * {@link ICraftingTask#calculate()} must be run before this
 | 
			
		||||
     * Used to check if the crafting task has recursive elements (eg. block needs 9 ingots, ingots are crafted by a block)
 | 
			
		||||
     * {@link ICraftingTask#calculate()} must be run before this!
 | 
			
		||||
     *
 | 
			
		||||
     * @return true if no recursion was found
 | 
			
		||||
     */
 | 
			
		||||
    boolean isValid();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return whether this crafting task has missing items
 | 
			
		||||
     * @return the missing items
 | 
			
		||||
     */
 | 
			
		||||
    boolean hasMissing();
 | 
			
		||||
    IItemStackList getMissing();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@link ICraftingTask#calculate()} must be run before this!
 | 
			
		||||
 
 | 
			
		||||
@@ -184,7 +184,8 @@ public interface INetworkMaster {
 | 
			
		||||
                ICraftingTask task = createCraftingTask(stack, pattern, 1);
 | 
			
		||||
 | 
			
		||||
                task.calculate();
 | 
			
		||||
                task.clearMissing();
 | 
			
		||||
                task.getMissing().clear();
 | 
			
		||||
 | 
			
		||||
                addCraftingTask(task);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ import java.util.List;
 | 
			
		||||
 * This holds all fluids from all the connected storages from a {@link INetworkMaster}.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Refined Storage uses this class mainly for use in Grids and Detectors to avoid querying
 | 
			
		||||
 * individual {@link IFluidStorage} constantly (performance impact) and to send and detect storage changes
 | 
			
		||||
 * individual {@link IFluidStorage}s constantly (performance impact) and to send and detect storage changes
 | 
			
		||||
 * more efficiently.
 | 
			
		||||
 */
 | 
			
		||||
public interface IFluidStorageCache {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ import java.util.List;
 | 
			
		||||
 * This holds all items from all the connected storages from a {@link INetworkMaster}.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Refined Storage uses this class mainly for use in Grids and Detectors to avoid querying
 | 
			
		||||
 * individual {@link IItemStorage} constantly (performance impact) and to send and detect storage changes
 | 
			
		||||
 * individual {@link IItemStorage}s constantly (performance impact) and to send and detect storage changes
 | 
			
		||||
 * more efficiently.
 | 
			
		||||
 */
 | 
			
		||||
public interface IItemStorageCache {
 | 
			
		||||
@@ -45,7 +45,7 @@ public interface IItemStorageCache {
 | 
			
		||||
    void remove(@Nonnull ItemStack stack);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return the list behind this cope
 | 
			
		||||
     * @return the list behind this cache
 | 
			
		||||
     */
 | 
			
		||||
    IItemStackList getList();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -263,7 +263,7 @@ public class CraftingTask implements ICraftingTask {
 | 
			
		||||
    public boolean update(Map<ICraftingPatternContainer, Integer> usedContainers) {
 | 
			
		||||
        IItemStackList oreDictPrepped = network.getItemStorageCache().getList().prepOreDict();
 | 
			
		||||
 | 
			
		||||
        if (hasMissing()) {
 | 
			
		||||
        if (!missing.isEmpty()) {
 | 
			
		||||
            for (ItemStack missing : this.missing.getStacks()) {
 | 
			
		||||
                if (!oreDictPrepped.trackedRemove(missing, true)) {
 | 
			
		||||
                    oreDictPrepped.undo();
 | 
			
		||||
@@ -346,11 +346,6 @@ public class CraftingTask implements ICraftingTask {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void clearMissing() {
 | 
			
		||||
        missing.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getQuantity() {
 | 
			
		||||
        return quantity;
 | 
			
		||||
@@ -521,8 +516,8 @@ public class CraftingTask implements ICraftingTask {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean hasMissing() {
 | 
			
		||||
        return !missing.isEmpty();
 | 
			
		||||
    public IItemStackList getMissing() {
 | 
			
		||||
        return missing;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -145,8 +145,10 @@ public class ItemGridHandler implements IItemGridHandler {
 | 
			
		||||
 | 
			
		||||
        if (stack != null) {
 | 
			
		||||
            ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity);
 | 
			
		||||
 | 
			
		||||
            task.calculate();
 | 
			
		||||
            task.clearMissing();
 | 
			
		||||
            task.getMissing().clear();
 | 
			
		||||
 | 
			
		||||
            network.addCraftingTask(task);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -275,8 +275,8 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
 | 
			
		||||
                            craftingTaskIterator.remove();
 | 
			
		||||
 | 
			
		||||
                            craftingTasksChanged = true;
 | 
			
		||||
                        } else if(task.hasMissing() && ticks % 100 == 0 && Math.random() > 0.5) {
 | 
			
		||||
                            task.clearMissing();
 | 
			
		||||
                        } else if (!task.getMissing().isEmpty() && ticks % 100 == 0 && Math.random() > 0.5) {
 | 
			
		||||
                            task.getMissing().clear();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user