package com.yolp900.itsjustacharm.common.crafting; import com.yolp900.itsjustacharm.api.ItsJustaCharmAPI; import com.yolp900.itsjustacharm.api.constructionTable.RecipeBaseConstructionTable; import com.yolp900.itsjustacharm.api.constructionTable.RecipeShapedConstructionTable; import com.yolp900.itsjustacharm.api.constructionTable.RecipeShapelessConstructionTable; import com.yolp900.itsjustacharm.common.inventory.ContainerDummy; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.world.World; public class CraftingHandlerConstructionTable { public static ItemStack getVanillaRecipeOutput(ItemStack[] gridInputs, World world) { InventoryCrafting ic = new InventoryCrafting(new ContainerDummy(), 3, 3); for (int i = 0; i < 9; i++) { ic.setInventorySlotContents(i, gridInputs[i]); } return CraftingManager.getInstance().findMatchingRecipe(ic, world); } public static ItemStack getConstructionTableShapedRecipeOutput(ItemStack[] gridInputs, ItemStack[] secInputs) { ItemStack output = null; int numOfItemStacks = 0; for (ItemStack secInput : secInputs) { if (secInput != null) { numOfItemStacks++; } } ItemStack[] secNoNulls = new ItemStack[numOfItemStacks]; int index = 0; for (ItemStack secInput : secInputs) { if (secInput != null) { secNoNulls[index] = secInput; index++; } } for (RecipeBaseConstructionTable recipe : ItsJustaCharmAPI.ConstructionTable.constructionTableRecipes) { if (recipe instanceof RecipeShapedConstructionTable) { if (recipe.matches(gridInputs, secNoNulls)) { output = recipe.getOutput(); break; } } } return output; } public static ItemStack getConstructionTableShapelessRecipeOutput(ItemStack[] gridInputs, ItemStack[] secInputs) { if (gridInputs == null || gridInputs.length <= 0) return null; ItemStack output = null; int numOfItemStacks = 0; for (ItemStack secInput : secInputs) { if (secInput != null) { numOfItemStacks++; } } ItemStack[] secNoNulls = new ItemStack[numOfItemStacks]; int index = 0; for (ItemStack secInput : secInputs) { if (secInput != null) { secNoNulls[index] = secInput; index++; } } for (RecipeBaseConstructionTable recipe : ItsJustaCharmAPI.ConstructionTable.constructionTableRecipes) { if (recipe instanceof RecipeShapelessConstructionTable) { if (recipe.matches(gridInputs, secNoNulls)) { output = recipe.getOutput(); break; } } } return output; } public static RecipeType getCurrentRecipeType(ItemStack[] gridInputs, ItemStack[] secInputs, World world) { RecipeType currentType = RecipeType.None; if (getVanillaRecipeOutput(gridInputs, world) != null) currentType = RecipeType.Vanilla; if (getConstructionTableShapelessRecipeOutput(gridInputs, secInputs) != null) currentType = RecipeType.CTShapeless; if (getConstructionTableShapedRecipeOutput(gridInputs, secInputs) != null) currentType = RecipeType.CTShaped; return currentType; } public enum RecipeType { None, Vanilla, CTShaped, CTShapeless } }