Search in sources :

Example 1 with AltarRecipeEffect

use of hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect in project AstralSorcery by HellFirePvP.

the class SimpleAltarRecipe method write.

public final void write(JsonObject object) {
    object.addProperty("altar_type", this.getAltarType().ordinal());
    object.addProperty("duration", this.getDuration());
    object.addProperty("starlight", this.getStarlightRequirement());
    this.getInputs().serialize(object);
    if (this.getCustomRecipeType() != null) {
        object.addProperty("recipe_class", this.getCustomRecipeType().toString());
    }
    JsonArray outputs = new JsonArray();
    for (ItemStack output : this.outputs) {
        outputs.add(JsonHelper.serializeItemStack(output));
    }
    object.add("output", outputs);
    JsonObject options = new JsonObject();
    this.serializeAdditionalJson(options);
    if (!options.entrySet().isEmpty()) {
        object.add("options", options);
    }
    if (this.getFocusConstellation() != null) {
        object.addProperty("focus_constellation", this.getFocusConstellation().getRegistryName().toString());
    }
    if (!this.getRelayInputs().isEmpty()) {
        JsonArray inputs = new JsonArray();
        for (WrappedIngredient traitInput : this.getRelayInputs()) {
            inputs.add(traitInput.getIngredient().serialize());
        }
        object.add("relay_inputs", inputs);
    }
    if (!this.getCraftingEffects().isEmpty()) {
        JsonArray effects = new JsonArray();
        for (AltarRecipeEffect effect : this.getCraftingEffects()) {
            effects.add(effect.getRegistryName().toString());
        }
        object.add("effects", effects);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient) ItemStack(net.minecraft.item.ItemStack) AltarRecipeEffect(hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect)

Example 2 with AltarRecipeEffect

use of hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect in project AstralSorcery by HellFirePvP.

the class SimpleAltarRecipeSerializer method read.

@Override
public SimpleAltarRecipe read(ResourceLocation recipeId, JsonObject json) {
    int typeId = JSONUtils.getInt(json, "altar_type");
    AltarType type = MiscUtils.getEnumEntry(AltarType.class, typeId);
    int duration = JSONUtils.getInt(json, "duration");
    int starlightRequirement = JSONUtils.getInt(json, "starlight");
    AltarRecipeGrid grid = AltarRecipeGrid.deserialize(type, json);
    grid.validate(type);
    SimpleAltarRecipe recipe = new SimpleAltarRecipe(recipeId, type, duration, starlightRequirement, grid);
    if (JSONUtils.hasField(json, "recipe_class")) {
        ResourceLocation key = new ResourceLocation(JSONUtils.getString(json, "recipe_class"));
        recipe = AltarRecipeTypeHandler.convert(recipe, key);
        recipe.setCustomRecipeType(key);
    }
    if (JSONUtils.isJsonArray(json, "output")) {
        JsonArray outputArray = JSONUtils.getJsonArray(json, "output");
        for (int i = 0; i < outputArray.size(); i++) {
            recipe.addOutput(JsonHelper.getItemStack(outputArray.get(i), String.format("output[%s]", i)));
        }
    } else {
        recipe.addOutput(JsonHelper.getItemStack(json, "output"));
    }
    JsonObject recipeOptions = new JsonObject();
    if (JSONUtils.hasField(json, "options")) {
        recipeOptions = JSONUtils.getJsonObject(json, "options");
    }
    recipe.deserializeAdditionalJson(recipeOptions);
    if (JSONUtils.hasField(json, "focus_constellation")) {
        ResourceLocation key = new ResourceLocation(JSONUtils.getString(json, "focus_constellation"));
        IConstellation cst = RegistriesAS.REGISTRY_CONSTELLATIONS.getValue(key);
        if (cst == null) {
            throw new JsonSyntaxException("Unknown constellation " + key.toString());
        }
        recipe.setFocusConstellation(cst);
    }
    if (JSONUtils.hasField(json, "relay_inputs")) {
        JsonArray relayIngredients = JSONUtils.getJsonArray(json, "relay_inputs");
        for (int i = 0; i < relayIngredients.size(); i++) {
            JsonElement element = relayIngredients.get(i);
            Ingredient ingredient = Ingredient.deserialize(element);
            if (!ingredient.hasNoMatchingItems()) {
                recipe.addRelayInput(ingredient);
            } else {
                AstralSorcery.log.warn("Skipping relay_inputs[" + i + "] for recipe " + recipeId + " as the ingredient has no matching items!");
                AstralSorcery.log.warn("Ingredient skipped: " + JSONUtils.toString(element));
            }
        }
    }
    if (JSONUtils.hasField(json, "effects")) {
        JsonArray effectNames = JSONUtils.getJsonArray(json, "effects");
        for (int i = 0; i < effectNames.size(); i++) {
            JsonElement element = effectNames.get(i);
            ResourceLocation effectKey = new ResourceLocation(JSONUtils.getString(element, "effects[" + i + "]"));
            AltarRecipeEffect effect = RegistriesAS.REGISTRY_ALTAR_EFFECTS.getValue(effectKey);
            if (effect == null) {
                throw new JsonSyntaxException("No altar effect for name " + effectKey + "! (Found at: effects[" + i + "])");
            }
            recipe.addAltarEffect(effect);
        }
    }
    return recipe;
}
Also used : JsonArray(com.google.gson.JsonArray) AltarType(hellfirepvp.astralsorcery.common.block.tile.altar.AltarType) JsonSyntaxException(com.google.gson.JsonSyntaxException) Ingredient(net.minecraft.item.crafting.Ingredient) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) JsonObject(com.google.gson.JsonObject) AltarRecipeGrid(hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid) SimpleAltarRecipe(hellfirepvp.astralsorcery.common.crafting.recipe.SimpleAltarRecipe) AltarRecipeEffect(hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation)

