net.minecraft.item.crafting.Ingredient Java Examples
The following examples show how to use
net.minecraft.item.crafting.Ingredient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecipeShapelessFluid.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean matches(InventoryCrafting matrix, World world) { ArrayList<Ingredient> required = new ArrayList<>(getIngredients()); for (int i = 0; i < matrix.getSizeInventory(); i++) { ItemStack slot = matrix.getStackInSlot(i); if (!slot.isEmpty()) { boolean inRecipe = false; Iterator<Ingredient> iterator = required.iterator(); while (iterator.hasNext()) { Ingredient next = iterator.next(); if (next.apply(slot)) { inRecipe = true; iterator.remove(); break; } } if (!inRecipe) return false; } } return required.isEmpty(); }
Example #2
Source File: RecipeBase.java From EnderStorage with MIT License | 6 votes |
@Override public boolean matches(CraftingInventory inv, World worldIn) { for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { Ingredient ingredient = Ingredient.EMPTY; if (i >= 0 && j >= 0 && i < 3 && j < 3) { ingredient = this.input.get(i + j * 3); } if (!ingredient.test(inv.getStackInSlot(i + j * inv.getWidth()))) { return false; } } } return true; }
Example #3
Source File: MetaItemShapelessRecipeFactory.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public IRecipe parse(JsonContext context, JsonObject json) { String group = JsonUtils.getString(json, "group", ""); NonNullList<Ingredient> ings = NonNullList.create(); for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients")) ings.add(CraftingHelper.getIngredient(ele, context)); if (ings.isEmpty()) throw new JsonParseException("No ingredients for shapeless recipe"); JsonObject result = JsonUtils.getJsonObject(json, "result"); String name = JsonUtils.getString(result, "name"); int amount = JsonUtils.getInt(result, "amount", 1); ItemStack stack = ItemStack.EMPTY; for (MetaItem<?> item : MetaItems.ITEMS) { MetaItem<?>.MetaValueItem value = item.getItem(name); if (value != null) { stack = value.getStackForm(amount); } } return new ShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), ings, stack); }
Example #4
Source File: CraftShapedRecipe.java From Kettle with GNU General Public License v3.0 | 6 votes |
public void addToCraftingManager() { String[] shape = this.getShape(); Map<Character, ItemStack> ingred = this.getIngredientMap(); int width = shape[0].length(); NonNullList<Ingredient> data = NonNullList.withSize(shape.length * width, Ingredient.EMPTY); for (int i = 0; i < shape.length; i++) { String row = shape[i]; for (int j = 0; j < row.length(); j++) { data.set(i * width + j, Ingredient.fromStacks(new net.minecraft.item.ItemStack[]{CraftItemStack.asNMSCopy(ingred.get(row.charAt(j)))})); } } // TODO: Check if it's correct way to register recipes ForgeRegistries.RECIPES.register(new ShapedRecipes("", width, shape.length, data, CraftItemStack.asNMSCopy(this.getResult()))); // CraftingManager.register(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapedRecipes("", width, shape.length, data, CraftItemStack.asNMSCopy(this.getResult()))); }
Example #5
Source File: ItemBookCode.java From Minecoprocessors with GNU General Public License v3.0 | 6 votes |
@SubscribeEvent public static void registerRecipes(final RegistryEvent.Register<IRecipe> event) { NonNullList<Ingredient> lst = NonNullList.create(); lst.add(Ingredient.fromItem(Items.WRITABLE_BOOK)); lst.add(Ingredient.fromItem(BlockMinecoprocessor.ITEM_INSTANCE)); event.getRegistry().register(new ShapelessRecipes("", new ItemStack(ItemBookCode.INSTANCE), lst) { @Override public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) { NonNullList<ItemStack> l = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY); for (int i = 0; i < l.size(); ++i) { ItemStack stack = inv.getStackInSlot(i); if (stack.getItem() == BlockMinecoprocessor.ITEM_INSTANCE) { ItemStack returnStack = stack.copy(); returnStack.setCount(1); l.set(i, returnStack); return l; } } throw new RuntimeException("Item to return not found in inventory"); } }.setRegistryName(ItemBookCode.REGISTRY_NAME)); }
Example #6
Source File: ItemHelper.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public static boolean isSameRecipeInput(Ingredient target, Object input) { if (input instanceof String) { NonNullList<ItemStack> ores = OreDictionary.getOres(input.toString()); return ores.stream().allMatch(target::apply); } else if (input instanceof ItemStack) { return target.apply((ItemStack) input); } else if (input instanceof NonNullList) { NonNullList<ItemStack> items = (NonNullList<ItemStack>) input; return items.stream().anyMatch(target::apply); } else { throw new IllegalArgumentException("Invalid input: " + input); } }
Example #7
Source File: ShapelessRecipe.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
private boolean matchesInput(ShapelessOreRecipe recipe) { if (recipe.getIngredients().size() != getRecipeSize()) return false; Object[] input = getRecipeInput(); for (int i = 0; i < recipe.getIngredients().size(); i++) { Ingredient target = recipe.getIngredients().get(i); Object source = input[i]; if (!ItemHelper.isSameRecipeInput(target, source)) return false; } return true; }
Example #8
Source File: ItemHelperTests.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Test public void test_isSameRecipeInput() { assertTrue(ItemHelper.isSameRecipeInput(new OreIngredient("stickWood"), "stickWood")); assertFalse(ItemHelper.isSameRecipeInput(new OreIngredient("stickWood"), "oreIron")); assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.APPLE), new ItemStack(Items.APPLE))); assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.APPLE), new ItemStack(Items.DIAMOND_SWORD))); NonNullList<ItemStack> stickWoodList = OreDictionary.getOres("stickWood"); ItemStack[] stickWood = stickWoodList.toArray(new ItemStack[0]); assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), stickWoodList)); assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), OreDictionary.getOres("ingotIron"))); assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), new ItemStack(Items.STICK))); assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.STICK), stickWoodList)); assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), new ItemStack(Items.DIAMOND_PICKAXE))); }
Example #9
Source File: FluidRecipeJEI.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@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()); }
Example #10
Source File: ShapelessRecipe.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
private boolean matchesInput(ShapelessRecipes recipe) { if (isOreRecipe()) return false; if (recipe.recipeItems.size() != getRecipeSize()) return false; Object[] input = getRecipeInput(); for (int i = 0; i < recipe.recipeItems.size(); i++) { Ingredient target = recipe.recipeItems.get(i); ItemStack source = (ItemStack) input[i]; if (!target.apply(source)) return false; } return true; }
Example #11
Source File: ChoppingRecipe.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public ChoppingRecipe read(ResourceLocation recipeId, JsonObject json) { String group = JSONUtils.getString(json, "group", ""); JsonElement jsonelement = JSONUtils.isJsonArray(json, "ingredient") ? JSONUtils.getJsonArray(json, "ingredient") : JSONUtils.getJsonObject(json, "ingredient"); Ingredient ingredient = Ingredient.deserialize(jsonelement); String s1 = JSONUtils.getString(json, "result"); ResourceLocation resourcelocation = new ResourceLocation(s1); ItemStack itemstack = new ItemStack(Optional.ofNullable(ForgeRegistries.ITEMS.getValue(resourcelocation)).orElseThrow(() -> new IllegalStateException("Item: " + s1 + " does not exist"))); double outputMultiplier = JSONUtils.getFloat(json, "output_multiplier", 1.0f); double hitCountMultiplier = JSONUtils.getFloat(json, "hit_count_multiplier", 1.0f); int maxOutput = JSONUtils.getInt(json, "max_output", 0); int sawingTime = JSONUtils.getInt(json, "sawing_time", 200); return new ChoppingRecipe(recipeId, group, ingredient, itemstack, outputMultiplier, hitCountMultiplier, maxOutput, sawingTime); }
Example #12
Source File: RecipeShapedFluid.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Override public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) { NonNullList<ItemStack> remains = ForgeHooks.defaultRecipeGetRemainingItems(inv); for (int i = 0; i < height * width; i++) { ItemStack stack = inv.getStackInSlot(i); NonNullList<Ingredient> matchedIngredients = this.input; if (matchedIngredients.get(i) instanceof IngredientFluidStack) { if (!stack.isEmpty()) { ItemStack copy = stack.copy(); copy.setCount(1); remains.set(i, copy); } IFluidHandlerItem handler = FluidUtil.getFluidHandler(remains.get(i)); if (handler != null) { FluidStack fluid = ((IngredientFluidStack) matchedIngredients.get(i)).getFluid(); handler.drain(fluid.amount, true); remains.set(i, handler.getContainer()); } } } return remains; }
Example #13
Source File: ChoppingRecipe.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ChoppingRecipe(ResourceLocation id, String group, Ingredient input, ItemStack output, double outputMultiplier, double hitCountMultiplier, int maxOutput, int sawingTime) { this.id = id; this.group = group; this.input = input; this.output = output; this.outputMultiplier = outputMultiplier; this.hitCountMultiplier = hitCountMultiplier; this.maxOutput = maxOutput; this.sawingTime = sawingTime; }
Example #14
Source File: ShapedRecipe.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
private boolean isSameInputs(NonNullList<Ingredient> targetInput) { Object[] sourceInput = getRecipeInput(); for (int i = 0; i < targetInput.size(); i++) { Ingredient target = targetInput.get(i); Object source = sourceInput[i]; if (!ItemHelper.isSameRecipeInput(target, source)) return false; } return true; }
Example #15
Source File: ReColourRecipe.java From EnderStorage with MIT License | 5 votes |
@Override public ReColourRecipe read(ResourceLocation recipeId, JsonObject json) { String group = JSONUtils.getString(json, "group", ""); ItemStack result = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "result")); Ingredient ingredient; JsonElement ing = json.get("ingredient"); if (ing != null) { ingredient = Ingredient.deserialize(ing); } else { ingredient = Ingredient.fromStacks(result); } return new ReColourRecipe(recipeId, group, result, ingredient); }
Example #16
Source File: ConfigToggledIngredientSerializer.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected ConfigToggledIngredient(String categoryName, String keyName, Ingredient then, Ingredient other) { super(Stream.empty()); this.categoryName = categoryName; this.keyName = keyName; this.then = then; this.other = other; }
Example #17
Source File: FireRecipeJEI.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void getIngredients(@Nonnull IIngredients ingredients) { List<ItemStack> stacks = Lists.newArrayList(); stacks.addAll(Arrays.asList(input.getMatchingStacks())); List<List<ItemStack>> lists = Lists.newArrayList(); lists.add(stacks); stacks.removeIf(Ingredient.fromStacks(recipe.getOutput())::apply); ingredients.setInputLists(ItemStack.class, lists); ingredients.setOutput(ItemStack.class, recipe.getOutput()); }
Example #18
Source File: EntityBurnableItem.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void setItem(@Nonnull ItemStack stack) { super.setItem(stack); Map.Entry<Ingredient, FireRecipe> recipeEntry = FireRecipes.RECIPES.entrySet().stream() .filter(item -> item.getKey().apply(stack) && !Ingredient.fromStacks(item.getValue().output).apply(stack)) .findFirst().orElse(null); if (recipeEntry != null) recipe = recipeEntry.getValue(); else recipe = null; }
Example #19
Source File: IngredientFluidStackFactory.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Nonnull @Override public Ingredient parse(JsonContext context, JsonObject json) { String name = JsonUtils.getString(json, "fluid"); int amount = JsonUtils.getInt(json, "amount", 1000); Fluid fluid = FluidRegistry.getFluid(name); if (fluid == null) throw new JsonSyntaxException("Fluid with name " + name + " could not be found"); return new IngredientFluidStack(fluid, amount); }
Example #20
Source File: RecipeShapelessFluidFactory.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public IRecipe parse(JsonContext context, JsonObject json) { String group = JsonUtils.getString(json, "group", ""); NonNullList<Ingredient> ingredients = NonNullList.create(); for (JsonElement element : JsonUtils.getJsonArray(json, "ingredients")) ingredients.add(CraftingHelper.getIngredient(element, context)); if (ingredients.isEmpty()) throw new JsonParseException("No ingredients in shapeless recipe"); ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); RecipeShapelessFluid recipe = new RecipeShapelessFluid(group.isEmpty() ? null : new ResourceLocation(group), result, ingredients); return recipe; }
Example #21
Source File: RecipeUtils.java From OpenModsLib with MIT License | 5 votes |
public static ItemStack[][] getFullRecipeInput(IRecipe recipe) { final NonNullList<Ingredient> ingredients = recipe.getIngredients(); final int ingredientCount = ingredients.size(); final ItemStack[][] result = new ItemStack[ingredientCount][]; for (int i = 0; i < ingredientCount; i++) result[i] = ingredients.get(i).getMatchingStacks(); return result; }
Example #22
Source File: DryingRecipe.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public DryingRecipe read(ResourceLocation recipeId, JsonObject json) { String group = JSONUtils.getString(json, "group", ""); JsonElement jsonelement = JSONUtils.isJsonArray(json, "ingredient") ? JSONUtils.getJsonArray(json, "ingredient") : JSONUtils.getJsonObject(json, "ingredient"); Ingredient ingredient = Ingredient.deserialize(jsonelement); String s1 = JSONUtils.getString(json, "result"); ResourceLocation resourcelocation = new ResourceLocation(s1); ItemStack itemstack = new ItemStack(Optional.ofNullable(ForgeRegistries.ITEMS.getValue(resourcelocation)).orElseThrow(() -> new IllegalStateException("Item: " + s1 + " does not exist"))); int dryingTime = JSONUtils.getInt(json, "dryingTime", 200); return new DryingRecipe(recipeId, group, ingredient, itemstack, dryingTime); }
Example #23
Source File: ConfigToggledIngredientSerializer.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Ingredient parse(JsonObject json) { String categoryName = JSONUtils.getString(json, "category"); String keyName = JSONUtils.getString(json, "key"); return new ConfigToggledIngredient( categoryName, keyName, CraftingHelper.getIngredient(json.getAsJsonObject("then")), CraftingHelper.getIngredient(json.getAsJsonObject("else")) ); }
Example #24
Source File: CreateRecipe.java From EnderStorage with MIT License | 5 votes |
@Override public void write(PacketBuffer buffer, CreateRecipe recipe) { buffer.writeString(recipe.group); for (Ingredient ingredient : recipe.input) { ingredient.write(buffer); } buffer.writeItemStack(recipe.output); }
Example #25
Source File: CreateRecipe.java From EnderStorage with MIT License | 5 votes |
@Nullable @Override public CreateRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { String s = buffer.readString(32767); NonNullList<Ingredient> ingredients = NonNullList.withSize(3 * 3, Ingredient.EMPTY); for (int k = 0; k < ingredients.size(); ++k) { ingredients.set(k, Ingredient.read(buffer)); } ItemStack result = buffer.readItemStack(); return new CreateRecipe(recipeId, s, result, ingredients); }
Example #26
Source File: CreateRecipe.java From EnderStorage with MIT License | 5 votes |
@Override public CreateRecipe read(ResourceLocation recipeId, JsonObject json) { String group = JSONUtils.getString(json, "group", ""); Map<String, Ingredient> key = ShapedRecipe.deserializeKey(JSONUtils.getJsonObject(json, "key")); String[] pattern = ShapedRecipe.shrink(ShapedRecipe.patternFromJson(JSONUtils.getJsonArray(json, "pattern"))); int width = pattern[0].length(); int height = pattern.length; NonNullList<Ingredient> ingredients = ShapedRecipe.deserializeIngredients(pattern, key, width, height); ItemStack result = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "result")); return new CreateRecipe(recipeId, group, result, ingredients); }
Example #27
Source File: BlockFluidLethe.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@SubscribeEvent public static void onEntityUpdate(EntityUpdateEvent event) { Entity entityIn = event.getEntity(); BlockPos pos = entityIn.getPosition(); World world = entityIn.world; IBlockState state = world.getBlockState(pos); // if (state.getBlock() == ModFluids.LETHE.getActualBlock()) { // // run(world, pos, state.getBlock(), entityIn, // entity -> entity instanceof EntityPlayer, // entity -> { // EntityPlayer player = (EntityPlayer) entity; // if (player.experienceLevel > 0) // CapManager.forObject(player).addMana(expToNextLevel(--player.experienceLevel)); // }); // // } run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ManaRecipes.RECIPES.keySet().stream().anyMatch(item -> item.apply(((EntityItem) entity).getItem())), entity -> { List<Map.Entry<Ingredient, FluidRecipeLoader.FluidCrafter>> allEntries = ManaRecipes.RECIPES.entries().stream().filter(entry -> entry.getValue().getFluid().getBlock() == state.getBlock() && entry.getKey().apply(((EntityItem) entity).getItem())).collect(Collectors.toList()); allEntries.forEach(crafter -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), crafter.getValue().build())); }); }
Example #28
Source File: Potions.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
public static void initRecipes() { PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromItem(Items.EMERALD), TQPotionTypes.ROYALTY); PotionHelper.addMix(TQPotionTypes.ROYALTY, Ingredient.fromItem(Items.REDSTONE), TQPotionTypes.ROYALTY_LONG); PotionHelper.addMix(TQPotionTypes.ROYALTY, Ingredient.fromItem(Items.GLOWSTONE_DUST), TQPotionTypes.ROYALTY_STRONG); PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromItem(Items.DIAMOND), TQPotionTypes.LOYALTY); PotionHelper.addMix(TQPotionTypes.LOYALTY, Ingredient.fromItem(Items.REDSTONE), TQPotionTypes.LOYALTY_LONG); PotionHelper.addMix(TQPotionTypes.LOYALTY, Ingredient.fromItem(Items.GLOWSTONE_DUST), TQPotionTypes.LOYALTY_STRONG); }
Example #29
Source File: DryingRecipe.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public DryingRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { String group = buffer.readString(32767); Ingredient ingredient = Ingredient.read(buffer); ItemStack itemstack = buffer.readItemStack(); int dryingTime = buffer.readVarInt(); return new DryingRecipe(recipeId, group, ingredient, itemstack, dryingTime); }
Example #30
Source File: Potions.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public void registerPotions(IForgeRegistry<PotionType> reg) { // wither potion Ingredient redstone = Ingredient.fromItem(Items.REDSTONE); Ingredient glowstone = Ingredient.fromItem(Items.GLOWSTONE_DUST); // Wither reg.register(withering); reg.register(witheringLong); Ingredient witheringDust = Ingredient.fromItem(EnderZoo.itemWitheringDust); registerPotionTypeConversion(PotionTypes.AWKWARD, witheringDust, withering); registerPotionTypeConversion(withering, redstone, witheringLong); // Confusion reg.register(confusion); reg.register(confusionLong); Ingredient confusionDust = Ingredient.fromItem(EnderZoo.itemConfusingDust); registerPotionTypeConversion(PotionTypes.AWKWARD, confusionDust, confusion); registerPotionTypeConversion(confusion, redstone, confusionLong); // Rising if (Config.floatingPotionEnabled) { reg.register(floating); reg.register(floatingLong); reg.register(floatingTwo); Ingredient owlEgg = Ingredient.fromItem(EnderZoo.itemOwlEgg); registerPotionTypeConversion(PotionTypes.AWKWARD, owlEgg, floating); registerPotionTypeConversion(floating, redstone, floatingLong); registerPotionTypeConversion(floating, glowstone, floatingTwo); } }