Search in sources :

Example 6 with FluidIngredient

use of com.simibubi.create.foundation.fluid.FluidIngredient in project Create by Creators-of-Create.

the class BasinCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, BasinRecipe recipe, IIngredients iingredients) {
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    IGuiFluidStackGroup fluidStacks = recipeLayout.getFluidStacks();
    NonNullList<FluidIngredient> fluidIngredients = recipe.getFluidIngredients();
    List<Pair<Ingredient, MutableInt>> ingredients = ItemHelper.condenseIngredients(recipe.getIngredients());
    List<ItemStack> itemOutputs = recipe.getRollableResultsAsItemStacks();
    NonNullList<FluidStack> fluidOutputs = recipe.getFluidResults();
    int size = ingredients.size() + fluidIngredients.size();
    int xOffset = size < 3 ? (3 - size) * 19 / 2 : 0;
    int yOffset = 0;
    int i;
    for (i = 0; i < ingredients.size(); i++) {
        itemStacks.init(i, true, 16 + xOffset + (i % 3) * 19, 50 - (i / 3) * 19 + yOffset);
        List<ItemStack> stacks = new ArrayList<>();
        Pair<Ingredient, MutableInt> pair = ingredients.get(i);
        Ingredient ingredient = pair.getFirst();
        MutableInt amount = pair.getSecond();
        for (ItemStack itemStack : ingredient.getItems()) {
            ItemStack stack = itemStack.copy();
            stack.setCount(amount.getValue());
            stacks.add(stack);
        }
        itemStacks.set(i, stacks);
    }
    int j;
    for (j = 0; j < fluidIngredients.size(); j++) {
        int i2 = i + j;
        fluidStacks.init(j, true, 17 + xOffset + (i2 % 3) * 19, 51 - (i2 / 3) * 19 + yOffset);
        List<FluidStack> stacks = fluidIngredients.get(j).getMatchingFluidStacks();
        fluidStacks.set(j, withImprovedVisibility(stacks));
    }
    int outSize = fluidOutputs.size() + recipe.getRollableResults().size();
    int outputIndex = 0;
    if (!itemOutputs.isEmpty())
        addStochasticTooltip(itemStacks, recipe.getRollableResults(), i);
    for (; outputIndex < outSize; outputIndex++) {
        int xPosition = 141 - (outSize % 2 != 0 && outputIndex == outSize - 1 ? 0 : outputIndex % 2 == 0 ? 10 : -9);
        int yPosition = -19 * (outputIndex / 2) + 50 + yOffset;
        if (itemOutputs.size() > outputIndex) {
            itemStacks.init(i, false, xPosition, yPosition + yOffset);
            itemStacks.set(i, itemOutputs.get(outputIndex));
            i++;
        } else {
            fluidStacks.init(j, false, xPosition + 1, yPosition + 1 + yOffset);
            fluidStacks.set(j, withImprovedVisibility(fluidOutputs.get(outputIndex - itemOutputs.size())));
            j++;
        }
    }
    addFluidTooltip(fluidStacks, fluidIngredients, fluidOutputs);
    HeatCondition requiredHeat = recipe.getRequiredHeat();
    if (!requiredHeat.testBlazeBurner(HeatLevel.NONE)) {
        itemStacks.init(i, true, 133, 80);
        itemStacks.set(i, AllBlocks.BLAZE_BURNER.asStack());
        i++;
    }
    if (!requiredHeat.testBlazeBurner(HeatLevel.KINDLED)) {
        itemStacks.init(i, true, 152, 80);
        itemStacks.set(i, AllItems.BLAZE_CAKE.asStack());
        i++;
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IGuiFluidStackGroup(mezz.jei.api.gui.ingredient.IGuiFluidStackGroup) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) ArrayList(java.util.ArrayList) HeatCondition(com.simibubi.create.content.contraptions.processing.HeatCondition) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) Ingredient(net.minecraft.world.item.crafting.Ingredient) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) MutableInt(org.apache.commons.lang3.mutable.MutableInt) ItemStack(net.minecraft.world.item.ItemStack) Pair(com.simibubi.create.foundation.utility.Pair)

