reserve items used by CraftingTask to prevent using them more than on… (#2557)
* reserve items used by CraftingTask to prevent using them more than once fixes #2155 * Revert "reserve items used by CraftingTask to prevent using them more than once fixes #2155" This reverts commit c0fea5d1 * extractInitial when first adding a CraftingTask * fix formatting * some cleanup * make extractInitial private again check for missing before starting task
This commit is contained in:
@@ -36,11 +36,11 @@ public interface ICraftingManager {
|
||||
Map<ITextComponent, List<IItemHandlerModifiable>> getNamedContainers();
|
||||
|
||||
/**
|
||||
* Adds a crafting task.
|
||||
* Starts a crafting task.
|
||||
*
|
||||
* @param task the task to add
|
||||
* @param task the task to start
|
||||
*/
|
||||
void add(@Nonnull ICraftingTask task);
|
||||
void start(@Nonnull ICraftingTask task);
|
||||
|
||||
/**
|
||||
* Cancels a crafting task.
|
||||
|
@@ -125,4 +125,9 @@ public interface ICraftingTask {
|
||||
* @return the state of this crafting task
|
||||
*/
|
||||
CraftingTaskState getState();
|
||||
|
||||
/**
|
||||
* Start the CraftingTask
|
||||
*/
|
||||
void start();
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import com.refinedmods.refinedstorage.api.network.INetwork;
|
||||
import com.refinedmods.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.refinedmods.refinedstorage.api.util.IComparer;
|
||||
import com.refinedmods.refinedstorage.apiimpl.API;
|
||||
import com.refinedmods.refinedstorage.apiimpl.autocrafting.task.v6.CraftingTask;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
@@ -74,7 +75,8 @@ public class CraftingManager implements ICraftingManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(@Nonnull ICraftingTask task) {
|
||||
public void start(@Nonnull ICraftingTask task) {
|
||||
task.start();
|
||||
tasksToAdd.add(task);
|
||||
|
||||
network.markDirty();
|
||||
@@ -253,7 +255,7 @@ public class CraftingManager implements ICraftingManager {
|
||||
ICraftingTaskError error = task.calculate();
|
||||
|
||||
if (error == null && !task.hasMissing()) {
|
||||
this.add(task);
|
||||
this.start(task);
|
||||
|
||||
return task;
|
||||
} else {
|
||||
@@ -289,7 +291,7 @@ public class CraftingManager implements ICraftingManager {
|
||||
ICraftingTaskError error = task.calculate();
|
||||
|
||||
if (error == null && !task.hasMissing()) {
|
||||
this.add(task);
|
||||
this.start(task);
|
||||
|
||||
return task;
|
||||
} else {
|
||||
|
@@ -138,4 +138,8 @@ public abstract class Craft {
|
||||
return tag;
|
||||
}
|
||||
|
||||
void finishCalculation() {
|
||||
//NOOP
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -264,16 +264,6 @@ public class CraftingTask implements ICraftingTask {
|
||||
this.toCraftFluids.add(req);
|
||||
}
|
||||
|
||||
if (missing.isEmpty()) {
|
||||
crafts.values().forEach(c -> {
|
||||
totalSteps += c.getQuantity();
|
||||
|
||||
if (c instanceof Processing) {
|
||||
((Processing) c).finishCalculation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.state = CraftingTaskState.CALCULATED;
|
||||
|
||||
return null;
|
||||
@@ -596,6 +586,24 @@ public class CraftingTask implements ICraftingTask {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (hasMissing()) {
|
||||
LOGGER.warn("Crafting task with missing items or fluids cannot execute, cancelling...");
|
||||
return;
|
||||
}
|
||||
|
||||
crafts.values().forEach(craft -> {
|
||||
totalSteps += craft.getQuantity();
|
||||
craft.finishCalculation();
|
||||
});
|
||||
|
||||
executionStarted = System.currentTimeMillis();
|
||||
|
||||
extractInitial();
|
||||
}
|
||||
|
||||
|
||||
private void extractInitial() {
|
||||
if (!toExtractInitial.isEmpty()) {
|
||||
List<ItemStack> toRemove = new ArrayList<>();
|
||||
@@ -930,10 +938,6 @@ public class CraftingTask implements ICraftingTask {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (executionStarted == -1) {
|
||||
executionStarted = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
++ticks;
|
||||
|
||||
if (this.crafts.isEmpty()) {
|
||||
|
@@ -48,6 +48,7 @@ class Processing extends Craft {
|
||||
this.itemsToDisplay = CraftingTask.readItemStackList(tag.getList(NBT_ITEMS_TO_DISPLAY, Constants.NBT.TAG_COMPOUND));
|
||||
}
|
||||
|
||||
@Override
|
||||
void finishCalculation() {
|
||||
this.totalQuantity = quantity;
|
||||
updateItemsToDisplay();
|
||||
|
@@ -122,7 +122,7 @@ public class FluidGridHandler implements IFluidGridHandler {
|
||||
)
|
||||
);
|
||||
} else if (noPreview && !task.hasMissing()) {
|
||||
network.getCraftingManager().add(task);
|
||||
network.getCraftingManager().start(task);
|
||||
|
||||
RS.NETWORK_HANDLER.sendTo(player, new GridCraftingStartResponseMessage());
|
||||
} else {
|
||||
@@ -159,7 +159,7 @@ public class FluidGridHandler implements IFluidGridHandler {
|
||||
|
||||
ICraftingTaskError error = task.calculate();
|
||||
if (error == null && !task.hasMissing()) {
|
||||
network.getCraftingManager().add(task);
|
||||
network.getCraftingManager().start(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -180,7 +180,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
)
|
||||
);
|
||||
} else if (noPreview && !task.hasMissing()) {
|
||||
network.getCraftingManager().add(task);
|
||||
network.getCraftingManager().start(task);
|
||||
|
||||
RS.NETWORK_HANDLER.sendTo(player, new GridCraftingStartResponseMessage());
|
||||
} else {
|
||||
@@ -217,7 +217,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
|
||||
ICraftingTaskError error = task.calculate();
|
||||
if (error == null && !task.hasMissing()) {
|
||||
network.getCraftingManager().add(task);
|
||||
network.getCraftingManager().start(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user