fixes some issues with IProcessable and machines

This commit is contained in:
way2muchnoise
2016-10-19 17:56:31 +02:00
parent 81c099f63c
commit a4b859764a
3 changed files with 42 additions and 42 deletions

View File

@@ -3,6 +3,7 @@ package refinedstorage.api.autocrafting.task;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import refinedstorage.api.autocrafting.ICraftingPattern; import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.util.IItemStackList;
import java.util.Deque; import java.util.Deque;
@@ -18,7 +19,15 @@ public interface IProcessable {
/** /**
* @return the stacks to insert * @return the stacks to insert
*/ */
Deque<ItemStack> getToInsert(); IItemStackList getToInsert();
/**
* Check if the processing can start
*
* @param list a list to compare the need inputs against
* @return true if processing can start
*/
boolean canStartProcessing(IItemStackList list);
void setStartedProcessing(); void setStartedProcessing();

View File

@@ -236,33 +236,33 @@ public class CraftingTask implements ICraftingTask {
for (IProcessable processable : toProcess) { for (IProcessable processable : toProcess) {
IItemHandler inventory = processable.getPattern().getContainer().getFacingInventory(); IItemHandler inventory = processable.getPattern().getContainer().getFacingInventory();
if (inventory != null && !processable.getToInsert().isEmpty() && canProcess(processable)) { if (!processable.isStartedProcessing() && inventory != null && processable.canStartProcessing(network.getItemStorageCache().getList()) && canProcess(processable)) {
processable.setStartedProcessing(); processable.setStartedProcessing();
ItemStack toInsert = network.extractItem(processable.getToInsert().peek(), 1, DEFAULT_COMPARE | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0)); for (ItemStack insertStack : processable.getToInsert().getStacks()) {
ItemStack toInsert = network.extractItem(insertStack, insertStack.stackSize, DEFAULT_COMPARE | (processable.getPattern().isOredict() ? IComparer.COMPARE_OREDICT : 0));
if (ItemHandlerHelper.insertItem(inventory, toInsert, true) == null) { if (ItemHandlerHelper.insertItem(inventory, toInsert, true) == null) {
ItemHandlerHelper.insertItem(inventory, toInsert, false); ItemHandlerHelper.insertItem(inventory, toInsert, false);
processable.getToInsert().pop(); network.sendCraftingMonitorUpdate();
}
network.sendCraftingMonitorUpdate();
} }
} }
} }
for (ItemStack stack : toTake.getStacks()) { for (ItemStack stack : toTake.getStacks()) {
ItemStack stackExtracted = network.extractItem(stack, 1); ItemStack stackExtracted = network.extractItem(stack, Math.min(stack.stackSize, 64));
if (stackExtracted != null) { if (stackExtracted != null) {
toTake.remove(stack, 1, true); toTake.remove(stack, stackExtracted.stackSize, true);
took.add(stackExtracted); took.add(stackExtracted);
network.sendCraftingMonitorUpdate(); network.sendCraftingMonitorUpdate();
}
break; break;
}
} }
// If we took all the items, we can start taking fluids // If we took all the items, we can start taking fluids
@@ -276,9 +276,9 @@ public class CraftingTask implements ICraftingTask {
tookFluids.add(stackExtracted); tookFluids.add(stackExtracted);
network.sendCraftingMonitorUpdate(); network.sendCraftingMonitorUpdate();
}
break; break;
}
} }
} }

View File

@@ -2,23 +2,20 @@ package refinedstorage.apiimpl.autocrafting.task;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
import refinedstorage.RSUtils;
import refinedstorage.api.autocrafting.ICraftingPattern; import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.task.IProcessable; import refinedstorage.api.autocrafting.task.IProcessable;
import refinedstorage.api.util.IComparer;
import refinedstorage.api.util.IItemStackList;
import refinedstorage.apiimpl.API; import refinedstorage.apiimpl.API;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
public class Processable implements IProcessable { public class Processable implements IProcessable {
private static final String NBT_SATISFIED = "Satisfied_%d"; private static final String NBT_SATISFIED = "Satisfied_%d";
private static final String NBT_TO_INSERT = "ToInsert"; private static final String NBT_TO_INSERT = "ToInsert";
private ICraftingPattern pattern; private ICraftingPattern pattern;
private Deque<ItemStack> toInsert = new ArrayDeque<>(); private IItemStackList toInsert = API.instance().createItemStackList();
private boolean satisfied[]; private boolean satisfied[];
private boolean startedProcessing; private boolean startedProcessing;
@@ -45,19 +42,7 @@ public class Processable implements IProcessable {
} }
} }
NBTTagList toInsertList = tag.getTagList(NBT_TO_INSERT, Constants.NBT.TAG_COMPOUND); this.toInsert = RSUtils.readItemStackList(tag.getTagList(NBT_TO_INSERT, Constants.NBT.TAG_COMPOUND));
List<ItemStack> toInsert = new ArrayList<>();
for (int i = 0; i < toInsertList.tagCount(); ++i) {
ItemStack stack = ItemStack.loadItemStackFromNBT(toInsertList.getCompoundTagAt(i));
if (stack != null) {
toInsert.add(stack);
}
}
this.toInsert = new ArrayDeque<>(toInsert);
} }
@Override @Override
@@ -66,10 +51,22 @@ public class Processable implements IProcessable {
} }
@Override @Override
public Deque<ItemStack> getToInsert() { public IItemStackList getToInsert() {
return toInsert; return toInsert;
} }
@Override
public boolean canStartProcessing(IItemStackList list) {
list = list.copy(); // So we can edit the list
for (ItemStack stack : toInsert.getStacks()) {
ItemStack actualStack = list.get(stack, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0));
if (actualStack == null || actualStack.stackSize == 0 || !list.remove(actualStack, true)) {
return false;
}
}
return true;
}
@Override @Override
public void setStartedProcessing() { public void setStartedProcessing() {
startedProcessing = true; startedProcessing = true;
@@ -119,13 +116,7 @@ public class Processable implements IProcessable {
tag.setBoolean(String.format(NBT_SATISFIED, i), satisfied[i]); tag.setBoolean(String.format(NBT_SATISFIED, i), satisfied[i]);
} }
NBTTagList toInsertList = new NBTTagList(); tag.setTag(NBT_TO_INSERT, RSUtils.serializeItemStackList(toInsert));
for (ItemStack stack : new ArrayList<>(toInsert)) {
toInsertList.appendTag(stack.serializeNBT());
}
tag.setTag(NBT_TO_INSERT, toInsertList);
return tag; return tag;
} }