Search in sources :

Example 6 with GasStackIngredient

use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.

the class NucleosynthesizingRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ItemStackIngredient inputSolid = ItemStackIngredient.read(buffer);
        GasStackIngredient inputGas = GasStackIngredient.read(buffer);
        ItemStack outputItem = buffer.readItem();
        int duration = buffer.readVarInt();
        return this.factory.create(recipeId, inputSolid, inputGas, outputItem, duration);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading nucleosynthesizing recipe from packet.", e);
        throw e;
    }
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) ItemStack(net.minecraft.item.ItemStack) JsonSyntaxException(com.google.gson.JsonSyntaxException) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient)

Example 7 with GasStackIngredient

use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.

the class RotaryRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    FluidStackIngredient fluidInputIngredient = null;
    GasStackIngredient gasInputIngredient = null;
    GasStack gasOutput = null;
    FluidStack fluidOutput = null;
    boolean hasFluidToGas = false;
    boolean hasGasToFluid = false;
    if (json.has(JsonConstants.FLUID_INPUT) || json.has(JsonConstants.GAS_OUTPUT)) {
        JsonElement fluidInput = JSONUtils.isArrayNode(json, JsonConstants.FLUID_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.FLUID_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.FLUID_INPUT);
        fluidInputIngredient = FluidStackIngredient.deserialize(fluidInput);
        gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
        hasFluidToGas = true;
        if (gasOutput.isEmpty()) {
            throw new JsonSyntaxException("Rotary recipe gas output cannot be empty if it is defined.");
        }
    }
    if (json.has(JsonConstants.GAS_INPUT) || json.has(JsonConstants.FLUID_OUTPUT)) {
        JsonElement gasInput = JSONUtils.isArrayNode(json, JsonConstants.GAS_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.GAS_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.GAS_INPUT);
        gasInputIngredient = GasStackIngredient.deserialize(gasInput);
        fluidOutput = SerializerHelper.getFluidStack(json, JsonConstants.FLUID_OUTPUT);
        hasGasToFluid = true;
        if (fluidOutput.isEmpty()) {
            throw new JsonSyntaxException("Rotary recipe fluid output cannot be empty if it is defined.");
        }
    }
    if (hasFluidToGas && hasGasToFluid) {
        return this.factory.create(recipeId, fluidInputIngredient, gasInputIngredient, gasOutput, fluidOutput);
    } else if (hasFluidToGas) {
        return this.factory.create(recipeId, fluidInputIngredient, gasOutput);
    } else if (hasGasToFluid) {
        return this.factory.create(recipeId, gasInputIngredient, fluidOutput);
    }
    throw new JsonSyntaxException("Rotary recipes require at least a gas to fluid or fluid to gas conversion.");
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) FluidStack(net.minecraftforge.fluids.FluidStack) JsonElement(com.google.gson.JsonElement) GasStack(mekanism.api.chemical.gas.GasStack) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Nonnull(javax.annotation.Nonnull)

Example 8 with GasStackIngredient

use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.

the class PressurizedReactionRecipeSerializer 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 solidIngredient = ItemStackIngredient.deserialize(itemInput);
    JsonElement fluidInput = JSONUtils.isArrayNode(json, JsonConstants.FLUID_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.FLUID_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.FLUID_INPUT);
    FluidStackIngredient fluidIngredient = FluidStackIngredient.deserialize(fluidInput);
    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);
    FloatingLong energyRequired = FloatingLong.ZERO;
    if (json.has(JsonConstants.ENERGY_REQUIRED)) {
        energyRequired = SerializerHelper.getFloatingLong(json, JsonConstants.ENERGY_REQUIRED);
    }
    int duration;
    JsonElement ticks = json.get(JsonConstants.DURATION);
    if (!JSONUtils.isNumberValue(ticks)) {
        throw new JsonSyntaxException("Expected duration to be a number greater than zero.");
    }
    duration = ticks.getAsJsonPrimitive().getAsInt();
    if (duration <= 0) {
        throw new JsonSyntaxException("Expected duration to be a number greater than zero.");
    }
    ItemStack itemOutput = ItemStack.EMPTY;
    GasStack gasOutput = GasStack.EMPTY;
    if (json.has(JsonConstants.ITEM_OUTPUT)) {
        itemOutput = SerializerHelper.getItemStack(json, JsonConstants.ITEM_OUTPUT);
        if (itemOutput.isEmpty()) {
            throw new JsonSyntaxException("Reaction chamber item output must not be empty, if it is defined.");
        }
        if (json.has(JsonConstants.GAS_OUTPUT)) {
            // The gas is optional given we have an output item
            gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
            if (gasOutput.isEmpty()) {
                throw new JsonSyntaxException("Reaction chamber gas output must not be empty, if it is defined.");
            }
        }
    } else {
        // If we don't have an output item, we are required to have an output gas
        gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
        if (gasOutput.isEmpty()) {
            throw new JsonSyntaxException("Reaction chamber gas output must not be empty, if there is no item output.");
        }
    }
    return this.factory.create(recipeId, solidIngredient, fluidIngredient, gasIngredient, energyRequired, duration, itemOutput, gasOutput);
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) FloatingLong(mekanism.api.math.FloatingLong) JsonSyntaxException(com.google.gson.JsonSyntaxException) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) JsonElement(com.google.gson.JsonElement) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Nonnull(javax.annotation.Nonnull)

