use of net.minecraft.item.crafting.Ingredient in project MC-Prefab by Brian-Wuest.
the class ModRegistry method AddShapelessRecipe.
/**
* This should only be used for registering recipes for vanilla objects and not mod-specific objects.
* @param name The name of the recipe.
* @param stack The output stack.
* @param recipeComponents The recipe components.
*/
public static ShapelessRecipes AddShapelessRecipe(String name, String groupName, ItemStack stack, Object... recipeComponents) {
name = Prefab.MODID.toLowerCase().replace(' ', '_') + ":" + name;
NonNullList<Ingredient> list = NonNullList.create();
for (Object object : recipeComponents) {
if (object instanceof ItemStack) {
list.add(Ingredient.fromStacks(((ItemStack) object).copy()));
} else if (object instanceof Item) {
list.add(Ingredient.fromStacks(new ItemStack((Item) object)));
} else {
if (!(object instanceof Block)) {
throw new IllegalArgumentException("Invalid shapeless recipe: unknown type " + object.getClass().getName() + "!");
}
list.add(Ingredient.fromStacks(new ItemStack((Block) object)));
}
}
ShapelessRecipes shapelessRecipes = new ShapelessRecipes(groupName, stack, list);
shapelessRecipes.setRegistryName(name);
ForgeRegistries.RECIPES.register(shapelessRecipes);
return shapelessRecipes;
}
use of net.minecraft.item.crafting.Ingredient in project Solar by Martacus.
the class TileOfferingShrine method onUse.
public void onUse(EntityPlayer player, EnumHand hand) {
ItemStack heldItem = player.getHeldItem(hand);
if (heldItem.getItem() == ModItems.RITUAL_AMULET) {
if (!this.validMultiblock()) {
// todo: let player know multiblock aint valid maybe?
return;
}
LinkedList<ItemStack> itemStacks = this.itemStackHandler.getOfferItemStacks();
List<OfferingRecipe> offeringRecipes = OfferingRecipeRegister.getRecipes();
for (OfferingRecipe recipe : offeringRecipes) {
boolean matches = true;
List<Ingredient> ingredients = recipe.getIngredients();
for (int i = 7; i >= 0; i--) {
ItemStack ingredientStack = ingredients.get(i).getMatchingStacks()[0];
if (!itemStacks.get(i).isItemEqual(ingredientStack)) {
matches = false;
}
}
if (matches) {
this.offeringRecipe = OfferingRecipeRegister.getRegistrationName(recipe);
notifyUpdate();
break;
}
}
return;
}
ItemStack returnStack;
ItemStack insertStack = heldItem.copy();
insertStack.setCount(1);
returnStack = this.itemStackHandler.insertItem(insertStack, false);
if (returnStack.isEmpty()) {
if (heldItem.getCount() <= 1) {
player.setHeldItem(hand, ItemStack.EMPTY);
} else {
heldItem.setCount(heldItem.getCount() - 1);
}
}
notifyUpdate();
}
use of net.minecraft.item.crafting.Ingredient in project BuildCraft by BuildCraft.
the class GuiAutoCraftItems 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 RebornCore by TechReborn.
the class RebornCraftingHelper method buildInput.
/**
* Converts an object array into a NonNullList of Ingredients
*/
private static NonNullList<Ingredient> buildInput(Object[] input) {
NonNullList<Ingredient> list = NonNullList.create();
for (Object obj : input) {
if (obj instanceof Ingredient) {
list.add((Ingredient) obj);
} else {
Ingredient ingredient = CraftingHelper.getIngredient(obj);
if (ingredient == null) {
ingredient = Ingredient.EMPTY;
}
list.add(ingredient);
}
}
return list;
}
use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class FluidRecipeJEI method getIngredients.
@Override
public void getIngredients(@Nonnull IIngredients ingredients) {
List<List<ItemStack>> stacks = Lists.newArrayList();
stacks.add(Lists.newArrayList(builder.getMainInput().getMatchingStacks()));
for (Ingredient ingredient : builder.getInputs()) stacks.add(Lists.newArrayList(ingredient.getMatchingStacks()));
if (!isFluidOutput())
for (List<ItemStack> stackList : stacks) stackList.removeIf(Ingredient.fromStacks(builder.getOutput())::apply);
ingredients.setInputLists(ItemStack.class, stacks);
ingredients.setInput(FluidStack.class, new FluidStack(builder.getFluid(), 1000));
if (isFluidOutput())
ingredients.setOutput(FluidStack.class, builder.getFluidOutput());
else
ingredients.setOutput(ItemStack.class, builder.getOutput());
}
Aggregations