Search in sources :

Example 1 with ChemicalType

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

the class BoxedChemical method read.

/**
 * Reads a Boxed Chemical from a CompoundNBT.
 *
 * @param nbt NBT.
 *
 * @return Boxed Chemical.
 */
public static BoxedChemical read(@Nullable CompoundNBT nbt) {
    ChemicalType chemicalType = ChemicalType.fromNBT(nbt);
    Chemical<?> chemical = null;
    if (chemicalType == ChemicalType.GAS) {
        chemical = Gas.readFromNBT(nbt);
    } else if (chemicalType == ChemicalType.INFUSION) {
        chemical = InfuseType.readFromNBT(nbt);
    } else if (chemicalType == ChemicalType.PIGMENT) {
        chemical = Pigment.readFromNBT(nbt);
    } else if (chemicalType == ChemicalType.SLURRY) {
        chemical = Slurry.readFromNBT(nbt);
    }
    return chemicalType == null || chemical == null ? EMPTY : new BoxedChemical(chemicalType, chemical);
}
Also used : ChemicalType(mekanism.api.chemical.ChemicalType)

Example 2 with ChemicalType

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

the class ChemicalCrystallizerRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    ChemicalType chemicalType = SerializerHelper.getChemicalType(json);
    JsonElement input = JSONUtils.isArrayNode(json, JsonConstants.INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.INPUT);
    ChemicalStackIngredient<?, ?> inputIngredient = (ChemicalStackIngredient<?, ?>) SerializerHelper.getDeserializerForType(chemicalType).deserialize(input);
    ItemStack output = SerializerHelper.getItemStack(json, JsonConstants.OUTPUT);
    if (output.isEmpty()) {
        throw new JsonSyntaxException("Recipe output must not be empty.");
    }
    return this.factory.create(recipeId, inputIngredient, output);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ChemicalType(mekanism.api.chemical.ChemicalType) JsonElement(com.google.gson.JsonElement) ItemStack(net.minecraft.item.ItemStack) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient) Nonnull(javax.annotation.Nonnull)

Example 3 with ChemicalType

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

the class ChemicalCrystallizerRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ChemicalType chemicalType = buffer.readEnum(ChemicalType.class);
        ChemicalStackIngredient<?, ?> inputIngredient = (ChemicalStackIngredient<?, ?>) SerializerHelper.getDeserializerForType(chemicalType).read(buffer);
        ItemStack output = buffer.readItem();
        return this.factory.create(recipeId, inputIngredient, output);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading boxed chemical to itemstack recipe from packet.", e);
        throw e;
    }
}
Also used : ChemicalType(mekanism.api.chemical.ChemicalType) ItemStack(net.minecraft.item.ItemStack) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Example 4 with ChemicalType

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

the class ChemicalDissolutionRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ItemStackIngredient itemInput = ItemStackIngredient.read(buffer);
        GasStackIngredient gasInput = GasStackIngredient.read(buffer);
        ChemicalType chemicalType = buffer.readEnum(ChemicalType.class);
        ChemicalStack<?> output;
        if (chemicalType == ChemicalType.GAS) {
            output = GasStack.readFromPacket(buffer);
        } else if (chemicalType == ChemicalType.INFUSION) {
            output = InfusionStack.readFromPacket(buffer);
        } else if (chemicalType == ChemicalType.PIGMENT) {
            output = PigmentStack.readFromPacket(buffer);
        } else if (chemicalType == ChemicalType.SLURRY) {
            output = SlurryStack.readFromPacket(buffer);
        } else {
            throw new IllegalStateException("Unknown chemical type");
        }
        return this.factory.create(recipeId, itemInput, gasInput, output);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading itemstack gas to gas recipe from packet.", e);
        throw e;
    }
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) ChemicalType(mekanism.api.chemical.ChemicalType) JsonSyntaxException(com.google.gson.JsonSyntaxException) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient)

Example 5 with ChemicalType

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

the class ChemicalCrystallizerInputRecipeCache method clear.

@Override
public void clear() {
    super.clear();
    for (ChemicalType chemicalType : EnumUtils.CHEMICAL_TYPES) {
        typeBasedCache.get(chemicalType).clear();
        typeBasedComplexRecipes.get(chemicalType).clear();
    }
}
Also used : ChemicalType(mekanism.api.chemical.ChemicalType)

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