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