Search in sources :

Example 1 with CrTChemicalTagManager

use of mekanism.common.integration.crafttweaker.tag.CrTChemicalTagManager 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

CommandStringDisplayable (com.blamejared.crafttweaker.api.brackets.CommandStringDisplayable)1 IFluidStack (com.blamejared.crafttweaker.api.fluid.IFluidStack)1 IIngredient (com.blamejared.crafttweaker.api.item.IIngredient)1 IItemStack (com.blamejared.crafttweaker.api.item.IItemStack)1 MCFluidStack (com.blamejared.crafttweaker.impl.fluid.MCFluidStack)1 ItemStackHelper (com.blamejared.crafttweaker.impl.helper.ItemStackHelper)1 MCItemStack (com.blamejared.crafttweaker.impl.item.MCItemStack)1 MCWeightedItemStack (com.blamejared.crafttweaker.impl.item.MCWeightedItemStack)1 MCTag (com.blamejared.crafttweaker.impl.tag.MCTag)1 TagManagerFluid (com.blamejared.crafttweaker.impl.tag.manager.TagManagerFluid)1 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1