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