Search in sources :

Example 11 with ChemicalType

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

the class ChemicalCrystallizerInputRecipeCache method initCache.

@Override
protected void initCache(List<ChemicalCrystallizerRecipe> recipes) {
    for (ChemicalCrystallizerRecipe recipe : recipes) {
        IChemicalStackIngredient<?, ?> ingredient = recipe.getInput();
        ChemicalType type = ChemicalType.getTypeFor(ingredient);
        if (mapInputs(recipe, type, ingredient)) {
            typeBasedComplexRecipes.get(type).add(recipe);
        }
    }
}
Also used : ChemicalType(mekanism.api.chemical.ChemicalType) ChemicalCrystallizerRecipe(mekanism.api.recipes.ChemicalCrystallizerRecipe)

Example 12 with ChemicalType

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

the class BoxedChemicalStack method read.

/**
 * Reads a Boxed Chemical Stack from a CompoundNBT.
 *
 * @param nbt NBT.
 *
 * @return Boxed Chemical Stack.
 */
public static BoxedChemicalStack read(@Nullable CompoundNBT nbt) {
    ChemicalType chemicalType = ChemicalType.fromNBT(nbt);
    ChemicalStack<?> stack = null;
    if (chemicalType == ChemicalType.GAS) {
        stack = GasStack.readFromNBT(nbt);
    } else if (chemicalType == ChemicalType.INFUSION) {
        stack = InfusionStack.readFromNBT(nbt);
    } else if (chemicalType == ChemicalType.PIGMENT) {
        stack = PigmentStack.readFromNBT(nbt);
    } else if (chemicalType == ChemicalType.SLURRY) {
        stack = SlurryStack.readFromNBT(nbt);
    }
    return chemicalType == null || stack == null ? EMPTY : new BoxedChemicalStack(chemicalType, stack);
}
Also used : ChemicalType(mekanism.api.chemical.ChemicalType)

Example 13 with ChemicalType

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

the class ChemicalDissolutionRecipeCategory method setIngredients.

@Override
public void setIngredients(ChemicalDissolutionRecipe recipe, IIngredients ingredients) {
    ingredients.setInputLists(VanillaTypes.ITEM, Collections.singletonList(recipe.getItemInput().getRepresentations()));
    List<@NonNull GasStack> gasInputs = recipe.getGasInput().getRepresentations();
    List<GasStack> scaledGases = gasInputs.stream().map(gas -> new GasStack(gas, gas.getAmount() * TileEntityChemicalDissolutionChamber.BASE_TICKS_REQUIRED)).collect(Collectors.toList());
    ingredients.setInputLists(MekanismJEI.TYPE_GAS, Collections.singletonList(scaledGases));
    BoxedChemicalStack outputDefinition = recipe.getOutputDefinition();
    ChemicalType chemicalType = outputDefinition.getChemicalType();
    if (chemicalType == ChemicalType.GAS) {
        ingredients.setOutput(MekanismJEI.TYPE_GAS, (GasStack) outputDefinition.getChemicalStack());
    } else if (chemicalType == ChemicalType.INFUSION) {
        ingredients.setOutput(MekanismJEI.TYPE_INFUSION, (InfusionStack) outputDefinition.getChemicalStack());
    } else if (chemicalType == ChemicalType.PIGMENT) {
        ingredients.setOutput(MekanismJEI.TYPE_PIGMENT, (PigmentStack) outputDefinition.getChemicalStack());
    } else if (chemicalType == ChemicalType.SLURRY) {
        ingredients.setOutput(MekanismJEI.TYPE_SLURRY, (SlurryStack) outputDefinition.getChemicalStack());
    } else {
        throw new IllegalStateException("Unknown chemical type");
    }
}
Also used : ChemicalStack(mekanism.api.chemical.ChemicalStack) IIngredients(mezz.jei.api.ingredients.IIngredients) GuiGasGauge(mekanism.client.gui.element.gauge.GuiGasGauge) ChemicalType(mekanism.api.chemical.ChemicalType) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) GuiGauge(mekanism.client.gui.element.gauge.GuiGauge) TileEntityChemicalDissolutionChamber(mekanism.common.tile.machine.TileEntityChemicalDissolutionChamber) GasStack(mekanism.api.chemical.gas.GasStack) NonNull(mekanism.api.annotations.NonNull) MekanismBlocks(mekanism.common.registries.MekanismBlocks) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) GuiHorizontalPowerBar(mekanism.client.gui.element.bar.GuiHorizontalPowerBar) ChemicalDissolutionRecipe(mekanism.api.recipes.ChemicalDissolutionRecipe) 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) Collectors(java.util.stream.Collectors) MekanismJEI(mekanism.client.jei.MekanismJEI) ProgressType(mekanism.client.gui.element.progress.ProgressType) List(java.util.List) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) IIngredientType(mezz.jei.api.ingredients.IIngredientType) GaugeType(mekanism.client.gui.element.gauge.GaugeType) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) IGuiIngredientGroup(mezz.jei.api.gui.ingredient.IGuiIngredientGroup) VanillaTypes(mezz.jei.api.constants.VanillaTypes) Collections(java.util.Collections) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) ChemicalType(mekanism.api.chemical.ChemicalType) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) GasStack(mekanism.api.chemical.gas.GasStack) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack)

Example 14 with ChemicalType

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

