Search in sources :

Example 1 with CrTImportsComponent

use of mekanism.common.integration.crafttweaker.example.component.CrTImportsComponent in project Mekanism by mekanism.

the class BaseCrTExampleProvider method getIngredientRepresentation.

private String getIngredientRepresentation(CrTImportsComponent imports, FluidStackIngredient ingredient) {
    if (ingredient instanceof FluidStackIngredient.Single) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        String stackRepresentation = new MCFluidStack(SerializerHelper.deserializeFluid(serialized)).getCommandString();
        return imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".from(" + stackRepresentation + ")";
    } else if (ingredient instanceof FluidStackIngredient.Tagged) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        String tagRepresentation = TagManagerFluid.INSTANCE.getTag(serialized.get(JsonConstants.TAG).getAsString()).getCommandString();
        return imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".from(" + tagRepresentation + ", " + serialized.getAsJsonPrimitive(JsonConstants.AMOUNT) + ")";
    } else if (ingredient instanceof FluidStackIngredient.Multi) {
        FluidStackIngredient.Multi multiIngredient = (FluidStackIngredient.Multi) ingredient;
        StringBuilder builder = new StringBuilder(imports.addImport(CrTConstants.CLASS_FLUID_STACK_INGREDIENT) + ".createMulti(");
        if (!multiIngredient.forEachIngredient(i -> {
            String rep = getIngredientRepresentation(imports, i);
            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) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) MCFluidStack(com.blamejared.crafttweaker.impl.fluid.MCFluidStack) JsonObject(com.google.gson.JsonObject)

Example 2 with CrTImportsComponent

use of mekanism.common.integration.crafttweaker.example.component.CrTImportsComponent in project Mekanism by mekanism.

the class CrTExampleBuilder method build.

public String build() {
    int contentLength = contents.size();
    if (contentLength == 0) {
        invalidContents();
    }
    // TODO: Trim trailing and starting blank lines and check if empty again (may be best to do this *after* the string is built??)
    // Though do we want it to just silently trim or do we want it to hard fail
    StringBuilder preImports = new StringBuilder();
    StringBuilder postImports = new StringBuilder();
    for (int i = 0; i < contentLength; i++) {
        ICrTExampleComponent component = contents.get(i);
        if (component instanceof CrTImportsComponent) {
            // Set imports being declared to false so that we move onto post imports
            importsDeclared = false;
            continue;
        }
        StringBuilder stringBuilder = importsDeclared ? preImports : postImports;
        if (component != null) {
            // Null components are blank lines and can be ignored here as the new line afterwards will be added when appropriate
            stringBuilder.append(component.asString());
        }
        if (i < contentLength - 1) {
            // If we are not on the last line add a new line after this
            stringBuilder.append('\n');
        }
    }
    return preImports.append(importsComponent.asString()).append(postImports).toString();
}
Also used : ICrTExampleComponent(mekanism.common.integration.crafttweaker.example.component.ICrTExampleComponent) CrTImportsComponent(mekanism.common.integration.crafttweaker.example.component.CrTImportsComponent)

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