mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-18 19:39:14 +00:00
70 lines
2.2 KiB
Java
70 lines
2.2 KiB
Java
package crazypants.enderio.machine;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class MachineRecipeRegistry {
|
|
|
|
public static final MachineRecipeRegistry instance = new MachineRecipeRegistry();
|
|
|
|
private final Map<String, Map<String, IMachineRecipe>> machineRecipes = new HashMap<>();
|
|
|
|
public void registerRecipe(String machine, IMachineRecipe recipe) {
|
|
getRecipesForMachine(machine).put(recipe.getUid(), recipe);
|
|
}
|
|
|
|
public Map<String, IMachineRecipe> getRecipesForMachine(String machineName) {
|
|
Map<String, IMachineRecipe> res = machineRecipes.get(machineName);
|
|
if (res == null) {
|
|
res = new LinkedHashMap<>();
|
|
machineRecipes.put(machineName, res);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public IMachineRecipe getRecipeForUid(String uid) {
|
|
if (uid == null) {
|
|
return null;
|
|
}
|
|
for (Map<String, IMachineRecipe> recipes : machineRecipes.values()) {
|
|
for (IMachineRecipe recipe : recipes.values()) {
|
|
if (uid.equals(recipe.getUid())) {
|
|
return recipe;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public IMachineRecipe getRecipeForInputs(String machineName, MachineRecipeInput... inputs) {
|
|
Map<String, IMachineRecipe> recipes = getRecipesForMachine(machineName);
|
|
if (recipes == null) {
|
|
return null;
|
|
}
|
|
for (IMachineRecipe recipe : recipes.values()) {
|
|
if (recipe.isRecipe(inputs)) {
|
|
return recipe;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public List<IMachineRecipe> getRecipesForInput(String machineName, MachineRecipeInput input) {
|
|
if (input == null) {
|
|
return Collections.emptyList();
|
|
}
|
|
List<IMachineRecipe> result = new ArrayList<>();
|
|
Map<String, IMachineRecipe> recipes = getRecipesForMachine(machineName);
|
|
for (IMachineRecipe recipe : recipes.values()) {
|
|
if (recipe.isValidInput(input)) {
|
|
result.add(recipe);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|