Example 7 with FluidIngredient

use of com.simibubi.create.foundation.fluid.FluidIngredient in project Create by Creators-of-Create.

the class SpoutCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, FillingRecipe recipe, IIngredients ingredients) {
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    IGuiFluidStackGroup fluidStacks = recipeLayout.getFluidStacks();
    FluidIngredient fluidIngredient = recipe.getRequiredFluid();
    List<ItemStack> matchingIngredients = Arrays.asList(recipe.getIngredients().get(0).getItems());
    fluidStacks.init(0, true, 27, 32);
    fluidStacks.set(0, withImprovedVisibility(fluidIngredient.getMatchingFluidStacks()));
    itemStacks.init(0, true, 26, 50);
    itemStacks.set(0, matchingIngredients);
    itemStacks.init(1, false, 131, 50);
    itemStacks.set(1, recipe.getResultItem());
    addFluidTooltip(fluidStacks, ImmutableList.of(fluidIngredient), Collections.emptyList());
}
Also used : FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) IGuiFluidStackGroup(mezz.jei.api.gui.ingredient.IGuiFluidStackGroup) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) ItemStack(net.minecraft.world.item.ItemStack)

Example 8 with FluidIngredient

use of com.simibubi.create.foundation.fluid.FluidIngredient in project Create by Creators-of-Create.

the class ProcessingRecipeSerializer method readFromJson.

protected T readFromJson(ResourceLocation recipeId, JsonObject json) {
    ProcessingRecipeBuilder<T> builder = new ProcessingRecipeBuilder<>(factory, recipeId);
    NonNullList<Ingredient> ingredients = NonNullList.create();
    NonNullList<FluidIngredient> fluidIngredients = NonNullList.create();
    NonNullList<ProcessingOutput> results = NonNullList.create();
    NonNullList<FluidStack> fluidResults = NonNullList.create();
    for (JsonElement je : GsonHelper.getAsJsonArray(json, "ingredients")) {
        if (FluidIngredient.isFluidIngredient(je))
            fluidIngredients.add(FluidIngredient.deserialize(je));
        else
            ingredients.add(Ingredient.fromJson(je));
    }
    for (JsonElement je : GsonHelper.getAsJsonArray(json, "results")) {
        JsonObject jsonObject = je.getAsJsonObject();
        if (GsonHelper.isValidNode(jsonObject, "fluid"))
            fluidResults.add(FluidHelper.deserializeFluidStack(jsonObject));
        else
            results.add(ProcessingOutput.deserialize(je));
    }
    builder.withItemIngredients(ingredients).withItemOutputs(results).withFluidIngredients(fluidIngredients).withFluidOutputs(fluidResults);
    if (GsonHelper.isValidNode(json, "processingTime"))
        builder.duration(GsonHelper.getAsInt(json, "processingTime"));
    if (GsonHelper.isValidNode(json, "heatRequirement"))
        builder.requiresHeat(HeatCondition.deserialize(GsonHelper.getAsString(json, "heatRequirement")));
    T recipe = builder.build();
    recipe.readAdditional(json);
    return recipe;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) JsonObject(com.google.gson.JsonObject) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) Ingredient(net.minecraft.world.item.crafting.Ingredient) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) JsonElement(com.google.gson.JsonElement)

Example 9 with FluidIngredient

use of com.simibubi.create.foundation.fluid.FluidIngredient in project Create by Creators-of-Create.

the class FillingBySpout method fillItem.

