Search in sources :

Example 1 with FluidIngredient

use of com.simibubi.create.foundation.fluid.FluidIngredient in project createaddition by mrh0.

the class CrudeBurningCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, CrudeBurningRecipe recipe, IIngredients ingredients) {
    IGuiFluidStackGroup fluidStacks = recipeLayout.getFluidStacks();
    NonNullList<FluidIngredient> fluidIngredients = NonNullList.of(recipe.getFluidIngredient());
    List<FluidStack> out = new ArrayList<FluidStack>();
    fluidStacks.init(0, true, 81, 7);
    fluidStacks.set(0, withImprovedVisibility(recipe.getFluidIngredient().getMatchingFluidStacks().stream().map(fluid -> {
        out.add(fluid);
        return fluid;
    }).collect(Collectors.toList())));
    addFluidTooltip(fluidStacks, fluidIngredients, out);
}
Also used : IGuiFluidStackGroup(mezz.jei.api.gui.ingredient.IGuiFluidStackGroup) IIngredients(mezz.jei.api.ingredients.IIngredients) Collectors(java.util.stream.Collectors) AllGuiTextures(com.simibubi.create.foundation.gui.AllGuiTextures) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Ingredient(net.minecraft.world.item.crafting.Ingredient) List(java.util.List) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) Minecraft(net.minecraft.client.Minecraft) CrudeBurningRecipe(com.mrh0.createaddition.recipe.crude_burning.CrudeBurningRecipe) NonNullList(net.minecraft.core.NonNullList) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack) VanillaTypes(mezz.jei.api.constants.VanillaTypes) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) CABlocks(com.mrh0.createaddition.index.CABlocks) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) FluidStack(net.minecraftforge.fluids.FluidStack) IGuiFluidStackGroup(mezz.jei.api.gui.ingredient.IGuiFluidStackGroup) ArrayList(java.util.ArrayList)

Example 2 with FluidIngredient

use of com.simibubi.create.foundation.fluid.FluidIngredient in project createaddition by mrh0.

the class CrudeBurningRecipeSerializer method fromNetwork.

@Override
public CrudeBurningRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
    int burnTime = buffer.readInt();
    FluidIngredient fluid = FluidIngredient.read(buffer);
    return new CrudeBurningRecipe(recipeId, fluid, burnTime);
}
Also used : FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient)

Example 3 with FluidIngredient

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

the class BasinRecipe method apply.

