use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class ChemicalDissolutionRecipeSerializer method fromJson.
@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
JsonElement itemInput = JSONUtils.isArrayNode(json, JsonConstants.ITEM_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.ITEM_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.ITEM_INPUT);
ItemStackIngredient itemIngredient = ItemStackIngredient.deserialize(itemInput);
JsonElement gasInput = JSONUtils.isArrayNode(json, JsonConstants.GAS_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.GAS_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.GAS_INPUT);
GasStackIngredient gasIngredient = GasStackIngredient.deserialize(gasInput);
ChemicalStack<?> output = SerializerHelper.getBoxedChemicalStack(json, JsonConstants.OUTPUT);
if (output.isEmpty()) {
throw new JsonSyntaxException("Recipe output must not be empty.");
}
return this.factory.create(recipeId, itemIngredient, gasIngredient, output);
}
use of mekanism.api.recipes.inputs.ItemStackIngredient 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.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class CombinerRecipeSerializer method fromJson.
@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
JsonElement mainInput = JSONUtils.isArrayNode(json, JsonConstants.MAIN_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.MAIN_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.MAIN_INPUT);
ItemStackIngredient mainIngredient = ItemStackIngredient.deserialize(mainInput);
JsonElement extraInput = JSONUtils.isArrayNode(json, JsonConstants.EXTRA_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.EXTRA_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.EXTRA_INPUT);
ItemStackIngredient extraIngredient = ItemStackIngredient.deserialize(extraInput);
ItemStack output = SerializerHelper.getItemStack(json, JsonConstants.OUTPUT);
if (output.isEmpty()) {
throw new JsonSyntaxException("Combiner recipe output must not be empty.");
}
return this.factory.create(recipeId, mainIngredient, extraIngredient, output);
}
use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class CombinerRecipeSerializer method fromNetwork.
@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
try {
ItemStackIngredient mainInput = ItemStackIngredient.read(buffer);
ItemStackIngredient extraInput = ItemStackIngredient.read(buffer);
ItemStack output = buffer.readItem();
return this.factory.create(recipeId, mainInput, extraInput, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading combiner recipe from packet.", e);
throw e;
}
}
use of mekanism.api.recipes.inputs.ItemStackIngredient in project Mekanism by mekanism.
the class ItemStackChemicalToItemStackRecipeSerializer method fromNetwork.
@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
try {
ItemStackIngredient itemInput = ItemStackIngredient.read(buffer);
INGREDIENT chemicalInput = getDeserializer().read(buffer);
ItemStack output = buffer.readItem();
return this.factory.create(recipeId, itemInput, chemicalInput, output);
} catch (Exception e) {
Mekanism.logger.error("Error reading itemstack chemical to itemstack recipe from packet.", e);
throw e;
}
}
Aggregations