add byproducts
parent
2b7940ad7b
commit
f8c17d351f
|
|
@ -9,6 +9,7 @@ import org.jgrapht.graph.DefaultWeightedEdge;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Recipe {
|
||||
private Map<Item, Integer> inputs;
|
||||
|
|
@ -110,14 +111,25 @@ public class Recipe {
|
|||
public Graph<Item, DefaultWeightedEdge> buildGraph(Item target) {
|
||||
Graph<Item, DefaultWeightedEdge> graph = new DefaultDirectedWeightedGraph<>(DefaultWeightedEdge.class);
|
||||
graph.addVertex(target);
|
||||
target.sum +=1;
|
||||
target.sum += 1;
|
||||
Map<Item, Integer> output = outputs.entrySet().stream()
|
||||
.filter(itemIntegerEntry -> itemIntegerEntry.getKey() != target)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
output.forEach((item, integer) -> {
|
||||
graph.addVertex(item);
|
||||
graph.addEdge(target, item);
|
||||
graph.setEdgeWeight(target, item, integer);
|
||||
});
|
||||
inputs.forEach((item, integer) -> {
|
||||
graph.addVertex(item);
|
||||
graph.addEdge(item, target);
|
||||
graph.setEdgeWeight(item, target, integer);
|
||||
|
||||
Graph<Item, DefaultWeightedEdge> g = item.getRecipe().buildGraph(item);
|
||||
Graphs.addGraph(graph, g);
|
||||
Recipe recipe = item.getRecipe();
|
||||
if (recipe != null) {
|
||||
Graph<Item, DefaultWeightedEdge> g = recipe.buildGraph(item);
|
||||
Graphs.addGraph(graph, g);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue