use of com.infinityraider.agricraft.api.v1.stat.IAgriStat in project AgriCraft by AgriCraft.
the class MessageTileEntitySeedStorage method getNecessarySerializers.
@Override
protected List<IMessageSerializer> getNecessarySerializers() {
return ImmutableList.of(new IMessageSerializer<IAgriStat>() {
@Override
public boolean accepts(Class<IAgriStat> clazz) {
return IAgriStat.class.isAssignableFrom(clazz);
}
@Override
public IMessageWriter<IAgriStat> getWriter(Class<IAgriStat> clazz) {
return (buf, data) -> {
NBTTagCompound tag = new NBTTagCompound();
data.writeToNBT(tag);
ByteBufUtil.writeNBT(buf, tag);
};
}
@Override
public IMessageReader<IAgriStat> getReader(Class<IAgriStat> clazz) {
return buf -> AgriApi.getStatRegistry().valueOf(ByteBufUtil.readNBT(buf)).get();
}
});
}
use of com.infinityraider.agricraft.api.v1.stat.IAgriStat in project AgriCraft by AgriCraft.
the class TileEntityCrop method addDisplayInfo.
@Override
public void addDisplayInfo(Consumer<String> information) {
// Add Soil Information
information.accept("Soil: " + this.getSoil().map(IAgriSoil::getName).orElse("Unknown"));
if (this.hasSeed()) {
// Fetch the plant.
final IAgriPlant plant = this.getSeed().getPlant();
// Fetch the stat.
final IAgriStat stat = this.getSeed().getStat();
//Add the SEED name.
information.accept(AgriCore.getTranslator().translate("agricraft_tooltip.seed") + ": " + plant.getSeedName());
//Add the GROWTH.
if (this.isMature()) {
information.accept(AgriCore.getTranslator().translate("agricraft_tooltip.growth") + ": " + AgriCore.getTranslator().translate("agricraft_tooltip.mature"));
} else {
information.accept(AgriCore.getTranslator().translate("agricraft_tooltip.growth") + ": " + (int) (100.0 * (this.getGrowthStage() + 1) / plant.getGrowthStages()) + "%");
}
//Add the ANALYZED data.
if (stat.isAnalyzed()) {
stat.addStats(information);
} else {
information.accept(AgriCore.getTranslator().translate("agricraft_tooltip.analyzed"));
}
//Add the fertility information.
information.accept(AgriCore.getTranslator().translate(this.isFertile() ? "agricraft_tooltip.fertile" : "agricraft_tooltip.notFertile"));
} else {
information.accept(AgriCore.getTranslator().translate("agricraft_tooltip.empty"));
}
}
use of com.infinityraider.agricraft.api.v1.stat.IAgriStat in project AgriCraft by AgriCraft.
the class MutateStrategy method executeStrategy.
@Override
public Optional<AgriSeed> executeStrategy(IAgriCrop crop, Random rand) {
// Validate the parameters.
Objects.requireNonNull(crop, "You cannot execute a mutation on a null crop!");
Objects.requireNonNull(rand, "The random passed to a mutation strategy should not be null!");
// Fetch all neighboring crop instances.
final List<IAgriCrop> neighbors = WorldHelper.getTileNeighbors(crop.getWorld(), crop.getPos(), IAgriCrop.class);
// Determine all possible parents.
final List<IAgriPlant> parents = neighbors.stream().filter(IAgriCrop::isMature).map(IAgriCrop::getSeed).filter(Objects::nonNull).map(AgriSeed::getPlant).collect(Collectors.toList());
// If we have less than two parents, might as well as abort.
if (parents.size() < 2) {
return Optional.empty();
}
// Determine the list of possible cross-over mutations.
final List<IAgriMutation> mutations = AgriApi.getMutationRegistry().stream().filter(m -> m.areParentsIn(parents)).filter(m -> crop.isFertile(m.getChild())).collect(Collectors.toList());
// If we didn't find any valid mutations, might as well as abort.
if (mutations.isEmpty()) {
return Optional.empty();
}
// Choose a random index in the list.
final int index = rand.nextInt(mutations.size());
// Fetch the chosen mutation from the list.
final IAgriMutation mutation = mutations.get(index);
// Determine if we should actually go through with this.
if (mutation.getChance() <= rand.nextDouble()) {
return Optional.empty();
}
// Calculate the stat associated with the new plant.
Optional<IAgriStat> stat = AgriApi.getStatCalculatorRegistry().valueOf(mutation).map(c -> c.calculateMutationStats(mutation, neighbors));
// Return the mutation result.
return stat.map(s -> new AgriSeed(mutation.getChild(), s));
}
Aggregations