Search in sources :

Example 1 with Chemical

use of mekanism.api.chemical.Chemical 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 2 with Chemical

use of mekanism.api.chemical.Chemical in project Mekanism by mekanism.

the class ChemicalCrystallizerInputRecipeCache method containsInput.

/**
 * Checks if there is a matching recipe that has the given input.
 *
 * @param world World.
 * @param input Recipe input.
 *
 * @return {@code true} if there is a match, {@code false} if there isn't.
 */
public <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> boolean containsInput(@Nullable World world, CHEMICAL input) {
    if (input.isEmptyType()) {
        // Don't allow empty inputs
        return false;
    }
    initCacheIfNeeded(world);
    ChemicalType type = ChemicalType.getTypeFor(input);
    STACK stack = (STACK) input.getStack(1);
    return containsInput(type, stack) || typeBasedComplexRecipes.get(type).stream().anyMatch(recipe -> recipe.testType(stack));
}
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) ChemicalType(mekanism.api.chemical.ChemicalType)

Example 3 with Chemical

use of mekanism.api.chemical.Chemical 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)

Aggregations

List (java.util.List)3 Map (java.util.Map)3 Chemical (mekanism.api.chemical.Chemical)3 ChemicalStack (mekanism.api.chemical.ChemicalStack)3 IChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient)3 EnumMap (java.util.EnumMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2 Nullable (javax.annotation.Nullable)2 ChemicalType (mekanism.api.chemical.ChemicalType)2 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)2 ChemicalCrystallizerRecipe (mekanism.api.recipes.ChemicalCrystallizerRecipe)2 MekanismRecipeType (mekanism.common.recipe.MekanismRecipeType)2 ChemicalInputCache (mekanism.common.recipe.lookup.cache.type.ChemicalInputCache)2 EnumUtils (mekanism.common.util.EnumUtils)2 World (net.minecraft.world.World)2 CommandStringDisplayable (com.blamejared.crafttweaker.api.brackets.CommandStringDisplayable)1 IFluidStack (com.blamejared.crafttweaker.api.fluid.IFluidStack)1 IIngredient (com.blamejared.crafttweaker.api.item.IIngredient)1