Search in sources :

Example 11 with ItemStackIngredient

use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.

the class SawmillRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ItemStackIngredient inputIngredient = ItemStackIngredient.read(buffer);
        ItemStack mainOutput = buffer.readItem();
        ItemStack secondaryOutput = buffer.readItem();
        double secondaryChance = buffer.readDouble();
        return this.factory.create(recipeId, inputIngredient, mainOutput, secondaryOutput, secondaryChance);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading sawmill recipe from packet.", e);
        throw e;
    }
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) ItemStack(net.minecraft.item.ItemStack) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Example 12 with ItemStackIngredient

use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.

the class BYGRecipeProvider method dye.

private void dye(Consumer<IFinishedRecipe> consumer, String basePath, IItemProvider output, boolean large, EnumColor color, String inputTag, IItemProvider... extraInputs) {
    ItemStackIngredient inputIngredient = ItemStackIngredient.from(BaseRecipeProvider.createIngredient(tag(inputTag), extraInputs));
    String name = large ? "large_" + color.getRegistryPrefix() : color.getRegistryPrefix();
    ItemStackToItemStackRecipeBuilder.enriching(inputIngredient, new ItemStack(output, large ? 4 : 2)).addCondition(modLoaded).build(consumer, Mekanism.rl(basePath + "dye/" + name));
    // Flowers -> 4x dye output (See PigmentExtractingRecipeProvider#addFlowerExtractionRecipes for note)
    long flowerRate = 3 * PigmentExtractingRecipeProvider.DYE_RATE;
    ItemStackToChemicalRecipeBuilder.pigmentExtracting(inputIngredient, MekanismPigments.PIGMENT_COLOR_LOOKUP.get(color).getStack(large ? 2 * flowerRate : flowerRate)).addCondition(modLoaded).build(consumer, Mekanism.rl(basePath + "pigment_extracting/" + name));
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) ItemStack(net.minecraft.item.ItemStack)

Example 13 with ItemStackIngredient

use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.

the class ILikeWoodRecipeProvider method addWoodType.

// TODO: Maybe move some of these into RecipeProviderUtil, so that we make sure the numbers stay consistent
public static void addWoodType(Consumer<IFinishedRecipe> consumer, ICondition condition, String basePath, IItemProvider planks, IItemProvider log, IItemProvider fences, IWoodType woodType, ICondition bedVersion, ICondition soulTorchVersion) {
    String name = woodType.getName();
    Item stick = ILikeWood.getItem(woodType, WoodenItemType.STICK);
    // Barrel
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.BARREL)), new ItemStack(planks, 7)).addCondition(condition).build(consumer, Mekanism.rl(basePath + "barrel/" + name));
    // Chest
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.CHEST)), new ItemStack(planks, 8)).addCondition(condition).build(consumer, Mekanism.rl(basePath + "chest/" + name));
    // Composter
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.COMPOSTER)), new ItemStack(planks, 3), new ItemStack(fences, 4), 1).addCondition(condition).build(consumer, Mekanism.rl(basePath + "composter/" + name));
    // Crafting table
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.CRAFTING_TABLE)), new ItemStack(planks, 4)).addCondition(condition).build(consumer, Mekanism.rl(basePath + "crafting_table/" + name));
    // Item Frame
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getItem(woodType, WoodenItemType.ITEM_FRAME)), new ItemStack(stick, 8), new ItemStack(Items.LEATHER), 1).addCondition(condition).build(consumer, Mekanism.rl(basePath + "item_frame/" + name));
    // Ladder
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.LADDER), 3), new ItemStack(stick, 7)).addCondition(condition).build(consumer, Mekanism.rl(basePath + "ladder/" + name));
    // Lectern
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.LECTERN)), new ItemStack(planks, 8), new ItemStack(Items.BOOK, 3), 1).addCondition(condition).build(consumer, Mekanism.rl(basePath + "lectern/" + name));
    // Panel
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.PANELS)), new ItemStack(stick, 6), MekanismItems.SAWDUST.getItemStack(), 0.25).addCondition(condition).build(consumer, Mekanism.rl(basePath + "panel/" + name));
    // Post
    ItemStackIngredient postIngredient;
    if (woodType.getBlockTypes().contains(WoodenBlockType.STRIPPED_POST)) {
        postIngredient = ItemStackIngredient.from(Ingredient.of(ILikeWood.getBlock(woodType, WoodenBlockType.POST), ILikeWood.getBlock(woodType, WoodenBlockType.STRIPPED_POST)));
    } else {
        postIngredient = ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.POST));
    }
    SawmillRecipeBuilder.sawing(postIngredient, new ItemStack(planks, 3), MekanismItems.SAWDUST.getItemStack(), 0.125).addCondition(condition).build(consumer, Mekanism.rl(basePath + "post/" + name));
    // Torch
    Block torch = ILikeWood.getBlock(woodType, WoodenBlockType.TORCH);
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(torch, 4), new ItemStack(stick), new ItemStack(Items.COAL), 1).addCondition(condition).build(consumer, Mekanism.rl(basePath + "torch/" + name));
    // Soul Torch
    SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.SOUL_TORCH), 4), new ItemStack(torch, 4), new ItemStack(Blocks.SOUL_SOIL), 1).addCondition(soulTorchVersion).build(consumer, Mekanism.rl(basePath + "soul_torch/" + name));
    // Wall
    if (woodType.getBlockTypes().contains(WoodenBlockType.WALL)) {
        SawmillRecipeBuilder.sawing(ItemStackIngredient.from(ILikeWood.getBlock(woodType, WoodenBlockType.WALL)), new ItemStack(log)).addCondition(condition).build(consumer, Mekanism.rl(basePath + "wall/" + name));
    }
    // Beds
    addBedRecipes(consumer, bedVersion, planks, woodType, basePath + "bed/" + name + "/");
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 14 with ItemStackIngredient

