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