Search in sources :

Example 1 with Mutation

use of com.infinityraider.agricraft.impl.v1.genetics.Mutation in project AgriCraft by AgriCraft.

the class JsonHelper method wrap.

@Nonnull
public static Optional<IAgriMutation> wrap(@Nullable AgriMutation mutation) {
    // Step I. Abort If Null Mutation.
    if (mutation == null) {
        return Optional.empty();
    }
    // Step II. Determine Chance.
    final double chance = mutation.getChance();
    // Step III. Determine ID.
    final String mutationId = mutation.getChild().getId().replace("_plant", "_mutation");
    // Step IV. Determine Child.
    final Optional<IAgriPlant> child = AgriApi.getPlantRegistry().get(mutation.getChild().getId());
    // Step V. Abort If Child Missing.
    if (!child.isPresent()) {
        return Optional.empty();
    }
    // Step VI. Determine Parents.
    final Optional<IAgriPlant> parentOne = AgriApi.getPlantRegistry().get(mutation.getParent1().getId());
    final Optional<IAgriPlant> parentTwo = AgriApi.getPlantRegistry().get(mutation.getParent2().getId());
    // Step VII. Abort If Missing Parent.
    if ((!parentOne.isPresent()) && (!parentTwo.isPresent())) {
        return Optional.empty();
    }
    // Step VIII. Create New Mutation
    return Optional.of(new Mutation(mutationId, chance, child.get(), parentOne.get(), parentTwo.get()));
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) Mutation(com.infinityraider.agricraft.impl.v1.genetics.Mutation) AgriMutation(com.agricraft.agricore.plant.AgriMutation) IAgriMutation(com.infinityraider.agricraft.api.v1.genetics.IAgriMutation) Nonnull(javax.annotation.Nonnull)

Aggregations

AgriMutation (com.agricraft.agricore.plant.AgriMutation)1 IAgriMutation (com.infinityraider.agricraft.api.v1.genetics.IAgriMutation)1 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)1 Mutation (com.infinityraider.agricraft.impl.v1.genetics.Mutation)1 Nonnull (javax.annotation.Nonnull)1