the class ChemicalDissolutionRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, ChemicalDissolutionRecipe recipe, IIngredients ingredients) {
    initItem(recipeLayout.getItemStacks(), 0, true, inputSlot, recipe.getItemInput().getRepresentations());
    List<@NonNull GasStack> gasInputs = recipe.getGasInput().getRepresentations();
    List<GasStack> scaledGases = gasInputs.stream().map(gas -> new GasStack(gas, gas.getAmount() * TileEntityChemicalDissolutionChamber.BASE_TICKS_REQUIRED)).collect(Collectors.toList());
    IGuiIngredientGroup<GasStack> gasStacks = recipeLayout.getIngredientsGroup(MekanismJEI.TYPE_GAS);
    initChemical(gasStacks, 0, true, inputGauge, scaledGases);
    BoxedChemicalStack outputDefinition = recipe.getOutputDefinition();
    ChemicalType chemicalType = outputDefinition.getChemicalType();
    if (chemicalType == ChemicalType.GAS) {
        initChemicalOutput(recipeLayout, MekanismJEI.TYPE_GAS, (GasStack) outputDefinition.getChemicalStack());
    } else if (chemicalType == ChemicalType.INFUSION) {
        initChemicalOutput(recipeLayout, MekanismJEI.TYPE_INFUSION, (InfusionStack) outputDefinition.getChemicalStack());
    } else if (chemicalType == ChemicalType.PIGMENT) {
        initChemicalOutput(recipeLayout, MekanismJEI.TYPE_PIGMENT, (PigmentStack) outputDefinition.getChemicalStack());
    } else if (chemicalType == ChemicalType.SLURRY) {
        initChemicalOutput(recipeLayout, MekanismJEI.TYPE_SLURRY, (SlurryStack) outputDefinition.getChemicalStack());
    } else {
        throw new IllegalStateException("Unknown chemical type");
    }
}
Also used : ChemicalStack(mekanism.api.chemical.ChemicalStack) IIngredients(mezz.jei.api.ingredients.IIngredients) GuiGasGauge(mekanism.client.gui.element.gauge.GuiGasGauge) ChemicalType(mekanism.api.chemical.ChemicalType) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) GuiGauge(mekanism.client.gui.element.gauge.GuiGauge) TileEntityChemicalDissolutionChamber(mekanism.common.tile.machine.TileEntityChemicalDissolutionChamber) GasStack(mekanism.api.chemical.gas.GasStack) NonNull(mekanism.api.annotations.NonNull) MekanismBlocks(mekanism.common.registries.MekanismBlocks) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) GuiHorizontalPowerBar(mekanism.client.gui.element.bar.GuiHorizontalPowerBar) ChemicalDissolutionRecipe(mekanism.api.recipes.ChemicalDissolutionRecipe) 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) Collectors(java.util.stream.Collectors) MekanismJEI(mekanism.client.jei.MekanismJEI) ProgressType(mekanism.client.gui.element.progress.ProgressType) List(java.util.List) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) IIngredientType(mezz.jei.api.ingredients.IIngredientType) GaugeType(mekanism.client.gui.element.gauge.GaugeType) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) IGuiIngredientGroup(mezz.jei.api.gui.ingredient.IGuiIngredientGroup) VanillaTypes(mezz.jei.api.constants.VanillaTypes) Collections(java.util.Collections) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) ChemicalType(mekanism.api.chemical.ChemicalType) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) GasStack(mekanism.api.chemical.gas.GasStack) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) BoxedChemicalStack(mekanism.api.chemical.merged.BoxedChemicalStack)

Example 15 with ChemicalType

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

the class SerializerHelper method serializeBoxedChemicalStack.

/**
 * Helper to serialize a Boxed Chemical Stack into a Json Object.
 *
 * @param stack Stack to serialize.
 *
 * @return Json representation.
 */
public static JsonElement serializeBoxedChemicalStack(@Nonnull BoxedChemicalStack stack) {
    JsonObject json;
    ChemicalType chemicalType = stack.getChemicalType();
    if (chemicalType == ChemicalType.GAS) {
        json = serializeGasStack((GasStack) stack.getChemicalStack());
    } else if (chemicalType == ChemicalType.INFUSION) {
        json = serializeInfusionStack((InfusionStack) stack.getChemicalStack());
    } else if (chemicalType == ChemicalType.PIGMENT) {
        json = serializePigmentStack((PigmentStack) stack.getChemicalStack());
    } else if (chemicalType == ChemicalType.SLURRY) {
        json = serializeSlurryStack((SlurryStack) stack.getChemicalStack());
    } else {
        throw new IllegalStateException("Unknown chemical type");
    }
    json.addProperty(JsonConstants.CHEMICAL_TYPE, chemicalType.getSerializedName());
    return json;
}
Also used : PigmentStack(mekanism.api.chemical.pigment.PigmentStack) ChemicalType(mekanism.api.chemical.ChemicalType) JsonObject(com.google.gson.JsonObject) GasStack(mekanism.api.chemical.gas.GasStack)

Aggregations

ChemicalType (mekanism.api.chemical.ChemicalType)16 List (java.util.List)5 ChemicalStack (mekanism.api.chemical.ChemicalStack)5 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)5 Map (java.util.Map)4 ChemicalCrystallizerRecipe (mekanism.api.recipes.ChemicalCrystallizerRecipe)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 EnumMap (java.util.EnumMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Predicate (java.util.function.Predicate)3 Nullable (javax.annotation.Nullable)3 Chemical (mekanism.api.chemical.Chemical)3 GasStack (mekanism.api.chemical.gas.GasStack)3 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)3 IChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient)3 MekanismRecipeType (mekanism.common.recipe.MekanismRecipeType)3 ChemicalInputCache (mekanism.common.recipe.lookup.cache.type.ChemicalInputCache)3 EnumUtils (mekanism.common.util.EnumUtils)3 World (net.minecraft.world.World)3