Search in sources :

Example 1 with IChemicalStackIngredient

use of mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient in project Mekanism by mekanism.

the class BaseCrTExampleProvider method addSupportedChemical.

private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> void addSupportedChemical(Class<STACK> stackClass, Class<? extends ICrTChemicalStack<CHEMICAL, STACK, ?>> stackCrTClass, Class<? extends IChemicalStackIngredient<CHEMICAL, STACK>> ingredientClass, String ingredientType, Function<STACK, CommandStringDisplayable> singleDescription, CrTChemicalTagManager<CHEMICAL> tagManager, ChemicalIngredientDeserializer<CHEMICAL, STACK, ?> deserializer) {
    addSupportedConversion(ICrTChemicalStack.class, stackCrTClass, stackClass, (imports, stack) -> singleDescription.apply(stack).getCommandString());
    addSupportedConversion(IChemicalStackIngredient.class, ingredientClass, ingredientClass, (imports, ingredient) -> getIngredientRepresentation(ingredient, imports.addImport(ingredientType), deserializer, singleDescription, tagManager), (imports, ingredient) -> {
        if (ingredient instanceof ChemicalStackIngredient.SingleIngredient) {
            JsonObject serialized = ingredient.serialize().getAsJsonObject();
            return singleDescription.apply(deserializer.deserializeStack(serialized)).getCommandString();
        } else if (ingredient instanceof ChemicalStackIngredient.TaggedIngredient) {
            JsonObject serialized = (JsonObject) ingredient.serialize();
            long amount = serialized.getAsJsonPrimitive(JsonConstants.AMOUNT).getAsLong();
            if (amount > 0 && amount <= Integer.MAX_VALUE) {
                return getTagWithExplicitAmount(tagManager.getTag(serialized.get(JsonConstants.TAG).getAsString()), (int) amount);
            }
        }
        return null;
    });
}
Also used : JsonObject(com.google.gson.JsonObject) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)

Example 2 with IChemicalStackIngredient

use of mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient in project Mekanism by mekanism.

the class MekanismRecipeHandler method convertIngredient.

private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> String convertIngredient(String crtClass, CrTChemicalTagManager<CHEMICAL> tagManager, ChemicalIngredientDeserializer<CHEMICAL, STACK, ?> deserializer, IChemicalStackIngredient<CHEMICAL, STACK> ingredient) {
    if (ingredient instanceof ChemicalStackIngredient.SingleIngredient) {
        // Serialize and deserialize to get easy access to the amount
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        // Note: Handled via implicit casts
        return convertParam(deserializer.deserializeStack(serialized));
    } else if (ingredient instanceof ChemicalStackIngredient.TaggedIngredient) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        MCTag<CHEMICAL> tag = tagManager.getTag(serialized.get(JsonConstants.TAG).getAsString());
        long amount = serialized.getAsJsonPrimitive(JsonConstants.AMOUNT).getAsLong();
        if (amount > 0 && amount <= Integer.MAX_VALUE) {
            // Note: Handled via implicit casts
            return getTagWithExplicitAmount(tag, (int) amount);
        }
        // Tag with amount can only handle up to max int, so we have to do it explicitly if we have more
        return crtClass + ".from(" + tag.getCommandString() + ", " + amount + ")";
    } else if (ingredient instanceof ChemicalStackIngredient.MultiIngredient) {
        ChemicalStackIngredient.MultiIngredient<CHEMICAL, STACK, ?> multiIngredient = (ChemicalStackIngredient.MultiIngredient<CHEMICAL, STACK, ?>) ingredient;
        StringBuilder builder = new StringBuilder(crtClass + ".createMulti(");
        multiIngredient.forEachIngredient(i -> {
            builder.append(convertIngredient(crtClass, tagManager, deserializer, i)).append(", ");
            return false;
        });
        // Remove trailing comma and space
        builder.setLength(builder.length() - 2);
        builder.append(")");
        return builder.toString();
    }
    // Shouldn't happen
    return "Unimplemented chemical stack ingredient: " + ingredient;
}
Also used : MCTag(com.blamejared.crafttweaker.impl.tag.MCTag) JsonObject(com.google.gson.JsonObject) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)

Example 3 with IChemicalStackIngredient

use of mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient in project Mekanism by mekanism.

