package net.minecraft.recipebook; import java.util.Iterator; import net.minecraft.util.Mth; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.ShapedRecipe; public interface PlaceRecipeHelper { static void placeRecipe(int i, int j, Recipe recipe, Iterable iterable, PlaceRecipeHelper.Output output) { if (recipe instanceof ShapedRecipe shapedRecipe) { placeRecipe(i, j, shapedRecipe.getWidth(), shapedRecipe.getHeight(), iterable, output); } else { placeRecipe(i, j, i, j, iterable, output); } } static void placeRecipe(int i, int j, int k, int l, Iterable iterable, PlaceRecipeHelper.Output output) { Iterator iterator = iterable.iterator(); int m = 0; for (int n = 0; n < j; n++) { boolean bl = l < j / 2.0F; int o = Mth.floor(j / 2.0F - l / 2.0F); if (bl && o > n) { m += i; n++; } for (int p = 0; p < i; p++) { if (!iterator.hasNext()) { return; } bl = k < i / 2.0F; o = Mth.floor(i / 2.0F - k / 2.0F); int q = k; boolean bl2 = p < k; if (bl) { q = o + k; bl2 = o <= p && p < o + k; } if (bl2) { output.addItemToSlot((T)iterator.next(), m, p, n); } else if (q == p) { m += i - p; break; } m++; } } } @FunctionalInterface public interface Output { void addItemToSlot(T object, int i, int j, int k); } }