Fix some bugs and start working on crafting monitor elements.
This commit is contained in:
@@ -21,14 +21,6 @@ public class CraftingStepCraft implements ICraftingStep {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute() {
|
public boolean execute() {
|
||||||
for (ItemStack toExtractItem : toExtract.getStacks()) {
|
|
||||||
ItemStack inNetwork = network.extractItem(toExtractItem, toExtractItem.getCount(), true);
|
|
||||||
|
|
||||||
if (inNetwork == null || inNetwork.getCount() < toExtractItem.getCount()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ItemStack toExtractItem : toExtract.getStacks()) {
|
for (ItemStack toExtractItem : toExtract.getStacks()) {
|
||||||
ItemStack extracted = network.extractItem(toExtractItem, toExtractItem.getCount(), false);
|
ItemStack extracted = network.extractItem(toExtractItem, toExtractItem.getCount(), false);
|
||||||
|
|
||||||
@@ -48,6 +40,23 @@ public class CraftingStepCraft implements ICraftingStep {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canExecute() {
|
||||||
|
for (ItemStack toExtractItem : toExtract.getStacks()) {
|
||||||
|
ItemStack inNetwork = network.extractItem(toExtractItem, toExtractItem.getCount(), true);
|
||||||
|
|
||||||
|
if (inNetwork == null || inNetwork.getCount() < toExtractItem.getCount()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IStackList<ItemStack> getToExtract() {
|
||||||
|
return toExtract;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICraftingPattern getPattern() {
|
public ICraftingPattern getPattern() {
|
||||||
return pattern;
|
return pattern;
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
|
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
|
||||||
|
|
||||||
public class CraftingStepSlot {
|
class CraftingStepWrapper {
|
||||||
private ICraftingStep step;
|
private ICraftingStep step;
|
||||||
private boolean fulfilled;
|
private boolean completed;
|
||||||
private int ticks = -1;
|
private int ticks = -1;
|
||||||
|
|
||||||
public CraftingStepSlot(ICraftingStep step) {
|
CraftingStepWrapper(ICraftingStep step) {
|
||||||
this.step = step;
|
this.step = step;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canExecute() {
|
boolean canExecute() {
|
||||||
|
if (!step.canExecute()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ticks++;
|
ticks++;
|
||||||
|
|
||||||
switch (step.getPattern().getContainer().getSpeedUpdateCount()) {
|
switch (step.getPattern().getContainer().getSpeedUpdateCount()) {
|
||||||
@@ -27,15 +31,15 @@ public class CraftingStepSlot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICraftingStep getStep() {
|
ICraftingStep getStep() {
|
||||||
return step;
|
return step;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFulfilled() {
|
boolean isCompleted() {
|
||||||
return fulfilled;
|
return completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFulfilled() {
|
void setCompleted() {
|
||||||
this.fulfilled = true;
|
this.completed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,10 @@ import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
|||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementError;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementInfo;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -22,7 +25,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
private ItemStack requested;
|
private ItemStack requested;
|
||||||
private int quantity;
|
private int quantity;
|
||||||
private ICraftingPattern pattern;
|
private ICraftingPattern pattern;
|
||||||
private List<CraftingStepSlot> steps = new LinkedList<>();
|
private List<CraftingStepWrapper> steps = new LinkedList<>();
|
||||||
|
|
||||||
private IStackList<ItemStack> toTake = API.instance().createItemStackList();
|
private IStackList<ItemStack> toTake = API.instance().createItemStackList();
|
||||||
private IStackList<ItemStack> missing = API.instance().createItemStackList();
|
private IStackList<ItemStack> missing = API.instance().createItemStackList();
|
||||||
@@ -43,7 +46,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
IStackList<ItemStack> storage = network.getItemStorageCache().getList().copy();
|
IStackList<ItemStack> storage = network.getItemStorageCache().getList().copy();
|
||||||
|
|
||||||
while (qty > 0) {
|
while (qty > 0) {
|
||||||
this.steps.add(new CraftingStepSlot(calculateInternal(storage, results, pattern)));
|
this.steps.add(new CraftingStepWrapper(calculateInternal(storage, results, pattern)));
|
||||||
|
|
||||||
qty -= getQuantityPerCraft(pattern, requested);
|
qty -= getQuantityPerCraft(pattern, requested);
|
||||||
}
|
}
|
||||||
@@ -69,9 +72,11 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
ItemStack fromSelf = results.get(possibleInput);
|
ItemStack fromSelf = results.get(possibleInput);
|
||||||
if (fromSelf != null) {
|
if (fromSelf != null) {
|
||||||
results.remove(fromSelf, Math.min(possibleInput.getCount(), fromSelf.getCount()));
|
int toExtractFromSelf = fromSelf.getCount();
|
||||||
|
|
||||||
toExtract -= fromSelf.getCount();
|
results.remove(fromSelf, Math.min(possibleInput.getCount(), toExtractFromSelf));
|
||||||
|
|
||||||
|
toExtract -= toExtractFromSelf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toExtract > 0) {
|
if (toExtract > 0) {
|
||||||
@@ -98,7 +103,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
this.toCraft.add(possibleInput, missing);
|
this.toCraft.add(possibleInput, missing);
|
||||||
|
|
||||||
while (missing > 0) {
|
while (missing > 0) {
|
||||||
this.steps.add(new CraftingStepSlot(calculateInternal(mutatedStorage, results, subPattern)));
|
this.steps.add(new CraftingStepWrapper(calculateInternal(mutatedStorage, results, subPattern)));
|
||||||
|
|
||||||
missing -= getQuantityPerCraft(subPattern, possibleInput);
|
missing -= getQuantityPerCraft(subPattern, possibleInput);
|
||||||
}
|
}
|
||||||
@@ -144,19 +149,21 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update() {
|
public boolean update() {
|
||||||
boolean allFulfilled = true;
|
boolean allCompleted = true;
|
||||||
|
|
||||||
for (CraftingStepSlot slot : steps) {
|
for (CraftingStepWrapper step : steps) {
|
||||||
if (!slot.isFulfilled()) {
|
if (!step.isCompleted()) {
|
||||||
allFulfilled = false;
|
allCompleted = false;
|
||||||
|
|
||||||
if (slot.canExecute() && slot.getStep().execute()) {
|
if (step.canExecute() && step.getStep().execute()) {
|
||||||
slot.setFulfilled();
|
step.setCompleted();
|
||||||
|
|
||||||
|
network.getCraftingManager().sendCraftingMonitorUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return allFulfilled;
|
return allCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -181,11 +188,53 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ICraftingMonitorElement> getCraftingMonitorElements() {
|
public List<ICraftingMonitorElement> getCraftingMonitorElements() {
|
||||||
// TODO
|
|
||||||
|
|
||||||
ICraftingMonitorElementList elements = API.instance().createCraftingMonitorElementList();
|
ICraftingMonitorElementList elements = API.instance().createCraftingMonitorElementList();
|
||||||
|
|
||||||
elements.directAdd(new CraftingMonitorElementItemRender(network.getCraftingManager().getTasks().indexOf(this), requested, quantity, 0));
|
elements.directAdd(new CraftingMonitorElementItemRender(
|
||||||
|
network.getCraftingManager().getTasks().indexOf(this),
|
||||||
|
requested != null ? requested : pattern.getOutputs().get(0),
|
||||||
|
quantity,
|
||||||
|
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.getCount(),
|
||||||
|
32
|
||||||
|
), "")).forEach(elements::add);
|
||||||
|
|
||||||
|
elements.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (steps.stream().anyMatch(s -> s.getStep() instanceof CraftingStepCraft && !s.isCompleted())) {
|
||||||
|
elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_crafting", 16));
|
||||||
|
|
||||||
|
for (CraftingStepWrapper step : steps) {
|
||||||
|
if (step.getStep() instanceof CraftingStepCraft && !step.isCompleted()) {
|
||||||
|
for (ItemStack stack : ((CraftingStepCraft) step.getStep()).getToExtract().getStacks()) {
|
||||||
|
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(
|
||||||
|
-1,
|
||||||
|
stack,
|
||||||
|
stack.getCount(),
|
||||||
|
32
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: cache this
|
||||||
|
if (!step.getStep().canExecute()) {
|
||||||
|
element = new CraftingMonitorElementInfo(element, "gui.refinedstorage:crafting_monitor.waiting_for_items");
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.add(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.commit();
|
||||||
|
}
|
||||||
|
|
||||||
return elements.getElements();
|
return elements.getElements();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
|||||||
public interface ICraftingStep {
|
public interface ICraftingStep {
|
||||||
boolean execute();
|
boolean execute();
|
||||||
|
|
||||||
|
boolean canExecute();
|
||||||
|
|
||||||
ICraftingPattern getPattern();
|
ICraftingPattern getPattern();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user