private static boolean apply(BasinTileEntity basin, Recipe<?> recipe, boolean test) {
    boolean isBasinRecipe = recipe instanceof BasinRecipe;
    IItemHandler availableItems = basin.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
    IFluidHandler availableFluids = basin.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null);
    if (availableItems == null || availableFluids == null)
        return false;
    HeatLevel heat = BasinTileEntity.getHeatLevelOf(basin.getLevel().getBlockState(basin.getBlockPos().below(1)));
    if (isBasinRecipe && !((BasinRecipe) recipe).getRequiredHeat().testBlazeBurner(heat))
        return false;
    List<ItemStack> recipeOutputItems = new ArrayList<>();
    List<FluidStack> recipeOutputFluids = new ArrayList<>();
    List<Ingredient> ingredients = new LinkedList<>(recipe.getIngredients());
    ingredients.sort(Comparator.comparingInt(i -> i.getItems().length));
    List<FluidIngredient> fluidIngredients = isBasinRecipe ? ((BasinRecipe) recipe).getFluidIngredients() : Collections.emptyList();
    for (boolean simulate : Iterate.trueAndFalse) {
        if (!simulate && test)
            return true;
        int[] extractedItemsFromSlot = new int[availableItems.getSlots()];
        int[] extractedFluidsFromTank = new int[availableFluids.getTanks()];
        Ingredients: for (int i = 0; i < ingredients.size(); i++) {
            Ingredient ingredient = ingredients.get(i);
            for (int slot = 0; slot < availableItems.getSlots(); slot++) {
                if (simulate && availableItems.getStackInSlot(slot).getCount() <= extractedItemsFromSlot[slot])
                    continue;
                ItemStack extracted = availableItems.extractItem(slot, 1, true);
                if (!ingredient.test(extracted))
                    continue;
                // Catalyst items are never consumed
                if (extracted.hasContainerItem() && extracted.getContainerItem().sameItem(extracted))
                    continue Ingredients;
                if (!simulate)
                    availableItems.extractItem(slot, 1, false);
                else if (extracted.hasContainerItem())
                    recipeOutputItems.add(extracted.getContainerItem().copy());
                extractedItemsFromSlot[slot]++;
                continue Ingredients;
            }
            // something wasn't found
            return false;
        }
        boolean fluidsAffected = false;
        FluidIngredients: for (int i = 0; i < fluidIngredients.size(); i++) {
            FluidIngredient fluidIngredient = fluidIngredients.get(i);
            int amountRequired = fluidIngredient.getRequiredAmount();
            for (int tank = 0; tank < availableFluids.getTanks(); tank++) {
                FluidStack fluidStack = availableFluids.getFluidInTank(tank);
                if (simulate && fluidStack.getAmount() <= extractedFluidsFromTank[tank])
                    continue;
                if (!fluidIngredient.test(fluidStack))
                    continue;
                int drainedAmount = Math.min(amountRequired, fluidStack.getAmount());
                if (!simulate) {
                    fluidStack.shrink(drainedAmount);
                    fluidsAffected = true;
                }
                amountRequired -= drainedAmount;
                if (amountRequired != 0)
                    continue;
                extractedFluidsFromTank[tank] += drainedAmount;
                continue FluidIngredients;
            }
            // something wasn't found
            return false;
        }
        if (fluidsAffected) {
            basin.getBehaviour(SmartFluidTankBehaviour.INPUT).forEach(TankSegment::onFluidStackChanged);
            basin.getBehaviour(SmartFluidTankBehaviour.OUTPUT).forEach(TankSegment::onFluidStackChanged);
        }
        if (simulate) {
            if (recipe instanceof BasinRecipe) {
                recipeOutputItems.addAll(((BasinRecipe) recipe).rollResults());
                recipeOutputFluids.addAll(((BasinRecipe) recipe).getFluidResults());
            } else
                recipeOutputItems.add(recipe.getResultItem());
        }
        if (!basin.acceptOutputs(recipeOutputItems, recipeOutputFluids, simulate))
            return false;
    }
    return true;
}
Also used : SmartFluidTankBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour) IItemHandler(net.minecraftforge.items.IItemHandler) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Iterate(com.simibubi.create.foundation.utility.Iterate) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) HeatLevel(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel) ArrayList(java.util.ArrayList) Ingredient(net.minecraft.world.item.crafting.Ingredient) List(java.util.List) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) SmartInventory(com.simibubi.create.foundation.item.SmartInventory) Recipe(net.minecraft.world.item.crafting.Recipe) AllRecipeTypes(com.simibubi.create.AllRecipeTypes) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ProcessingRecipeParams(com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeParams) TankSegment(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour.TankSegment) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) Level(net.minecraft.world.level.Level) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) IItemHandler(net.minecraftforge.items.IItemHandler) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) TankSegment(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour.TankSegment) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) LinkedList(java.util.LinkedList) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) Ingredient(net.minecraft.world.item.crafting.Ingredient) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) HeatLevel(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel) ItemStack(net.minecraft.world.item.ItemStack)

Example 4 with FluidIngredient

use of com.simibubi.create.foundation.fluid.FluidIngredient in project createaddition by mrh0.

the class CrudeBurningRecipeSerializer method readFromJson.

@Override
public CrudeBurningRecipe readFromJson(ResourceLocation recipeId, JsonObject json) {
    int burnTime = (json.get("burnTime")).getAsInt();
    FluidIngredient fluid = FluidIngredient.deserialize(json.get("input"));
    return new CrudeBurningRecipe(recipeId, fluid, burnTime);
}
Also used : FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient)

Example 5 with FluidIngredient

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

the class BasinCategory method setIngredients.

@Override
public void setIngredients(BasinRecipe recipe, IIngredients ingredients) {
    List<Ingredient> itemIngredients = new ArrayList<>(recipe.getIngredients());
    HeatCondition requiredHeat = recipe.getRequiredHeat();
    if (!requiredHeat.testBlazeBurner(HeatLevel.NONE))
        itemIngredients.add(Ingredient.of(AllBlocks.BLAZE_BURNER.get()));
    if (!requiredHeat.testBlazeBurner(HeatLevel.KINDLED))
        itemIngredients.add(Ingredient.of(AllItems.BLAZE_CAKE.get()));
    ingredients.setInputIngredients(itemIngredients);
    ingredients.setInputLists(VanillaTypes.FLUID, recipe.getFluidIngredients().stream().map(FluidIngredient::getMatchingFluidStacks).collect(Collectors.toList()));
    if (!recipe.getRollableResults().isEmpty())
        ingredients.setOutput(VanillaTypes.ITEM, recipe.getResultItem());
    if (!recipe.getFluidResults().isEmpty())
        ingredients.setOutputs(VanillaTypes.FLUID, recipe.getFluidResults());
}
Also used : 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) ArrayList(java.util.ArrayList)

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