the class ChemicalCrystallizerInputRecipeCache method findFirstRecipe.

@Nullable
private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> ChemicalCrystallizerRecipe findFirstRecipe(ChemicalType type, STACK stack) {
    Predicate<ChemicalCrystallizerRecipe> matchPredicate = recipe -> ((IChemicalStackIngredient<CHEMICAL, STACK>) recipe.getInput()).test(stack);
    ChemicalInputCache<CHEMICAL, STACK, ChemicalCrystallizerRecipe> cache = (ChemicalInputCache<CHEMICAL, STACK, ChemicalCrystallizerRecipe>) typeBasedCache.get(type);
    ChemicalCrystallizerRecipe recipe = cache.findFirstRecipe(stack, matchPredicate);
    return recipe == null ? findFirstRecipe(typeBasedComplexRecipes.get(type), matchPredicate) : recipe;
}
Also used : EnumUtils(mekanism.common.util.EnumUtils) MekanismRecipeType(mekanism.common.recipe.MekanismRecipeType) EnumMap(java.util.EnumMap) ChemicalStack(mekanism.api.chemical.ChemicalStack) Predicate(java.util.function.Predicate) World(net.minecraft.world.World) Set(java.util.Set) ChemicalCrystallizerRecipe(mekanism.api.recipes.ChemicalCrystallizerRecipe) ChemicalInputCache(mekanism.common.recipe.lookup.cache.type.ChemicalInputCache) ChemicalType(mekanism.api.chemical.ChemicalType) HashSet(java.util.HashSet) List(java.util.List) Chemical(mekanism.api.chemical.Chemical) Map(java.util.Map) Nullable(javax.annotation.Nullable) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ChemicalInputCache(mekanism.common.recipe.lookup.cache.type.ChemicalInputCache) ChemicalCrystallizerRecipe(mekanism.api.recipes.ChemicalCrystallizerRecipe) Nullable(javax.annotation.Nullable)

Example 4 with IChemicalStackIngredient

use of mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient in project Mekanism by mekanism.

the class BaseCrTExampleProvider method getIngredientRepresentation.

