Search in sources :

Example 1 with AltarRecipeGrid

use of hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid 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 2 with AltarRecipeGrid

use of hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid 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)

Example 3 with AltarRecipeGrid

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

the class CategoryAltar method setIngredients.

@Override
public void setIngredients(SimpleAltarRecipe altarRecipe, IIngredients ingredients) {
    ImmutableList.Builder<List<ItemStack>> itemInputs = ImmutableList.builder();
    ImmutableList.Builder<List<ItemStack>> itemOutputs = ImmutableList.builder();
    itemOutputs.add(Collections.singletonList(altarRecipe.getOutputForRender(Collections.emptyList())));
    AltarRecipeGrid grid = altarRecipe.getInputs();
    for (int slot = 0; slot < AltarRecipeGrid.MAX_INVENTORY_SIZE; slot++) {
        itemInputs.add(ingredientStacks(grid.getIngredient(slot)));
    }
    for (WrappedIngredient relayInput : altarRecipe.getRelayInputs()) {
        itemInputs.add(ingredientStacks(relayInput.getIngredient()));
    }
    ingredients.setInputLists(VanillaTypes.ITEM, itemInputs.build());
    ingredients.setOutputLists(VanillaTypes.ITEM, itemOutputs.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) AltarRecipeGrid(hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient)

Aggregations

AltarRecipeGrid (hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid)3 AltarType (hellfirepvp.astralsorcery.common.block.tile.altar.AltarType)2 AltarRecipeEffect (hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ImmutableList (com.google.common.collect.ImmutableList)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)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 List (java.util.List)1 ItemStack (net.minecraft.item.ItemStack)1 Ingredient (net.minecraft.item.crafting.Ingredient)1