Stabilize autocrafting
This commit is contained in:
@@ -20,8 +20,18 @@ public class ItemPattern extends ItemBase {
|
||||
@Override
|
||||
public void addInformation(ItemStack pattern, EntityPlayer player, List list, boolean b) {
|
||||
if (isValid(pattern)) {
|
||||
for (ItemStack output : getOutputs(pattern)) {
|
||||
list.add(output.getDisplayName());
|
||||
if (!isProcessing(pattern)) {
|
||||
for (ItemStack output : getOutputs(pattern)) {
|
||||
list.add(output.getDisplayName());
|
||||
}
|
||||
} else {
|
||||
for (ItemStack input : getInputs(pattern)) {
|
||||
list.add(input.getDisplayName());
|
||||
}
|
||||
|
||||
for (ItemStack output : getOutputs(pattern)) {
|
||||
list.add("-> " + output.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,11 +140,14 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
||||
craftingTasks.removeAll(craftingTasksToCancel);
|
||||
craftingTasksToCancel.clear();
|
||||
|
||||
craftingTasks.addAll(craftingTasksToAdd);
|
||||
for (ICraftingTask task : craftingTasksToAdd) {
|
||||
craftingTasks.push(task);
|
||||
}
|
||||
craftingTasksToAdd.clear();
|
||||
|
||||
if (!craftingTasks.empty()) {
|
||||
ICraftingTask top = craftingTasks.peek();
|
||||
|
||||
if (ticks % top.getPattern().getCrafter(worldObj).getSpeed() == 0 && top.update(this)) {
|
||||
top.onDone(this);
|
||||
|
||||
@@ -371,14 +374,12 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
||||
|
||||
syncItems();
|
||||
|
||||
// Notify processing tasks that we got an item
|
||||
// A processing task accepts itemstacks of 1 item, so give it like that
|
||||
for (int i = 0; i < stack.stackSize; ++i) {
|
||||
for (ICraftingTask task : craftingTasks) {
|
||||
if (task instanceof ProcessingCraftingTask) {
|
||||
if (((ProcessingCraftingTask) task).onInserted(stack)) {
|
||||
break;
|
||||
}
|
||||
if (!craftingTasks.empty()) {
|
||||
ICraftingTask top = craftingTasks.peek();
|
||||
|
||||
if (top instanceof ProcessingCraftingTask) {
|
||||
((ProcessingCraftingTask) top).onPushed(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
if (!satisfied[i]) {
|
||||
done = false;
|
||||
|
||||
ItemStack took = controller.take(input.copy());
|
||||
ItemStack took = controller.take(input);
|
||||
|
||||
if (took != null) {
|
||||
itemsTook.add(took);
|
||||
@@ -74,9 +74,9 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
controller.addCraftingTask(pattern);
|
||||
|
||||
childTasks[i] = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -15,26 +15,25 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
public static final int ID = 1;
|
||||
|
||||
public static final String NBT_INSERTED = "Inserted";
|
||||
public static final String NBT_MISSING = "Missing";
|
||||
public static final String NBT_CHILD_TASKS = "ChildTasks";
|
||||
public static final String NBT_SATISFIED = "Satisfied";
|
||||
|
||||
private CraftingPattern pattern;
|
||||
private boolean inserted[];
|
||||
// @TODO: this should create a child task when missing?
|
||||
private boolean missing[];
|
||||
private boolean childTasks[];
|
||||
private boolean satisfied[];
|
||||
|
||||
public ProcessingCraftingTask(CraftingPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
this.inserted = new boolean[pattern.getInputs().length];
|
||||
this.missing = new boolean[pattern.getInputs().length];
|
||||
this.childTasks = new boolean[pattern.getInputs().length];
|
||||
this.satisfied = new boolean[pattern.getOutputs().length];
|
||||
}
|
||||
|
||||
public ProcessingCraftingTask(NBTTagCompound tag) {
|
||||
this.pattern = CraftingPattern.readFromNBT(tag.getCompoundTag(CraftingPattern.NBT));
|
||||
this.inserted = RefinedStorageUtils.readBooleanArray(tag, NBT_INSERTED);
|
||||
this.missing = RefinedStorageUtils.readBooleanArray(tag, NBT_MISSING);
|
||||
this.childTasks = RefinedStorageUtils.readBooleanArray(tag, NBT_CHILD_TASKS);
|
||||
this.satisfied = RefinedStorageUtils.readBooleanArray(tag, NBT_SATISFIED);
|
||||
}
|
||||
|
||||
@@ -55,8 +54,6 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
ItemStack took = controller.take(input);
|
||||
|
||||
if (took != null) {
|
||||
missing[i] = false;
|
||||
|
||||
ItemStack remaining = TileEntityHopper.putStackInInventoryAllSlots((IInventory) crafterFacing, took, crafter.getDirection().getOpposite());
|
||||
|
||||
if (remaining == null) {
|
||||
@@ -64,8 +61,18 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
} else {
|
||||
controller.push(took);
|
||||
}
|
||||
} else if (!childTasks[i]) {
|
||||
CraftingPattern pattern = controller.getPattern(input);
|
||||
|
||||
if (pattern != null) {
|
||||
childTasks[i] = true;
|
||||
|
||||
controller.addCraftingTask(pattern);
|
||||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
missing[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +89,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onInserted(ItemStack inserted) {
|
||||
public boolean onPushed(ItemStack inserted) {
|
||||
for (int i = 0; i < pattern.getOutputs().length; ++i) {
|
||||
if (!satisfied[i] && RefinedStorageUtils.compareStackNoQuantity(inserted, pattern.getOutputs()[i])) {
|
||||
satisfied[i] = true;
|
||||
@@ -110,8 +117,8 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
pattern.writeToNBT(patternTag);
|
||||
tag.setTag(CraftingPattern.NBT, patternTag);
|
||||
|
||||
RefinedStorageUtils.writeBooleanArray(tag, NBT_INSERTED, satisfied);
|
||||
RefinedStorageUtils.writeBooleanArray(tag, NBT_MISSING, missing);
|
||||
RefinedStorageUtils.writeBooleanArray(tag, NBT_INSERTED, inserted);
|
||||
RefinedStorageUtils.writeBooleanArray(tag, NBT_CHILD_TASKS, childTasks);
|
||||
RefinedStorageUtils.writeBooleanArray(tag, NBT_SATISFIED, satisfied);
|
||||
|
||||
tag.setInteger("Type", ID);
|
||||
@@ -128,7 +135,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
ItemStack input = pattern.getInputs()[i];
|
||||
|
||||
if (missing[i]) {
|
||||
if (!inserted[i] && !childTasks[i]) {
|
||||
builder.append("- ").append(input.getDisplayName()).append("\n");
|
||||
|
||||
missingItems++;
|
||||
@@ -139,6 +146,24 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
builder.append(TextFormatting.GRAY).append(TextFormatting.ITALIC).append("{none}").append(TextFormatting.RESET).append("\n");
|
||||
}
|
||||
|
||||
builder.append(TextFormatting.YELLOW).append("{items_crafting}").append(TextFormatting.RESET).append("\n");
|
||||
|
||||
int itemsCrafting = 0;
|
||||
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
ItemStack input = pattern.getInputs()[i];
|
||||
|
||||
if (!inserted[i] && childTasks[i]) {
|
||||
builder.append("- ").append(input.getUnlocalizedName()).append(".name").append("\n");
|
||||
|
||||
itemsCrafting++;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemsCrafting == 0) {
|
||||
builder.append(TextFormatting.GRAY).append(TextFormatting.ITALIC).append("{none}").append(TextFormatting.RESET).append("\n");
|
||||
}
|
||||
|
||||
builder.append(TextFormatting.YELLOW).append("{items_processing}").append(TextFormatting.RESET).append("\n");
|
||||
|
||||
int itemsProcessing = 0;
|
||||
@@ -146,7 +171,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
ItemStack input = pattern.getInputs()[i];
|
||||
|
||||
if (inserted[i] && !satisfied[i]) {
|
||||
if (inserted[i]) {
|
||||
builder.append("- ").append(input.getDisplayName()).append("\n");
|
||||
|
||||
itemsProcessing++;
|
||||
|
||||
Reference in New Issue
Block a user