private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> String getIngredientRepresentation(IChemicalStackIngredient<CHEMICAL, STACK> ingredient, String ingredientType, ChemicalIngredientDeserializer<CHEMICAL, STACK, ?> deserializer, Function<STACK, CommandStringDisplayable> singleDescription, CrTChemicalTagManager<CHEMICAL> tagManager) {
    if (ingredient instanceof ChemicalStackIngredient.SingleIngredient) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        String stackRepresentation = singleDescription.apply(deserializer.deserializeStack(serialized)).getCommandString();
        return ingredientType + ".from(" + stackRepresentation + ")";
    } else if (ingredient instanceof ChemicalStackIngredient.TaggedIngredient) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        String tagRepresentation = tagManager.getTag(serialized.get(JsonConstants.TAG).getAsString()).getCommandString();
        return ingredientType + ".from(" + tagRepresentation + ", " + serialized.getAsJsonPrimitive(JsonConstants.AMOUNT) + ")";
    } else if (ingredient instanceof ChemicalStackIngredient.MultiIngredient) {
        ChemicalStackIngredient.MultiIngredient<CHEMICAL, STACK, ?> multiIngredient = (ChemicalStackIngredient.MultiIngredient<CHEMICAL, STACK, ?>) ingredient;
        StringBuilder builder = new StringBuilder(ingredientType + ".createMulti(");
        if (!multiIngredient.forEachIngredient(i -> {
            String rep = getIngredientRepresentation(i, ingredientType, deserializer, singleDescription, tagManager);
            if (rep == null) {
                return true;
            }
            builder.append(rep).append(", ");
            return false;
        })) {
            // Remove trailing comma and space
            builder.setLength(builder.length() - 2);
            builder.append(")");
            return builder.toString();
        }
    }
    return null;
}
Also used : JSONUtils(net.minecraft.util.JSONUtils) JsonObject(com.google.gson.JsonObject) IDataProvider(net.minecraft.data.IDataProvider) Arrays(java.util.Arrays) ChemicalStack(mekanism.api.chemical.ChemicalStack) ICrTPigmentStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack.ICrTPigmentStack) Item(net.minecraft.item.Item) BiFunction(java.util.function.BiFunction) ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) IItemStack(com.blamejared.crafttweaker.api.item.IItemStack) JsonConstants(mekanism.api.JsonConstants) CrTGasStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTGasStack) CrTImportsComponent(mekanism.common.integration.crafttweaker.example.component.CrTImportsComponent) ICrTGasStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack.ICrTGasStack) Gson(com.google.gson.Gson) Chemical(mekanism.api.chemical.Chemical) Map(java.util.Map) GasStack(mekanism.api.chemical.gas.GasStack) IIngredient(com.blamejared.crafttweaker.api.item.IIngredient) Path(java.nio.file.Path) 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) CommandStringDisplayable(com.blamejared.crafttweaker.api.brackets.CommandStringDisplayable) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MekanismRecipeHandler(mekanism.common.integration.crafttweaker.recipe.handler.MekanismRecipeHandler) 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) IFluidStack(com.blamejared.crafttweaker.api.fluid.IFluidStack) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) InfusionStackIngredient(mekanism.api.recipes.inputs.chemical.InfusionStackIngredient) MCItemStack(com.blamejared.crafttweaker.impl.item.MCItemStack) ICrTChemicalStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack) CrTPigmentTagManager(mekanism.common.integration.crafttweaker.tag.CrTPigmentTagManager) Ingredient(net.minecraft.item.crafting.Ingredient) ICrTInfusionStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack.ICrTInfusionStack) TagManagerFluid(com.blamejared.crafttweaker.impl.tag.manager.TagManagerFluid) MCWeightedItemStack(com.blamejared.crafttweaker.impl.item.MCWeightedItemStack) HashMap(java.util.HashMap) Function(java.util.function.Function) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) LinkedHashMap(java.util.LinkedHashMap) ItemStack(net.minecraft.item.ItemStack) FloatingLong(mekanism.api.math.FloatingLong) ICrTSlurryStack(mekanism.common.integration.crafttweaker.chemical.ICrTChemicalStack.ICrTSlurryStack) ResourcePackType(net.minecraft.resources.ResourcePackType) 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) Nonnull(javax.annotation.Nonnull) DataGenerator(net.minecraft.data.DataGenerator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) CrTSlurryStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTSlurryStack) DirectoryCache(net.minecraft.data.DirectoryCache) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) ExistingFileHelper(net.minecraftforge.common.data.ExistingFileHelper) 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) IItemProvider(net.minecraft.util.IItemProvider) CrTPigmentStack(mekanism.common.integration.crafttweaker.chemical.CrTChemicalStack.CrTPigmentStack) ItemStackHelper(com.blamejared.crafttweaker.impl.helper.ItemStackHelper) SerializerHelper(mekanism.api.SerializerHelper) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) JsonObject(com.google.gson.JsonObject) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)

Example 5 with IChemicalStackIngredient

use of mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient in project Mekanism by mekanism.