use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.

the class MekanismRecipeHandler method convertIngredient.

private String convertIngredient(ItemStackIngredient ingredient) {
    if (ingredient instanceof ItemStackIngredient.Single) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        Ingredient vanillaIngredient = ((ItemStackIngredient.Single) ingredient).getInputRaw();
        int amount = JSONUtils.getAsInt(serialized, JsonConstants.AMOUNT, 1);
        String rep = basicImplicitIngredient(vanillaIngredient, amount, serialized.get(JsonConstants.INGREDIENT));
        if (rep == null) {
            rep = IIngredient.fromIngredient(vanillaIngredient).getCommandString();
            if (amount > 1) {
                return CrTConstants.CLASS_ITEM_STACK_INGREDIENT + ".from(" + rep + ", " + amount + ")";
            }
        }
        // Note: Handled via implicit casts
        return rep;
    } else if (ingredient instanceof ItemStackIngredient.Multi) {
        ItemStackIngredient.Multi multiIngredient = (ItemStackIngredient.Multi) ingredient;
        StringBuilder builder = new StringBuilder(CrTConstants.CLASS_ITEM_STACK_INGREDIENT + ".createMulti(");
        multiIngredient.forEachIngredient(i -> {
            builder.append(convertIngredient(i)).append(", ");
            return false;
        });
        // Remove trailing comma and space
        builder.setLength(builder.length() - 2);
        builder.append(")");
        return builder.toString();
    }
    // Shouldn't happen
    return "Unimplemented itemstack ingredient: " + ingredient;
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) JSONUtils(net.minecraft.util.JSONUtils) JsonObject(com.google.gson.JsonObject) IRecipeHandler(com.blamejared.crafttweaker.api.recipes.IRecipeHandler) ChemicalStack(mekanism.api.chemical.ChemicalStack) Item(net.minecraft.item.Item) ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) JsonConstants(mekanism.api.JsonConstants) InputIngredient(mekanism.api.recipes.inputs.InputIngredient) CrTGasStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTGasStack) MekanismRecipe(mekanism.api.recipes.MekanismRecipe) Chemical(mekanism.api.chemical.Chemical) GasStack(mekanism.api.chemical.gas.GasStack) IIngredient(com.blamejared.crafttweaker.api.item.IIngredient) IRecipeManager(com.blamejared.crafttweaker.api.managers.IRecipeManager) TagManagerItem(com.blamejared.crafttweaker.impl.tag.manager.TagManagerItem) CrTChemicalTagManager(mekanism.common.integration.crafttweaker.tag.CrTChemicalTagManager) NBTIngredient(net.minecraftforge.common.crafting.NBTIngredient) PigmentStackIngredient(mekanism.api.recipes.inputs.chemical.PigmentStackIngredient) CrTInfusionStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTInfusionStack) List(java.util.List) SlurryStackIngredient(mekanism.api.recipes.inputs.chemical.SlurryStackIngredient) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) FluidStack(net.minecraftforge.fluids.FluidStack) MCTag(com.blamejared.crafttweaker.impl.tag.MCTag) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) InfusionStackIngredient(mekanism.api.recipes.inputs.chemical.InfusionStackIngredient) CrTPigmentTagManager(mekanism.common.integration.crafttweaker.tag.CrTPigmentTagManager) Ingredient(net.minecraft.item.crafting.Ingredient) TagManagerFluid(com.blamejared.crafttweaker.impl.tag.manager.TagManagerFluid) ChemicalType(mekanism.api.chemical.ChemicalType) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) JsonElement(com.google.gson.JsonElement) ItemStack(net.minecraft.item.ItemStack) FloatingLong(mekanism.api.math.FloatingLong) CrTGasTagManager(mekanism.common.integration.crafttweaker.tag.CrTGasTagManager) ChemicalIngredientDeserializer(mekanism.api.recipes.inputs.chemical.ChemicalIngredientDeserializer) CrTInfuseTypeTagManager(mekanism.common.integration.crafttweaker.tag.CrTInfuseTypeTagManager) MCFluidStack(com.blamejared.crafttweaker.impl.fluid.MCFluidStack) Nullable(javax.annotation.Nullable) IRecipe(net.minecraft.item.crafting.IRecipe) CrTSlurryStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTSlurryStack) CrTSlurryTagManager(mekanism.common.integration.crafttweaker.tag.CrTSlurryTagManager) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient) CrTConstants(mekanism.common.integration.crafttweaker.CrTConstants) CrTPigmentStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTPigmentStack) ItemStackHelper(com.blamejared.crafttweaker.impl.helper.ItemStackHelper) SerializerHelper(mekanism.api.SerializerHelper) ResourceLocation(net.minecraft.util.ResourceLocation) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack) ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) InputIngredient(mekanism.api.recipes.inputs.InputIngredient) IIngredient(com.blamejared.crafttweaker.api.item.IIngredient) NBTIngredient(net.minecraftforge.common.crafting.NBTIngredient) PigmentStackIngredient(mekanism.api.recipes.inputs.chemical.PigmentStackIngredient) SlurryStackIngredient(mekanism.api.recipes.inputs.chemical.SlurryStackIngredient) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) InfusionStackIngredient(mekanism.api.recipes.inputs.chemical.InfusionStackIngredient) Ingredient(net.minecraft.item.crafting.Ingredient) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient) JsonObject(com.google.gson.JsonObject)