public static ItemStack fillItem(Level world, int requiredAmount, ItemStack stack, FluidStack availableFluid) {
    FluidStack toFill = availableFluid.copy();
    toFill.setAmount(requiredAmount);
    wrapper.setItem(0, stack);
    FillingRecipe fillingRecipe = SequencedAssemblyRecipe.getRecipe(world, wrapper, AllRecipeTypes.FILLING.getType(), FillingRecipe.class).filter(fr -> fr.getRequiredFluid().test(toFill)).orElseGet(() -> {
        for (Recipe<RecipeWrapper> recipe : world.getRecipeManager().getRecipesFor(AllRecipeTypes.FILLING.getType(), wrapper, world)) {
            FillingRecipe fr = (FillingRecipe) recipe;
            FluidIngredient requiredFluid = fr.getRequiredFluid();
            if (requiredFluid.test(toFill))
                return fr;
        }
        return null;
    });
    if (fillingRecipe != null) {
        List<ItemStack> results = fillingRecipe.rollResults();
        availableFluid.shrink(requiredAmount);
        stack.shrink(1);
        return results.isEmpty() ? ItemStack.EMPTY : results.get(0);
    }
    return GenericItemFilling.fillItem(world, requiredAmount, stack, availableFluid);
}
Also used : List(java.util.List) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) Recipe(net.minecraft.world.item.crafting.Recipe) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) AllRecipeTypes(com.simibubi.create.AllRecipeTypes) Optional(java.util.Optional) FluidStack(net.minecraftforge.fluids.FluidStack) SequencedAssemblyRecipe(com.simibubi.create.content.contraptions.itemAssembly.SequencedAssemblyRecipe) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) RecipeWrapper(net.minecraftforge.items.wrapper.RecipeWrapper) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack) RecipeWrapper(net.minecraftforge.items.wrapper.RecipeWrapper)

Example 10 with FluidIngredient

use of com.simibubi.create.foundation.fluid.FluidIngredient in project Create by Creators-of-Create.

the class FillingBySpout method getRequiredAmountForItem.

public static int getRequiredAmountForItem(Level world, ItemStack stack, FluidStack availableFluid) {
    wrapper.setItem(0, stack);
    Optional<FillingRecipe> assemblyRecipe = SequencedAssemblyRecipe.getRecipe(world, wrapper, AllRecipeTypes.FILLING.getType(), FillingRecipe.class);
    if (assemblyRecipe.isPresent()) {
        FluidIngredient requiredFluid = assemblyRecipe.get().getRequiredFluid();
        if (requiredFluid.test(availableFluid))
            return requiredFluid.getRequiredAmount();
    }
    for (Recipe<RecipeWrapper> recipe : world.getRecipeManager().getRecipesFor(AllRecipeTypes.FILLING.getType(), wrapper, world)) {
        FillingRecipe fillingRecipe = (FillingRecipe) recipe;
        FluidIngredient requiredFluid = fillingRecipe.getRequiredFluid();
        if (requiredFluid.test(availableFluid))
            return requiredFluid.getRequiredAmount();
    }
    return GenericItemFilling.getRequiredAmountForItem(world, stack, availableFluid);
}
Also used : FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) RecipeWrapper(net.minecraftforge.items.wrapper.RecipeWrapper)

Aggregations

FluidIngredient (com.simibubi.create.foundation.fluid.FluidIngredient)10 ItemStack (net.minecraft.world.item.ItemStack)5 Ingredient (net.minecraft.world.item.crafting.Ingredient)5 FluidStack (net.minecraftforge.fluids.FluidStack)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 IGuiFluidStackGroup (mezz.jei.api.gui.ingredient.IGuiFluidStackGroup)3 AllRecipeTypes (com.simibubi.create.AllRecipeTypes)2 HeatCondition (com.simibubi.create.content.contraptions.processing.HeatCondition)2 IGuiItemStackGroup (mezz.jei.api.gui.ingredient.IGuiItemStackGroup)2 Recipe (net.minecraft.world.item.crafting.Recipe)2 Level (net.minecraft.world.level.Level)2 RecipeWrapper (net.minecraftforge.items.wrapper.RecipeWrapper)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 CABlocks (com.mrh0.createaddition.index.CABlocks)1 CrudeBurningRecipe (com.mrh0.createaddition.recipe.crude_burning.CrudeBurningRecipe)1 SequencedAssemblyRecipe (com.simibubi.create.content.contraptions.itemAssembly.SequencedAssemblyRecipe)1 ProcessingRecipeParams (com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeParams)1