Example 3 with AltarRecipeEffect

use of hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect in project AstralSorcery by HellFirePvP.

the class SimpleAltarRecipe method read.

public static SimpleAltarRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
    AltarType type = ByteBufUtils.readEnumValue(buffer, AltarType.class);
    int duration = buffer.readInt();
    int starlight = buffer.readInt();
    AltarRecipeGrid grid = AltarRecipeGrid.read(buffer);
    SimpleAltarRecipe recipe = new SimpleAltarRecipe(recipeId, type, duration, starlight, grid);
    ResourceLocation customType = ByteBufUtils.readOptional(buffer, ByteBufUtils::readResourceLocation);
    if (customType != null) {
        recipe = AltarRecipeTypeHandler.convert(recipe, customType);
        recipe.setCustomRecipeType(customType);
    }
    List<ItemStack> outputs = ByteBufUtils.readList(buffer, ByteBufUtils::readItemStack);
    outputs.forEach(recipe::addOutput);
    recipe.setFocusConstellation(ByteBufUtils.readOptional(buffer, ByteBufUtils::readRegistryEntry));
    ByteBufUtils.readList(buffer, Ingredient::read).forEach(recipe::addRelayInput);
    List<AltarRecipeEffect> effects = ByteBufUtils.readList(buffer, ByteBufUtils::readRegistryEntry);
    for (AltarRecipeEffect effect : effects) {
        recipe.addAltarEffect(effect);
    }
    recipe.readRecipeSync(buffer);
    return recipe;
}
Also used : AltarType(hellfirepvp.astralsorcery.common.block.tile.altar.AltarType) ByteBufUtils(hellfirepvp.astralsorcery.common.util.data.ByteBufUtils) ResourceLocation(net.minecraft.util.ResourceLocation) AltarRecipeGrid(hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid) ItemStack(net.minecraft.item.ItemStack) ActiveSimpleAltarRecipe(hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe) AltarRecipeEffect(hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect)

Aggregations

AltarRecipeEffect (hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 AltarType (hellfirepvp.astralsorcery.common.block.tile.altar.AltarType)2 AltarRecipeGrid (hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 JsonElement (com.google.gson.JsonElement)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)1 WrappedIngredient (hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient)1 SimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.SimpleAltarRecipe)1 ActiveSimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe)1 ByteBufUtils (hellfirepvp.astralsorcery.common.util.data.ByteBufUtils)1 Ingredient (net.minecraft.item.crafting.Ingredient)1