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);
}
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);
}
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;
}
}
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;
}
}
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();
}
}
Aggregations