Example 15 with ItemStackIngredient

use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.

the class CrTItemStackIngredient method from.

/**
 * Creates a {@link ItemStackIngredient} that matches a given ingredient and amount.
 *
 * @param ingredient Ingredient to match
 * @param amount     Amount needed
 *
 * @return A {@link ItemStackIngredient} that matches a given ingredient and amount.
 */
@ZenCodeType.StaticExpansionMethod
public static ItemStackIngredient from(IIngredient ingredient, int amount) {
    CrTIngredientHelper.assertValidAmount("ItemStackIngredients", amount);
    // Note: the IIngredient cases also handle item tags/item stacks
    Ingredient vanillaIngredient = ingredient.asVanillaIngredient();
    if (vanillaIngredient == Ingredient.EMPTY) {
        throw new IllegalArgumentException("ItemStackIngredients cannot be made using the empty ingredient: " + amount);
    }
    return ItemStackIngredient.from(vanillaIngredient, amount);
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) IIngredient(com.blamejared.crafttweaker.api.item.IIngredient)

Aggregations

ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)26 ItemStack (net.minecraft.item.ItemStack)19 JsonSyntaxException (com.google.gson.JsonSyntaxException)18 JsonElement (com.google.gson.JsonElement)10 Nonnull (javax.annotation.Nonnull)10 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)8 FloatingLong (mekanism.api.math.FloatingLong)5 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)4 Ingredient (net.minecraft.item.crafting.Ingredient)4 IIngredient (com.blamejared.crafttweaker.api.item.IIngredient)3 GasStack (mekanism.api.chemical.gas.GasStack)3 Item (net.minecraft.item.Item)3 JsonObject (com.google.gson.JsonObject)2 ChemicalType (mekanism.api.chemical.ChemicalType)2 ChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)2 IChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient)2 InfusionStackIngredient (mekanism.api.recipes.inputs.chemical.InfusionStackIngredient)2 PigmentStackIngredient (mekanism.api.recipes.inputs.chemical.PigmentStackIngredient)2 SlurryStackIngredient (mekanism.api.recipes.inputs.chemical.SlurryStackIngredient)2 ResourceLocation (net.minecraft.util.ResourceLocation)2