use of net.minecraft.item.crafting.ShapedRecipes in project Engine by VoltzEngine-Project.
the class AutoCraftingManager method getIdealRecipe.
/**
* Does this player's inventory contain the required resources to craft this item?
*
* @return Required items to make the desired item.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public Pair<ItemStack, ItemStack[]> getIdealRecipe(ItemStack outputItem) {
this.printDebug("IdealRecipe", outputItem.toString());
for (IRecipe object : RecipeUtility.getRecipesByOutput(outputItem)) {
if (AutoCraftingManager.areStacksEqual(outputItem, object.getRecipeOutput())) {
this.printDebug("IdealRecipe", "Output Match Found");
if (object instanceof ShapedRecipes) {
if (this.hasResource(((ShapedRecipes) object).recipeItems) != null) {
this.printDebug("IdealRecipe", "Shaped Recipe Found");
return new Pair<>(object.getRecipeOutput().copy(), ((ShapedRecipes) object).recipeItems);
}
} else if (object instanceof ShapelessRecipes) {
if (this.hasResource(((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1])) != null) {
this.printDebug("IdealRecipe", "Shapeless Recipe Found");
return new Pair<>(object.getRecipeOutput().copy(), (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1]));
}
} else if (object instanceof ShapedOreRecipe) {
ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object;
Object[] oreRecipeInput = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input");
ArrayList<ItemStack> hasResources = this.hasResource(oreRecipeInput);
if (hasResources != null) {
this.printDebug("IdealRecipe", "ShapedOre Recipe Found");
return new Pair<>(object.getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1]));
}
} else if (object instanceof ShapelessOreRecipe) {
ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object;
ArrayList oreRecipeInput = ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input");
List<ItemStack> hasResources = this.hasResource(oreRecipeInput.toArray());
if (hasResources != null) {
this.printDebug("IdealRecipe", "ShapelessOre Recipe Found");
return new Pair<>(object.getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1]));
}
}
}
}
return null;
}
use of net.minecraft.item.crafting.ShapedRecipes in project pnc-repressurized by TeamPneumatic.
the class CraftingRegistrator method addPressureChamberStorageBlockRecipes.
/**
* Adds recipes like 9 gold ingot --> 1 gold block, and 1 gold block --> 9 gold ingots.
*/
public static void addPressureChamberStorageBlockRecipes() {
// search for a 3x3 recipe where all 9 ingredients are the same
for (IRecipe recipe : CraftingManager.REGISTRY) {
if (recipe instanceof ShapedRecipes) {
ShapedRecipes shaped = (ShapedRecipes) recipe;
NonNullList<Ingredient> ingredients = recipe.getIngredients();
ItemStack ref = ingredients.get(0).getMatchingStacks()[0];
if (ref.isEmpty() || ingredients.size() < 9)
continue;
boolean valid = true;
for (int i = 0; i < 9; i++) {
ItemStack stack = ingredients.get(i).getMatchingStacks()[0];
if (!stack.isItemEqual(ref)) {
valid = false;
break;
}
}
if (valid) {
ItemStack inputStack = ref.copy();
inputStack.setCount(9);
PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack }, 1.0F, new ItemStack[] { shaped.getRecipeOutput() }, false));
ItemStack inputStack2 = shaped.getRecipeOutput().copy();
inputStack2.setCount(1);
PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack2 }, -0.5F, new ItemStack[] { inputStack }, false));
}
}
}
}
use of net.minecraft.item.crafting.ShapedRecipes in project SpongeCommon by SpongePowered.
the class SpongeShapedCraftingRecipeBuilder method from.
@Override
public ShapedCraftingRecipe.Builder from(ShapedCraftingRecipe value) {
this.aisle.clear();
this.ingredientMap.clear();
this.groupName = "";
if (value instanceof ShapedRecipes) {
this.groupName = ((ShapedRecipes) value).group;
}
if (value != null) {
for (int y = 0; y < value.getHeight(); y++) {
String row = "";
for (int x = 0; x < value.getWidth(); x++) {
char symbol = (char) ('a' + x + y * value.getWidth());
row += symbol;
Ingredient ingredient = value.getIngredient(x, y);
this.ingredientMap.put(symbol, ingredient);
}
this.aisle.add(row);
}
this.result = value.getExemplaryResult().createStack();
} else {
this.result = null;
}
return this;
}
use of net.minecraft.item.crafting.ShapedRecipes in project Charset by CharsetMC.
the class RecipeReplacement method process.
public void process(Collection<IRecipe> registry) {
for (IRecipe recipe : registry) {
ResourceLocation recipeName = recipe.getRegistryName();
boolean dirty = false;
if (recipe instanceof ShapedRecipes || recipe instanceof ShapelessRecipes || recipe instanceof ShapedOreRecipe || recipe instanceof ShapelessOreRecipe) {
NonNullList<Ingredient> ingredients = recipe.getIngredients();
for (int i = 0; i < ingredients.size(); i++) {
Ingredient ing = ingredients.get(i);
Ingredient ingNew = replaceIngredient(ing);
if (ingNew != null) {
ingredients.set(i, ingNew);
dirty = true;
}
}
} else if (recipe instanceof RecipeCharset) {
TCharObjectMap<Ingredient> charToIngredient = ((RecipeCharset) recipe).charToIngredient;
NonNullList<Ingredient> ingredients = recipe.getIngredients();
for (int i = 0; i < ingredients.size(); i++) {
Ingredient ing = ingredients.get(i);
Ingredient ingNew = replaceIngredient(ing);
if (ingNew != null) {
ingredients.set(i, ingNew);
TCharIterator iterator = charToIngredient.keySet().iterator();
while (iterator.hasNext()) {
char c = iterator.next();
if (charToIngredient.get(c) == ing) {
charToIngredient.put(c, ing);
}
}
dirty = true;
}
}
}
if (dirty) {
ModCharset.logger.info("Successfully edited " + recipeName + "!");
}
}
}
use of net.minecraft.item.crafting.ShapedRecipes in project Galacticraft by micdoodle8.
the class ShapedRecipeHandler method loadUsageRecipes.
@Override
public void loadUsageRecipes(ItemStack ingredient) {
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
CachedShapedRecipe recipe = null;
if (irecipe instanceof ShapedRecipes) {
recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
} else if (irecipe instanceof ShapedOreRecipe) {
recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
}
if (recipe == null || !recipe.contains(recipe.ingredients, ingredient.getItem())) {
continue;
}
recipe.computeVisuals();
if (recipe.contains(recipe.ingredients, ingredient)) {
recipe.setIngredientPermutation(recipe.ingredients, ingredient);
arecipes.add(recipe);
}
}
}
Aggregations