the class ChemicalCrystallizerRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, ChemicalCrystallizerRecipe recipe, IIngredients ingredients) {
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    initItem(itemStacks, 0, false, output, recipe.getOutputDefinition());
    IChemicalStackIngredient<?, ?> input = recipe.getInput();
    if (input instanceof GasStackIngredient) {
        initChemical(recipeLayout, recipe, MekanismJEI.TYPE_GAS, (GasStackIngredient) input, null);
    } else if (input instanceof InfusionStackIngredient) {
        initChemical(recipeLayout, recipe, MekanismJEI.TYPE_INFUSION, (InfusionStackIngredient) input, null);
    } else if (input instanceof PigmentStackIngredient) {
        initChemical(recipeLayout, recipe, MekanismJEI.TYPE_PIGMENT, (PigmentStackIngredient) input, null);
    } else if (input instanceof SlurryStackIngredient) {
        SlurryStackIngredient slurryInput = (SlurryStackIngredient) input;
        Set<ITag<Item>> tags = new HashSet<>();
        for (SlurryStack slurryStack : slurryInput.getRepresentations()) {
            Slurry slurry = slurryStack.getType();
            if (!slurry.isIn(MekanismTags.Slurries.DIRTY)) {
                ITag<Item> oreTag = slurry.getOreTag();
                if (oreTag != null) {
                    tags.add(oreTag);
                }
            }
        }
        if (tags.size() == 1) {
            initChemical(recipeLayout, recipe, MekanismJEI.TYPE_SLURRY, slurryInput, itemStacks);
            // TODO: Eventually come up with a better way to do this to allow for if there outputs based on the input and multiple input types
            tags.stream().findFirst().ifPresent(tag -> initItem(itemStacks, 1, false, slurryOreSlot, tag.getValues().stream().map(ItemStack::new).collect(Collectors.toList())));
        } else {
            initChemical(recipeLayout, recipe, MekanismJEI.TYPE_SLURRY, slurryInput, null);
        }
    }
}
Also used : IOreInfo(mekanism.client.gui.machine.GuiChemicalCrystallizer.IOreInfo) ChemicalStack(mekanism.api.chemical.ChemicalStack) Item(net.minecraft.item.Item) IIngredients(mezz.jei.api.ingredients.IIngredients) ChemicalCrystallizerRecipe(mekanism.api.recipes.ChemicalCrystallizerRecipe) GuiGasGauge(mekanism.client.gui.element.gauge.GuiGasGauge) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) HashSet(java.util.HashSet) GuiGauge(mekanism.client.gui.element.gauge.GuiGauge) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) Slurry(mekanism.api.chemical.slurry.Slurry) Nonnull(javax.annotation.Nonnull) MekanismBlocks(mekanism.common.registries.MekanismBlocks) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) WeakHashMap(java.util.WeakHashMap) Nullable(javax.annotation.Nullable) BaseRecipeCategory(mekanism.client.jei.BaseRecipeCategory) SlotOverlay(mekanism.common.inventory.container.slot.SlotOverlay) SlotType(mekanism.client.gui.element.slot.SlotType) DataType(mekanism.common.tile.component.config.DataType) Set(java.util.Set) ITag(net.minecraft.tags.ITag) PigmentStackIngredient(mekanism.api.recipes.inputs.chemical.PigmentStackIngredient) GuiChemicalCrystallizer(mekanism.client.gui.machine.GuiChemicalCrystallizer) Collectors(java.util.stream.Collectors) MekanismJEI(mekanism.client.jei.MekanismJEI) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) IGuiIngredient(mezz.jei.api.gui.ingredient.IGuiIngredient) ProgressType(mekanism.client.gui.element.progress.ProgressType) SlurryStackIngredient(mekanism.api.recipes.inputs.chemical.SlurryStackIngredient) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) IIngredientType(mezz.jei.api.ingredients.IIngredientType) GaugeType(mekanism.client.gui.element.gauge.GaugeType) IGuiIngredientGroup(mezz.jei.api.gui.ingredient.IGuiIngredientGroup) MekanismTags(mekanism.common.tags.MekanismTags) VanillaTypes(mezz.jei.api.constants.VanillaTypes) Collections(java.util.Collections) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack) InfusionStackIngredient(mekanism.api.recipes.inputs.chemical.InfusionStackIngredient) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) HashSet(java.util.HashSet) Set(java.util.Set) PigmentStackIngredient(mekanism.api.recipes.inputs.chemical.PigmentStackIngredient) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Item(net.minecraft.item.Item) ITag(net.minecraft.tags.ITag) Slurry(mekanism.api.chemical.slurry.Slurry) SlurryStackIngredient(mekanism.api.recipes.inputs.chemical.SlurryStackIngredient) ItemStack(net.minecraft.item.ItemStack) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) InfusionStackIngredient(mekanism.api.recipes.inputs.chemical.InfusionStackIngredient)

Aggregations

IChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient)5 JsonObject (com.google.gson.JsonObject)3 Map (java.util.Map)3 ChemicalStack (mekanism.api.chemical.ChemicalStack)3 ChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)3 MCTag (com.blamejared.crafttweaker.impl.tag.MCTag)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 Chemical (mekanism.api.chemical.Chemical)2 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)2 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)2 ChemicalCrystallizerRecipe (mekanism.api.recipes.ChemicalCrystallizerRecipe)2 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)2 InfusionStackIngredient (mekanism.api.recipes.inputs.chemical.InfusionStackIngredient)2 PigmentStackIngredient (mekanism.api.recipes.inputs.chemical.PigmentStackIngredient)2