use of net.minecraft.item.crafting.ShapedRecipes in project RebornCore by TechReborn.
the class RebornCraftingHelper method addShapedRecipe.
/**
* Adds a basic shaped recipe
*
* @param output The stack that should be produced
*/
public static void addShapedRecipe(ItemStack output, Object... params) {
ResourceLocation location = getNameForRecipe(output);
CraftingHelper.ShapedPrimer primer = CraftingHelper.parseShaped(params);
ShapedRecipes recipe = new ShapedRecipes(output.getItem().getRegistryName().toString(), primer.width, primer.height, primer.input, output);
recipe.setRegistryName(location);
GameData.register_impl(recipe);
}
use of net.minecraft.item.crafting.ShapedRecipes in project RebornCore by TechReborn.
the class RecipeRemover method removeShapedRecipe.
public static void removeShapedRecipe(ItemStack resultItem) {
for (IRecipe tmpRecipe : CraftingManager.REGISTRY) {
if (tmpRecipe instanceof ShapedRecipes) {
ShapedRecipes recipe = (ShapedRecipes) tmpRecipe;
ItemStack recipeResult = recipe.getRecipeOutput();
if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
removeRecipe(recipe);
}
}
}
}
use of net.minecraft.item.crafting.ShapedRecipes in project Minechem by iopleke.
the class Recipe method init.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void init() {
Map<MapKey, ArrayList<Recipe>> preCullRecipes = new Hashtable<MapKey, ArrayList<Recipe>>();
recipes = new LinkedHashMap<MapKey, Recipe>();
smelting = FurnaceRecipes.smelting().getSmeltingList();
List craftingRecipes = CraftingManager.getInstance().getRecipeList();
if (Loader.isModLoaded("RotaryCraft")) {
List add = getRotaryRecipes();
if (add != null) {
craftingRecipes.addAll(add);
}
}
if (Loader.isModLoaded("Railcaft")) {
List add = getRailcraftRecipes();
if (add != null) {
craftingRecipes.addAll(add);
}
}
for (Object recipe : craftingRecipes) {
if (recipe instanceof IRecipe) {
ItemStack input = ((IRecipe) recipe).getRecipeOutput();
if (!invalidStack(input)) {
LogHelper.debug("Adding recipe for " + input.toString());
ItemStack[] components = null;
List<ItemStack> inputs = new ArrayList<ItemStack>();
if (recipe.getClass().equals(ShapelessOreRecipe.class) && ((ShapelessOreRecipe) recipe).getInput().size() > 0) {
for (Object o : ((ShapelessOreRecipe) recipe).getInput()) {
if (o instanceof ItemStack) {
inputs.add((ItemStack) o);
}
}
} else if (recipe.getClass().equals(ShapedOreRecipe.class)) {
for (Object o : ((ShapedOreRecipe) recipe).getInput()) {
if (o instanceof ItemStack) {
inputs.add((ItemStack) o);
} else if (o instanceof String) {
inputs.add(OreDictionary.getOres((String) o).get(0));
} else if (o instanceof ArrayList && !((ArrayList) o).isEmpty()) {
inputs.add((ItemStack) ((ArrayList) o).get(0));
}
}
} else if (recipe.getClass().equals(ShapelessRecipes.class) && ((ShapelessRecipes) recipe).recipeItems.toArray() instanceof ItemStack[]) {
inputs = (List<ItemStack>) (List<?>) (((ShapelessRecipes) recipe).recipeItems);
} else if (recipe.getClass().equals(ShapedRecipes.class)) {
inputs.addAll(Arrays.asList(((ShapedRecipes) recipe).recipeItems));
}
MapKey key = MapKey.getKey(input);
if (inputs.size() > 0 && key != null) {
for (Iterator<ItemStack> itr = inputs.iterator(); itr.hasNext(); ) {
ItemStack component = itr.next();
if (invalidStack(component) || component.getItem().hasContainerItem(component))
itr.remove();
}
components = inputs.toArray(new ItemStack[inputs.size()]);
if (components.length > 0) {
Recipe addRecipe = new Recipe(input, components);
addPreCullRecipe(key, addRecipe, preCullRecipes);
}
}
}
}
}
for (ItemStack input : smelting.keySet()) {
ItemStack output = smelting.get(input);
if (invalidStack(input) || invalidStack(output)) {
continue;
}
MapKey key = MapKey.getKey(output);
if (key != null) {
Recipe addRecipe = new Recipe(output, new ItemStack[] { input });
LogHelper.debug("Adding Smelting recipe for " + output.toString());
addPreCullRecipe(key, addRecipe, preCullRecipes);
}
}
for (Map.Entry<MapKey, ArrayList<Recipe>> entry : preCullRecipes.entrySet()) {
if (entry.getValue() != null && entry.getValue().size() > 0) {
LogHelper.debug("Culling recipe for " + entry.getValue().get(0).output.toString());
}
int depth = cullRecipes(entry, preCullRecipes);
if (entry.getValue().size() == 1) {
Recipe addRecipe = entry.getValue().get(0);
addRecipe.depth = depth;
recipes.put(entry.getKey(), addRecipe);
}
}
}
use of net.minecraft.item.crafting.ShapedRecipes in project ArsMagica2 by Mithion.
the class RecipeUtilities method addShapedRecipeFirst.
public static void addShapedRecipeFirst(List recipeList, ItemStack itemstack, Object... objArray) {
String var3 = "";
int var4 = 0;
int var5 = 0;
int var6 = 0;
if (objArray[var4] instanceof String[]) {
String[] var7 = ((String[]) objArray[var4++]);
for (int var8 = 0; var8 < var7.length; ++var8) {
String var9 = var7[var8];
++var6;
var5 = var9.length();
var3 = var3 + var9;
}
} else {
while (objArray[var4] instanceof String) {
String var11 = (String) objArray[var4++];
++var6;
var5 = var11.length();
var3 = var3 + var11;
}
}
HashMap var12;
for (var12 = new HashMap(); var4 < objArray.length; var4 += 2) {
Character var13 = (Character) objArray[var4];
ItemStack var14 = null;
if (objArray[var4 + 1] instanceof Item) {
var14 = new ItemStack((Item) objArray[var4 + 1]);
} else if (objArray[var4 + 1] instanceof Block) {
var14 = new ItemStack((Block) objArray[var4 + 1], 1, Short.MAX_VALUE);
} else if (objArray[var4 + 1] instanceof ItemStack) {
var14 = (ItemStack) objArray[var4 + 1];
}
var12.put(var13, var14);
}
ItemStack[] var15 = new ItemStack[var5 * var6];
for (int var16 = 0; var16 < var5 * var6; ++var16) {
char var10 = var3.charAt(var16);
if (var12.containsKey(Character.valueOf(var10))) {
var15[var16] = ((ItemStack) var12.get(Character.valueOf(var10))).copy();
} else {
var15[var16] = null;
}
}
ShapedRecipes var17 = new ShapedRecipes(var5, var6, var15, itemstack);
recipeList.add(0, var17);
}
use of net.minecraft.item.crafting.ShapedRecipes in project Engine by VoltzEngine-Project.
the class AutoCraftingManager method printRecipes.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void printRecipes(ItemStack stack) {
List<IRecipe> recipes = RecipeUtility.getRecipesByOutput(stack);
for (IRecipe recipe : recipes) {
if (recipe.getRecipeOutput() != null) {
if (AutoCraftingManager.areStacksEqual(recipe.getRecipeOutput(), stack)) {
if (recipe instanceof ShapedRecipes) {
printRecipe(((ShapedRecipes) recipe).recipeItems);
} else if (recipe instanceof ShapelessRecipes) {
printRecipe(((ShapelessRecipes) recipe).recipeItems.toArray(new Object[1]));
} else if (recipe instanceof ShapedOreRecipe) {
ShapedOreRecipe oreRecipe = (ShapedOreRecipe) recipe;
printRecipe((Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input"));
} else if (recipe instanceof ShapelessOreRecipe) {
ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) recipe;
ArrayList oreRecipeInput = ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input");
for (Object obj : oreRecipeInput) {
System.out.println(obj);
}
}
}
}
}
}
Aggregations