Search in sources :

Example 1 with AgriPlantIngredient

use of com.infinityraider.agricraft.api.v1.plant.AgriPlantIngredient in project AgriCraft by AgriCraft.

the class AgriPlantIngredientSerializer method parse.

@Nonnull
@Override
public AgriPlantIngredient parse(PacketBuffer buffer) {
    String id = buffer.readString();
    IAgriPlant plant = AgriApi.getPlantRegistry().get(id).orElse(AgriApi.getPlantRegistry().getNoPlant());
    if (plant.isPlant()) {
        return new AgriPlantIngredient(plant);
    } else {
        return new AgriLazyPlantIngredient(id);
    }
}
Also used : AgriPlantIngredient(com.infinityraider.agricraft.api.v1.plant.AgriPlantIngredient) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) Nonnull(javax.annotation.Nonnull)

Example 2 with AgriPlantIngredient

use of com.infinityraider.agricraft.api.v1.plant.AgriPlantIngredient in project AgriCraft by AgriCraft.

the class AgriPlantIngredientSerializer method parse.

@Nonnull
@Override
public AgriPlantIngredient parse(JsonObject json) {
    if (!json.has("plant")) {
        throw new JsonParseException("Agricraft plant ingredient must have a \"plant\" property!");
    }
    String id = json.get("plant").getAsString();
    IAgriPlant plant = AgriApi.getPlantRegistry().get(id).orElse(AgriApi.getPlantRegistry().getNoPlant());
    if (plant.isPlant()) {
        return new AgriPlantIngredient(plant);
    } else {
        return new AgriLazyPlantIngredient(id);
    }
}
Also used : AgriPlantIngredient(com.infinityraider.agricraft.api.v1.plant.AgriPlantIngredient) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) JsonParseException(com.google.gson.JsonParseException) Nonnull(javax.annotation.Nonnull)

Aggregations

AgriPlantIngredient (com.infinityraider.agricraft.api.v1.plant.AgriPlantIngredient)2 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)2 Nonnull (javax.annotation.Nonnull)2 JsonParseException (com.google.gson.JsonParseException)1