Skip to content

Commit

Permalink
ExprIngredientsOfRecipe - returning items with the shape for shaped r…
Browse files Browse the repository at this point in the history
…ecipe (#223)
  • Loading branch information
mowmowkittycat authored Jul 29, 2022
1 parent 0243de8 commit 02faf0b
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ch.njol.util.Kleenean;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.event.Event;
import org.bukkit.inventory.CookingRecipe;
import org.bukkit.inventory.FurnaceRecipe;
Expand Down Expand Up @@ -61,9 +62,15 @@ protected ItemType[] get(Event e) {
Bukkit.recipeIterator().forEachRemaining(recipe -> {
if (recipe instanceof Keyed keyed && keyed.getKey().toString().equalsIgnoreCase(this.recipe.getSingle(e))) {
if (recipe instanceof ShapedRecipe shapedRecipe) {
for (ItemStack ingredient : shapedRecipe.getIngredientMap().values()) {
if (ingredient == null) continue;
items.add(new ItemType(ingredient));
String[] shape = shapedRecipe.getShape();
for (int i = 0; i < Math.pow(shape.length, 2); i++) {
items.add(new ItemType(Material.AIR));
}
for (int i = 0; i < shape.length; i++) {
for (int x = 0; x < shape[i].length(); x++) {
ItemStack ingredient = shapedRecipe.getIngredientMap().get(shape[i].toCharArray()[x]);
if (ingredient != null) items.set(i * shape.length + x, new ItemType(ingredient));
}
}
} else if (recipe instanceof ShapelessRecipe shapelessRecipe) {
for (ItemStack ingredient : shapelessRecipe.getIngredientList()) {
Expand Down

0 comments on commit 02faf0b

Please sign in to comment.