use of net.minecraft.item.crafting.Ingredient in project BuildCraft by BuildCraft.
the class GuideCraftingFactory method equals.
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null)
return false;
if (obj.getClass() != getClass())
return false;
GuideCraftingFactory other = (GuideCraftingFactory) obj;
// Shortcut out of this full itemstack comparison as its really expensive
if (hash != other.hash)
return false;
if (input.getWidth() != other.input.getWidth() || input.getHeight() != other.input.getHeight())
return false;
NBTTagList nbtThis = new NBTTagList();
for (Ingredient ingredient : this.input) {
NBTTagList list = new NBTTagList();
for (ItemStack stack : ingredient.getMatchingStacks()) {
list.appendTag(stack.serializeNBT());
}
nbtThis.appendTag(list);
}
NBTTagList nbtThat = new NBTTagList();
for (Ingredient ingredient : other.input) {
NBTTagList list = new NBTTagList();
for (ItemStack stack : ingredient.getMatchingStacks()) {
list.appendTag(stack.serializeNBT());
}
nbtThat.appendTag(list);
}
return nbtThis.equals(nbtThat);
}
use of net.minecraft.item.crafting.Ingredient in project BuildCraft by BuildCraft.
the class BCTransportRecipes method addPipeUpgradeRecipe.
private static void addPipeUpgradeRecipe(ItemPipeHolder from, ItemPipeHolder to, Object additional) {
if (from == null || to == null) {
return;
}
if (additional == null) {
throw new NullPointerException("additional");
}
IRecipe returnRecipe = new ShapelessOreRecipe(from.getRegistryName(), new ItemStack(from), new ItemStack(to)).setRegistryName(new ResourceLocation(from.getRegistryName() + "_undo"));
ForgeRegistries.RECIPES.register(returnRecipe);
NonNullList<Ingredient> list = NonNullList.create();
list.add(Ingredient.fromItem(from));
list.add(CraftingHelper.getIngredient(additional));
IRecipe upgradeRecipe = new ShapelessRecipes(to.getRegistryName().getResourcePath(), new ItemStack(to), list).setRegistryName(new ResourceLocation(to.getRegistryName() + "_colorless"));
ForgeRegistries.RECIPES.register(upgradeRecipe);
for (EnumDyeColor colour : ColourUtil.COLOURS) {
ItemStack f = new ItemStack(from, 1, colour.getMetadata() + 1);
ItemStack t = new ItemStack(to, 1, colour.getMetadata() + 1);
IRecipe returnRecipeColored = new ShapelessOreRecipe(from.getRegistryName(), f, t).setRegistryName(new ResourceLocation(from.getRegistryName() + colour.getName() + "_undo"));
ForgeRegistries.RECIPES.register(returnRecipeColored);
NonNullList<Ingredient> colorList = NonNullList.create();
colorList.add(Ingredient.fromStacks(f));
colorList.add(CraftingHelper.getIngredient(additional));
IRecipe upgradeRecipeColored = new ShapelessOreRecipe(to.getRegistryName(), colorList, t).setRegistryName(new ResourceLocation(to.getRegistryName() + "_" + colour.getName()));
ForgeRegistries.RECIPES.register(upgradeRecipeColored);
}
}
use of net.minecraft.item.crafting.Ingredient in project BuildCraft by BuildCraft.
the class GuiAdvancedCraftingTable method sendRecipe.
private void sendRecipe(IRecipe recipe) {
List<ItemStack> stacks = new ArrayList<>(9);
int maxX = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeWidth() : 3;
int maxY = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeHeight() : 3;
int offsetX = maxX == 1 ? 1 : 0;
int offsetY = maxY == 1 ? 1 : 0;
List<Ingredient> ingredients = recipe.getIngredients();
if (ingredients.isEmpty()) {
return;
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
if (x < offsetX || y < offsetY) {
stacks.add(ItemStack.EMPTY);
continue;
}
int i = x - offsetX + (y - offsetY) * maxX;
if (i >= ingredients.size() || x - offsetX >= maxX) {
stacks.add(ItemStack.EMPTY);
} else {
Ingredient ing = ingredients.get(i);
ItemStack[] matching = ing.getMatchingStacks();
if (matching.length >= 1) {
stacks.add(matching[0]);
} else {
stacks.add(ItemStack.EMPTY);
}
}
}
}
container.sendSetPhantomSlots(container.tile.invBlueprint, stacks);
}
use of net.minecraft.item.crafting.Ingredient 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.Ingredient in project FoodCraft-Reloaded by LasmGratel.
the class RecipeManager method getIngredientRecipeNullable.
@Nullable
public <T, R extends Recipe<T>> R getIngredientRecipeNullable(Class<R> recipeClass, T input) {
if (!(input instanceof RecipeInput) && !((((RecipeInput) input).value instanceof ItemStack[]) || ((RecipeInput) input).value instanceof Item[]))
return null;
return getRecipes(recipeClass).stream().filter(recipe -> recipe.getInput() instanceof RecipeInput).filter(recipe -> ((RecipeInput) recipe.getInput()).getValue() instanceof Ingredient[]).filter(recipe -> ((RecipeInput) recipe.getInput()).getValue().length == ((RecipeInput) input).getValue().length).filter(recipe -> {
Ingredient[] ingredients = (Ingredient[]) ((RecipeInput) recipe.getInput()).getValue();
Object[] inputs = ((RecipeInput) input).getValue();
for (int i = 0; i < inputs.length; i++) {
ItemStack stack;
if (inputs[i] instanceof Item)
stack = new ItemStack((Item) inputs[i]);
else
stack = (ItemStack) inputs[i];
if (!ingredients[i].apply(stack))
return false;
}
return true;
}).findAny().orElse(null);
}
Aggregations