Fixes #94 "multiple recipies"
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
**Features**
|
**Features**
|
||||||
- Added an API
|
- Added an API
|
||||||
- Added Storage Drawers integration
|
- Added Storage Drawers integration
|
||||||
|
- Added handling for patterns that return the same item
|
||||||
- Increased cable recipe to 12 cables
|
- Increased cable recipe to 12 cables
|
||||||
|
|
||||||
### 0.7.8
|
### 0.7.8
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class CraftingTaskScheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void schedule(TileController controller, int compare, ItemStack item) {
|
public void schedule(TileController controller, int compare, ItemStack item) {
|
||||||
CraftingPattern pattern = controller.getPattern(item, compare);
|
CraftingPattern pattern = controller.getPatternWithBestScore(item, compare);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
scheduledItem = item;
|
scheduledItem = item;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class BasicCraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
satisfied[i] = true;
|
satisfied[i] = true;
|
||||||
} else if (!childTasks[i]) {
|
} else if (!childTasks[i]) {
|
||||||
CraftingPattern pattern = controller.getPattern(input);
|
CraftingPattern pattern = controller.getPatternWithBestScore(input);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
controller.addCraftingTask(controller.createCraftingTask(pattern));
|
controller.addCraftingTask(controller.createCraftingTask(pattern));
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
|||||||
controller.push(took, took.stackSize, false);
|
controller.push(took, took.stackSize, false);
|
||||||
}
|
}
|
||||||
} else if (!childTasks[i]) {
|
} else if (!childTasks[i]) {
|
||||||
CraftingPattern pattern = controller.getPattern(input);
|
CraftingPattern pattern = controller.getPatternWithBestScore(input);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
childTasks[i] = true;
|
childTasks[i] = true;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class StorageHandler {
|
|||||||
|
|
||||||
int quantityPerRequest = 0;
|
int quantityPerRequest = 0;
|
||||||
|
|
||||||
CraftingPattern pattern = controller.getPattern(requested);
|
CraftingPattern pattern = controller.getPatternWithBestScore(requested);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
for (ItemStack output : pattern.getOutputs()) {
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
|
|||||||
@@ -229,20 +229,55 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
return patterns;
|
return patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftingPattern getPattern(ItemStack pattern) {
|
public List<CraftingPattern> getPattern(ItemStack pattern) {
|
||||||
return getPattern(pattern, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
|
return getPattern(pattern, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftingPattern getPattern(ItemStack pattern, int flags) {
|
public List<CraftingPattern> getPattern(ItemStack pattern, int flags) {
|
||||||
|
List<CraftingPattern> patterns = new ArrayList<CraftingPattern>();
|
||||||
|
|
||||||
for (CraftingPattern craftingPattern : getPatterns()) {
|
for (CraftingPattern craftingPattern : getPatterns()) {
|
||||||
for (ItemStack output : craftingPattern.getOutputs()) {
|
for (ItemStack output : craftingPattern.getOutputs()) {
|
||||||
if (RefinedStorageUtils.compareStack(output, pattern, flags)) {
|
if (RefinedStorageUtils.compareStack(output, pattern, flags)) {
|
||||||
return craftingPattern;
|
patterns.add(craftingPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return patterns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftingPattern getPatternWithBestScore(ItemStack pattern) {
|
||||||
|
return getPatternWithBestScore(pattern, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftingPattern getPatternWithBestScore(ItemStack pattern, int flags) {
|
||||||
|
List<CraftingPattern> patterns = getPattern(pattern, flags);
|
||||||
|
|
||||||
|
if (patterns.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
} else if (patterns.size() == 1) {
|
||||||
|
return patterns.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] scores = new int[patterns.size()];
|
||||||
|
int highestScore = 0;
|
||||||
|
int highestPattern = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < patterns.size(); ++i) {
|
||||||
|
for (ItemStack input : patterns.get(i).getInputs()) {
|
||||||
|
ItemStack stored = getItem(input, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
|
||||||
|
|
||||||
|
scores[i] += stored != null ? stored.stackSize : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scores[i] > highestScore) {
|
||||||
|
highestScore = scores[i];
|
||||||
|
highestPattern = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return patterns.get(highestPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncMachines() {
|
private void syncMachines() {
|
||||||
|
|||||||
Reference in New Issue
Block a user