Expose CraftingTask#missing
This commit is contained in:
@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
|||||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||||
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||||
import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.IItemStackList;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
@@ -45,11 +46,6 @@ public interface ICraftingTask {
|
|||||||
*/
|
*/
|
||||||
void reschedule();
|
void reschedule();
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear out missing items. Tasks will run all possible tasks, before reporting missing items again.
|
|
||||||
*/
|
|
||||||
void clearMissing();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the amount of items that have to be crafted
|
* @return the amount of items that have to be crafted
|
||||||
*/
|
*/
|
||||||
@@ -108,18 +104,17 @@ public interface ICraftingTask {
|
|||||||
List<ICraftingStep> getSteps();
|
List<ICraftingStep> getSteps();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to check if the crafting task has recursive elements
|
* Used to check if the crafting task has recursive elements (eg. block needs 9 ingots, ingots are crafted by a block)
|
||||||
* (eg. block needs 9 ingots, ingots are crafted by a block)
|
* {@link ICraftingTask#calculate()} must be run before this!
|
||||||
* {@link ICraftingTask#calculate()} must be run before this
|
|
||||||
*
|
*
|
||||||
* @return true if no recursion was found
|
* @return true if no recursion was found
|
||||||
*/
|
*/
|
||||||
boolean isValid();
|
boolean isValid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return whether this crafting task has missing items
|
* @return the missing items
|
||||||
*/
|
*/
|
||||||
boolean hasMissing();
|
IItemStackList getMissing();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ICraftingTask#calculate()} must be run before this!
|
* {@link ICraftingTask#calculate()} must be run before this!
|
||||||
|
|||||||
@@ -184,7 +184,8 @@ public interface INetworkMaster {
|
|||||||
ICraftingTask task = createCraftingTask(stack, pattern, 1);
|
ICraftingTask task = createCraftingTask(stack, pattern, 1);
|
||||||
|
|
||||||
task.calculate();
|
task.calculate();
|
||||||
task.clearMissing();
|
task.getMissing().clear();
|
||||||
|
|
||||||
addCraftingTask(task);
|
addCraftingTask(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
* This holds all fluids from all the connected storages from a {@link INetworkMaster}.
|
* This holds all fluids from all the connected storages from a {@link INetworkMaster}.
|
||||||
* <p>
|
* <p>
|
||||||
* Refined Storage uses this class mainly for use in Grids and Detectors to avoid querying
|
* Refined Storage uses this class mainly for use in Grids and Detectors to avoid querying
|
||||||
* individual {@link IFluidStorage} constantly (performance impact) and to send and detect storage changes
|
* individual {@link IFluidStorage}s constantly (performance impact) and to send and detect storage changes
|
||||||
* more efficiently.
|
* more efficiently.
|
||||||
*/
|
*/
|
||||||
public interface IFluidStorageCache {
|
public interface IFluidStorageCache {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
* This holds all items from all the connected storages from a {@link INetworkMaster}.
|
* This holds all items from all the connected storages from a {@link INetworkMaster}.
|
||||||
* <p>
|
* <p>
|
||||||
* Refined Storage uses this class mainly for use in Grids and Detectors to avoid querying
|
* Refined Storage uses this class mainly for use in Grids and Detectors to avoid querying
|
||||||
* individual {@link IItemStorage} constantly (performance impact) and to send and detect storage changes
|
* individual {@link IItemStorage}s constantly (performance impact) and to send and detect storage changes
|
||||||
* more efficiently.
|
* more efficiently.
|
||||||
*/
|
*/
|
||||||
public interface IItemStorageCache {
|
public interface IItemStorageCache {
|
||||||
@@ -45,7 +45,7 @@ public interface IItemStorageCache {
|
|||||||
void remove(@Nonnull ItemStack stack);
|
void remove(@Nonnull ItemStack stack);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the list behind this cope
|
* @return the list behind this cache
|
||||||
*/
|
*/
|
||||||
IItemStackList getList();
|
IItemStackList getList();
|
||||||
|
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
public boolean update(Map<ICraftingPatternContainer, Integer> usedContainers) {
|
public boolean update(Map<ICraftingPatternContainer, Integer> usedContainers) {
|
||||||
IItemStackList oreDictPrepped = network.getItemStorageCache().getList().prepOreDict();
|
IItemStackList oreDictPrepped = network.getItemStorageCache().getList().prepOreDict();
|
||||||
|
|
||||||
if (hasMissing()) {
|
if (!missing.isEmpty()) {
|
||||||
for (ItemStack missing : this.missing.getStacks()) {
|
for (ItemStack missing : this.missing.getStacks()) {
|
||||||
if (!oreDictPrepped.trackedRemove(missing, true)) {
|
if (!oreDictPrepped.trackedRemove(missing, true)) {
|
||||||
oreDictPrepped.undo();
|
oreDictPrepped.undo();
|
||||||
@@ -346,11 +346,6 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearMissing() {
|
|
||||||
missing.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getQuantity() {
|
public int getQuantity() {
|
||||||
return quantity;
|
return quantity;
|
||||||
@@ -521,8 +516,8 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasMissing() {
|
public IItemStackList getMissing() {
|
||||||
return !missing.isEmpty();
|
return missing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -145,8 +145,10 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity);
|
ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity);
|
||||||
|
|
||||||
task.calculate();
|
task.calculate();
|
||||||
task.clearMissing();
|
task.getMissing().clear();
|
||||||
|
|
||||||
network.addCraftingTask(task);
|
network.addCraftingTask(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,8 +275,8 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
craftingTaskIterator.remove();
|
craftingTaskIterator.remove();
|
||||||
|
|
||||||
craftingTasksChanged = true;
|
craftingTasksChanged = true;
|
||||||
} else if(task.hasMissing() && ticks % 100 == 0 && Math.random() > 0.5) {
|
} else if (!task.getMissing().isEmpty() && ticks % 100 == 0 && Math.random() > 0.5) {
|
||||||
task.clearMissing();
|
task.getMissing().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user