Added support for multiple crafting recipes in Autocrafting.

This commit is contained in:
Brianna 2019-04-25 13:55:02 -04:00
parent 6d33ad9e4a
commit e4a6f8c0fd

View File

@ -15,7 +15,7 @@ import java.util.Map;
public class ModuleAutoCrafting implements Module {
private final Map<Material, Recipe> cachedRecipes = new HashMap<>();
private final Map<Material, Recipes> cachedRecipes = new HashMap<>();
private final Map<Hopper, Material> lastMaterial = new HashMap<>();
public static List<ItemStack> compressItemStack(List<ItemStack> target) {
@ -43,8 +43,11 @@ public class ModuleAutoCrafting implements Module {
if (hopper.getAutoCrafting() != null && canMove(hopperInventory, new ItemStack(hopper.getAutoCrafting()))) {
Recipe recipe = cachedRecipes.get(hopper.getAutoCrafting());
if (!(recipe instanceof ShapedRecipe) && !(recipe instanceof ShapelessRecipe)) return;
if (cachedRecipes.get(hopper.getAutoCrafting()) == null) return;
top:
for (Recipe recipe : cachedRecipes.get(hopper.getAutoCrafting()).getRecipes()) {
if (!(recipe instanceof ShapedRecipe) && !(recipe instanceof ShapelessRecipe)) continue;
List<ItemStack> ingredientMap = null;
if (recipe instanceof ShapelessRecipe) ingredientMap = ((ShapelessRecipe) recipe).getIngredientList();
if (recipe instanceof ShapedRecipe)
@ -71,7 +74,7 @@ public class ModuleAutoCrafting implements Module {
}
if (amt < item.getAmount()) {
return;
continue top;
}
}
main2:
@ -92,7 +95,7 @@ public class ModuleAutoCrafting implements Module {
}
hopperInventory.addItem(recipe.getResult());
}
}
}
public List<Material> getBlockedItems(Hopper hopper) {
@ -109,11 +112,14 @@ public class ModuleAutoCrafting implements Module {
}
if (!cachedRecipes.containsKey(material)) {
Recipes recipes = new Recipes();
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(material))) {
cachedRecipes.put(material, recipe);
recipes.addRecipe(recipe);
}
cachedRecipes.put(material, recipes);
} else {
Recipe recipe = cachedRecipes.get(material);
Recipes recipes = cachedRecipes.get(material);
for (Recipe recipe : recipes.getRecipes()) {
if (recipe instanceof ShapedRecipe) {
for (ItemStack itemStack : ((ShapedRecipe) recipe).getIngredientMap().values()) {
if (itemStack == null) continue;
@ -127,6 +133,7 @@ public class ModuleAutoCrafting implements Module {
}
}
}
}
return materials;
}
@ -149,4 +156,21 @@ public class ModuleAutoCrafting implements Module {
}
return false;
}
class Recipes {
private List<Recipe> recipes = new ArrayList<>();
public List<Recipe> getRecipes() {
return new ArrayList<>(recipes);
}
public void addRecipe(Recipe recipe) {
this.recipes.add(recipe);
}
public void clearRecipes() {
recipes.clear();
}
}
}