Example 9 with GasStackIngredient

use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.

the class PressurizedReactionRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        ItemStackIngredient inputSolid = ItemStackIngredient.read(buffer);
        FluidStackIngredient inputFluid = FluidStackIngredient.read(buffer);
        GasStackIngredient inputGas = GasStackIngredient.read(buffer);
        FloatingLong energyRequired = FloatingLong.readFromBuffer(buffer);
        int duration = buffer.readVarInt();
        ItemStack outputItem = buffer.readItem();
        GasStack outputGas = GasStack.readFromPacket(buffer);
        return this.factory.create(recipeId, inputSolid, inputFluid, inputGas, energyRequired, duration, outputItem, outputGas);
    } catch (Exception e) {
        Mekanism.logger.error("Error reading pressurized reaction recipe from packet.", e);
        throw e;
    }
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) FloatingLong(mekanism.api.math.FloatingLong) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) JsonSyntaxException(com.google.gson.JsonSyntaxException) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient)

Example 10 with GasStackIngredient

use of mekanism.api.recipes.inputs.chemical.GasStackIngredient in project Mekanism by mekanism.

the class RotaryRecipeSerializer method fromNetwork.

@Override
public RECIPE fromNetwork(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) {
    try {
        FluidStackIngredient fluidInputIngredient = null;
        GasStackIngredient gasInputIngredient = null;
        GasStack gasOutput = null;
        FluidStack fluidOutput = null;
        boolean hasFluidToGas = buffer.readBoolean();
        if (hasFluidToGas) {
            fluidInputIngredient = FluidStackIngredient.read(buffer);
            gasOutput = GasStack.readFromPacket(buffer);
        }
        boolean hasGasToFluid = buffer.readBoolean();
        if (hasGasToFluid) {
            gasInputIngredient = GasStackIngredient.read(buffer);
            fluidOutput = FluidStack.readFromPacket(buffer);
        }
        if (hasFluidToGas && hasGasToFluid) {
            return this.factory.create(recipeId, fluidInputIngredient, gasInputIngredient, gasOutput, fluidOutput);
        } else if (hasFluidToGas) {
            return this.factory.create(recipeId, fluidInputIngredient, gasOutput);
        } else if (hasGasToFluid) {
            return this.factory.create(recipeId, gasInputIngredient, fluidOutput);
        }
        // Should never happen, but if we somehow get here log it
        Mekanism.logger.error("Error reading rotary recipe from packet. A recipe got sent with no conversion in either direction.");
        return null;
    } catch (Exception e) {
        Mekanism.logger.error("Error reading rotary recipe from packet.", e);
        throw e;
    }
}
Also used : FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) JsonSyntaxException(com.google.gson.JsonSyntaxException) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient)

Aggregations

GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)11 JsonSyntaxException (com.google.gson.JsonSyntaxException)10 Nonnull (javax.annotation.Nonnull)6 GasStack (mekanism.api.chemical.gas.GasStack)6 ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)6 JsonElement (com.google.gson.JsonElement)5 ItemStack (net.minecraft.item.ItemStack)5 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)4 FloatingLong (mekanism.api.math.FloatingLong)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 WeakHashMap (java.util.WeakHashMap)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 ChemicalStack (mekanism.api.chemical.ChemicalStack)1 ChemicalType (mekanism.api.chemical.ChemicalType)1 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)1