@@ -66,11 +66,17 @@ public interface ICraftingStep {
 | 
			
		||||
    boolean hasReceivedOutputs();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param stack the output to check,
 | 
			
		||||
     * @param stack the output to check
 | 
			
		||||
     * @return true if we received the given output (based upon item and stacksize), false otherwise
 | 
			
		||||
     */
 | 
			
		||||
    boolean hasReceivedOutput(ItemStack stack);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param stack the output to check
 | 
			
		||||
     * @return amount of times this {@link ItemStack} has been received
 | 
			
		||||
     */
 | 
			
		||||
    int getReceivedOutput(ItemStack stack);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The {@link ItemStack} given to it will be changed and contain the remainder
 | 
			
		||||
     * The return value will only be true if the stack size is zero
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,16 @@ public interface ICraftingTask {
 | 
			
		||||
     */
 | 
			
		||||
    boolean update(Map<ICraftingPatternContainer, Integer> usedContainers);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Reschedule the task. This does a recalculation and restart of the task.
 | 
			
		||||
     */
 | 
			
		||||
    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
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -184,10 +184,8 @@ public interface INetworkMaster {
 | 
			
		||||
                ICraftingTask task = createCraftingTask(stack, pattern, 1);
 | 
			
		||||
 | 
			
		||||
                task.calculate();
 | 
			
		||||
 | 
			
		||||
                if (!task.hasMissing()) {
 | 
			
		||||
                    addCraftingTask(task);
 | 
			
		||||
                }
 | 
			
		||||
                task.clearMissing();
 | 
			
		||||
                addCraftingTask(task);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -112,6 +112,12 @@ public abstract class CraftingStep implements ICraftingStep {
 | 
			
		||||
        return received != null && received >= stack.stackSize;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getReceivedOutput(ItemStack stack) {
 | 
			
		||||
        Integer received = satisfied.get(API.instance().getItemStackHashCode(stack));
 | 
			
		||||
        return received == null ? 0 : received;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onReceiveOutput(ItemStack stack) {
 | 
			
		||||
        for (ItemStack output : pattern.getOutputs()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -240,6 +240,21 @@ public class CraftingTask implements ICraftingTask {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean update(Map<ICraftingPatternContainer, Integer> usedContainers) {
 | 
			
		||||
        IItemStackList oreDictPrepped = network.getItemStorageCache().getList().prepOreDict();
 | 
			
		||||
 | 
			
		||||
        if (hasMissing()) {
 | 
			
		||||
            for (ItemStack missing : this.missing.getStacks()) {
 | 
			
		||||
                if (!oreDictPrepped.trackedRemove(missing, true)) {
 | 
			
		||||
                    oreDictPrepped.undo();
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            oreDictPrepped.undo();
 | 
			
		||||
            reschedule();
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        for (FluidStack stack : toTakeFluids.getStacks()) {
 | 
			
		||||
            FluidStack stackExtracted = network.extractFluid(stack, stack.amount);
 | 
			
		||||
            if (stackExtracted != null) {
 | 
			
		||||
@@ -251,8 +266,6 @@ public class CraftingTask implements ICraftingTask {
 | 
			
		||||
 | 
			
		||||
        toTakeFluids.clean();
 | 
			
		||||
 | 
			
		||||
        IItemStackList oreDictPrepped = network.getItemStorageCache().getList().prepOreDict();
 | 
			
		||||
 | 
			
		||||
        for (ICraftingStep step : steps) {
 | 
			
		||||
            ICraftingPatternContainer container = step.getPattern().getContainer();
 | 
			
		||||
            Integer timesUsed = usedContainers.get(container);
 | 
			
		||||
@@ -284,11 +297,39 @@ public class CraftingTask implements ICraftingTask {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (steps.stream().filter(ICraftingStep::hasStartedProcessing).count() == 0) {
 | 
			
		||||
            // When there is no started processes, restart the task.
 | 
			
		||||
            reschedule();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Remove finished tasks
 | 
			
		||||
        steps.removeIf(ICraftingStep::hasReceivedOutputs);
 | 
			
		||||
 | 
			
		||||
        return isFinished();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void reschedule() {
 | 
			
		||||
        List<ICraftingStep> mainSteps = steps.stream().filter(s -> s.getPattern() == pattern).collect(Collectors.toList());
 | 
			
		||||
        missing.clear();
 | 
			
		||||
        steps.clear();
 | 
			
		||||
        // if the list of main steps is empty there is no point in rescheduling
 | 
			
		||||
        if (!mainSteps.isEmpty()) {
 | 
			
		||||
            quantity = 0;
 | 
			
		||||
            int quantityPerRequest = pattern.getQuantityPerRequest(requested);
 | 
			
		||||
            for (ICraftingStep step : mainSteps) {
 | 
			
		||||
                quantity += quantityPerRequest - step.getReceivedOutput(requested);
 | 
			
		||||
            }
 | 
			
		||||
            calculate();
 | 
			
		||||
            network.sendCraftingMonitorUpdate();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void clearMissing() {
 | 
			
		||||
        missing.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getQuantity() {
 | 
			
		||||
        return quantity;
 | 
			
		||||
@@ -346,6 +387,21 @@ public class CraftingTask implements ICraftingTask {
 | 
			
		||||
            0
 | 
			
		||||
        ));
 | 
			
		||||
 | 
			
		||||
        if (!missing.isEmpty()) {
 | 
			
		||||
            elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_missing", 16));
 | 
			
		||||
 | 
			
		||||
            missing.getStacks().stream()
 | 
			
		||||
                .map(stack -> new CraftingMonitorElementError(new CraftingMonitorElementItemRender(
 | 
			
		||||
                    -1,
 | 
			
		||||
                    stack,
 | 
			
		||||
                    stack.stackSize,
 | 
			
		||||
                    32
 | 
			
		||||
                ), ""))
 | 
			
		||||
                .forEach(elements::add);
 | 
			
		||||
 | 
			
		||||
            elements.commit();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!toInsertItems.isEmpty()) {
 | 
			
		||||
            elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_inserting", 16));
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -145,12 +145,9 @@ public class ItemGridHandler implements IItemGridHandler {
 | 
			
		||||
 | 
			
		||||
        if (stack != null) {
 | 
			
		||||
            ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity);
 | 
			
		||||
 | 
			
		||||
            task.calculate();
 | 
			
		||||
 | 
			
		||||
            if (!task.hasMissing()) {
 | 
			
		||||
                network.addCraftingTask(task);
 | 
			
		||||
            }
 | 
			
		||||
            task.clearMissing();
 | 
			
		||||
            network.addCraftingTask(task);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -132,7 +132,7 @@ public class GuiCraftingMonitor extends GuiBase {
 | 
			
		||||
            item++;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (itemSelectedTooltip != null) {
 | 
			
		||||
        if (itemSelectedTooltip != null && !itemSelectedTooltip.isEmpty()) {
 | 
			
		||||
            drawTooltip(mouseX, mouseY, I18n.format(itemSelectedTooltip));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -78,6 +78,10 @@ public class GuiCraftingPreview extends GuiBase {
 | 
			
		||||
    public void update(int x, int y) {
 | 
			
		||||
        scrollbar.setEnabled(getRows() > VISIBLE_ROWS);
 | 
			
		||||
        scrollbar.setMaxOffset(getRows() - VISIBLE_ROWS);
 | 
			
		||||
 | 
			
		||||
        if (!startButton.enabled && isCtrlKeyDown() && isShiftKeyDown()) {
 | 
			
		||||
            startButton.enabled = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -146,6 +150,10 @@ public class GuiCraftingPreview extends GuiBase {
 | 
			
		||||
            } else if (hoveringFluid != null) {
 | 
			
		||||
                drawTooltip(mouseX, mouseY, hoveringFluid.getLocalizedName());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!startButton.enabled && inBounds(85, 144, 50, 20, mouseX, mouseY)) {
 | 
			
		||||
                drawTooltip(mouseX, mouseY, t("gui.refinedstorage:crafting_preview.force_start"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.LinkedHashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
public class RecipeTransferHandlerPattern implements IRecipeTransferHandler<ContainerProcessingPatternEncoder> {
 | 
			
		||||
@@ -30,8 +31,8 @@ public class RecipeTransferHandlerPattern implements IRecipeTransferHandler<Cont
 | 
			
		||||
    @Override
 | 
			
		||||
    public IRecipeTransferError transferRecipe(ContainerProcessingPatternEncoder container, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
 | 
			
		||||
        if (doTransfer) {
 | 
			
		||||
            Map<Integer, ItemStack> inputs = new HashMap<>();
 | 
			
		||||
            Map<Integer, ItemStack> outputs = new HashMap<>();
 | 
			
		||||
            Map<Integer, ItemStack> inputs = new LinkedHashMap<>();
 | 
			
		||||
            Map<Integer, ItemStack> outputs = new LinkedHashMap<>();
 | 
			
		||||
 | 
			
		||||
            for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
 | 
			
		||||
                if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
 | 
			
		||||
 
 | 
			
		||||
@@ -275,6 +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();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user