Fixes
This commit is contained in:
		@@ -5,8 +5,6 @@ import net.minecraft.world.World;
 | 
			
		||||
import refinedstorage.api.autocrafting.ICraftingPattern;
 | 
			
		||||
import refinedstorage.api.network.INetworkMaster;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a crafting task.
 | 
			
		||||
 */
 | 
			
		||||
@@ -17,9 +15,14 @@ public interface ICraftingTask {
 | 
			
		||||
    ICraftingPattern getPattern();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return The child tasks
 | 
			
		||||
     * @return The child task
 | 
			
		||||
     */
 | 
			
		||||
    List<ICraftingTask> getChildren();
 | 
			
		||||
    ICraftingTask getChild();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param child The child task
 | 
			
		||||
     */
 | 
			
		||||
    void setChild(ICraftingTask child);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param world   The world
 | 
			
		||||
 
 | 
			
		||||
@@ -1,33 +1,24 @@
 | 
			
		||||
package refinedstorage.apiimpl.autocrafting.task;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
 | 
			
		||||
import refinedstorage.api.network.INetworkMaster;
 | 
			
		||||
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public abstract class CraftingTask implements ICraftingTask {
 | 
			
		||||
    protected List<ICraftingTask> children;
 | 
			
		||||
    protected ICraftingTask child;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<ICraftingTask> getChildren() {
 | 
			
		||||
        return children;
 | 
			
		||||
    public ICraftingTask getChild() {
 | 
			
		||||
        return child;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updateChildren(World world, INetworkMaster network) {
 | 
			
		||||
        Iterator<ICraftingTask> childrenIterator = children.iterator();
 | 
			
		||||
 | 
			
		||||
        while (childrenIterator.hasNext()) {
 | 
			
		||||
            if (childrenIterator.next().update(world, network)) {
 | 
			
		||||
                childrenIterator.remove();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setChild(ICraftingTask child) {
 | 
			
		||||
        this.child = child;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onCancelled(INetworkMaster network) {
 | 
			
		||||
        for (ICraftingTask child : children) {
 | 
			
		||||
        if (child != null) {
 | 
			
		||||
            child.onCancelled(network);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -47,8 +47,6 @@ public class CraftingTaskNormal extends CraftingTask {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean update(World world, INetworkMaster network) {
 | 
			
		||||
        updateChildren(world, network);
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < pattern.getInputs().length; ++i) {
 | 
			
		||||
            ItemStack input = pattern.getInputs()[i];
 | 
			
		||||
 | 
			
		||||
@@ -63,9 +61,11 @@ public class CraftingTaskNormal extends CraftingTask {
 | 
			
		||||
                    ICraftingPattern pattern = NetworkUtils.getPattern(network, input);
 | 
			
		||||
 | 
			
		||||
                    if (pattern != null) {
 | 
			
		||||
                        children.add(network.createCraftingTask(pattern));
 | 
			
		||||
                        child = network.createCraftingTask(pattern);
 | 
			
		||||
 | 
			
		||||
                        childrenCreated[i] = true;
 | 
			
		||||
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -77,21 +77,19 @@ public class CraftingTaskNormal extends CraftingTask {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (children.isEmpty()) {
 | 
			
		||||
            for (ItemStack output : pattern.getOutputs()) {
 | 
			
		||||
                // @TODO: Handle remainder
 | 
			
		||||
                network.insertItem(output, output.stackSize, false);
 | 
			
		||||
            }
 | 
			
		||||
        for (ItemStack output : pattern.getOutputs()) {
 | 
			
		||||
            // @TODO: Handle remainder
 | 
			
		||||
            network.insertItem(output, output.stackSize, false);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (pattern.getByproducts() != null) {
 | 
			
		||||
            for (ItemStack byproduct : pattern.getByproducts()) {
 | 
			
		||||
                // @TODO: Handle remainder
 | 
			
		||||
                network.insertItem(byproduct, byproduct.stackSize, false);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -251,4 +251,4 @@ public abstract class ItemStorageNBT implements IItemStorage {
 | 
			
		||||
 | 
			
		||||
        return stack;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
@@ -261,16 +261,18 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
 | 
			
		||||
                Iterator<ICraftingTask> craftingTaskIterator = craftingTasks.iterator();
 | 
			
		||||
 | 
			
		||||
                while (craftingTaskIterator.hasNext()) {
 | 
			
		||||
                    craftingTasksChanged = true;
 | 
			
		||||
 | 
			
		||||
                    ICraftingTask task = craftingTaskIterator.next();
 | 
			
		||||
 | 
			
		||||
                    markDirty();
 | 
			
		||||
 | 
			
		||||
                    ICraftingPatternContainer container = task.getPattern().getContainer(worldObj);
 | 
			
		||||
 | 
			
		||||
                    if (container != null && ticks % container.getSpeed() == 0 && task.update(worldObj, this)) {
 | 
			
		||||
                        craftingTaskIterator.remove();
 | 
			
		||||
 | 
			
		||||
                        craftingTasksChanged = true;
 | 
			
		||||
                    if (task.getChild() != null) {
 | 
			
		||||
                        if (updateCraftingTask(task.getChild())) {
 | 
			
		||||
                            task.setChild(null);
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        if (updateCraftingTask(task)) {
 | 
			
		||||
                            craftingTaskIterator.remove();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@@ -315,7 +317,15 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
 | 
			
		||||
        super.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean updateCraftingTask(ICraftingTask task) {
 | 
			
		||||
        ICraftingPatternContainer container = task.getPattern().getContainer(worldObj);
 | 
			
		||||
 | 
			
		||||
        return container != null && ticks % container.getSpeed() == 0 && task.update(worldObj, this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void updateCraftingTasks() {
 | 
			
		||||
        markDirty();
 | 
			
		||||
 | 
			
		||||
        for (INetworkNode node : nodeGraph.all()) {
 | 
			
		||||
            if (node instanceof TileCraftingMonitor) {
 | 
			
		||||
                ((TileCraftingMonitor) node).dataManager.sendParameterToWatchers(TileCraftingMonitor.TASKS);
 | 
			
		||||
@@ -541,22 +551,22 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
        @TODO: Processing crafting tasks
 | 
			
		||||
 | 
			
		||||
        // @TODO: Processing crafting tasks
 | 
			
		||||
 | 
			
		||||
        int inserted = remainder != null ? (orginalSize - remainder.stackSize) : orginalSize;
 | 
			
		||||
 | 
			
		||||
        if (!simulate && inserted > 0) {
 | 
			
		||||
            for (int i = 0; i < inserted; ++i) {
 | 
			
		||||
            /*for (int i = 0; i < inserted; ++i) {
 | 
			
		||||
                if (!craftingTasks.empty() && craftingTasks.peek() instanceof ProcessingCraftingTask) {
 | 
			
		||||
                    if (((ProcessingCraftingTask) craftingTasks.peek()).onInserted(stack)) {
 | 
			
		||||
                        updateTopCraftingTask(false);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            }*/
 | 
			
		||||
 | 
			
		||||
            itemStorage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted), false);
 | 
			
		||||
        }*/
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return remainder;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user