Search in sources :

Example 1 with AgriMutation

use of com.agricraft.agricore.plant.AgriMutation in project AgriCraft by AgriCraft.

the class PlayerConnectToServerHandler method syncMutations.

private void syncMutations(EntityPlayerMP player) {
    log.debug("Sending mutations to player: " + player.getDisplayNameString());
    final int count = AgriCore.getMutations().getAll().size();
    final Iterator<AgriMutation> it = AgriCore.getMutations().getAll().iterator();
    for (int i = 0; it.hasNext(); i++) {
        AgriMutation mutation = it.next();
        log.debug("Sending mutation: ({0} of {1})", i + 1, count);
        new MessageSyncMutationJson(mutation, i, count).sendTo(player);
    }
    log.debug("Finished sending mutations to player: " + player.getDisplayNameString());
}
Also used : AgriMutation(com.agricraft.agricore.plant.AgriMutation) MessageSyncMutationJson(com.infinityraider.agricraft.network.json.MessageSyncMutationJson)

Example 2 with AgriMutation

use of com.agricraft.agricore.plant.AgriMutation 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) AgriMutation(com.agricraft.agricore.plant.AgriMutation) IAgriMutation(com.infinityraider.agricraft.api.v1.mutation.IAgriMutation) Mutation(com.infinityraider.agricraft.farming.mutation.Mutation) Nonnull(javax.annotation.Nonnull)

Example 3 with AgriMutation

use of com.agricraft.agricore.plant.AgriMutation in project AgriCraft by AgriCraft.

the class CoreHandler method initMutations.

public static void initMutations() {
    // Announce Progress
    AgriCore.getLogger("agricraft").info("Registering Mutations!");
    // See if mutations are valid...
    final int raw = AgriCore.getMutations().getAll().size();
    AgriCore.getMutations().validate();
    final int count = AgriCore.getMutations().getAll().size();
    // Transfer
    AgriCore.getMutations().getAll().stream().filter(AgriMutation::isEnabled).map(JsonHelper::wrap).filter(Optional::isPresent).map(Optional::get).forEach(AgriApi.getMutationRegistry()::add);
    // Display Mutations
    AgriCore.getLogger("agricraft").info("Registered Mutations ({0}/{1}):", count, raw);
    for (IAgriMutation mutation : AgriApi.getMutationRegistry().all()) {
        AgriCore.getLogger("agricraft").info(" - {0}", mutation);
    }
}
Also used : AgriMutation(com.agricraft.agricore.plant.AgriMutation) IAgriMutation(com.infinityraider.agricraft.api.v1.mutation.IAgriMutation) Optional(java.util.Optional) IAgriMutation(com.infinityraider.agricraft.api.v1.mutation.IAgriMutation)

Aggregations

AgriMutation (com.agricraft.agricore.plant.AgriMutation)3 IAgriMutation (com.infinityraider.agricraft.api.v1.mutation.IAgriMutation)2 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)1 Mutation (com.infinityraider.agricraft.farming.mutation.Mutation)1 MessageSyncMutationJson (com.infinityraider.agricraft.network.json.MessageSyncMutationJson)1 Optional (java.util.Optional)1 Nonnull (javax.annotation.Nonnull)1