Search in sources :

Example 6 with IAgriStat

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();
        }
    });
}
Also used : IMessageWriter(com.infinityraider.infinitylib.network.serialization.IMessageWriter) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMessageReader(com.infinityraider.infinitylib.network.serialization.IMessageReader)

Example 7 with IAgriStat

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"));
    }
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat)

Example 8 with IAgriStat

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));
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) IAgriCrossStrategy(com.infinityraider.agricraft.api.v1.mutation.IAgriCrossStrategy) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) Random(java.util.Random) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) AgriCraftConfig(com.infinityraider.agricraft.reference.AgriCraftConfig) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed) IAgriMutation(com.infinityraider.agricraft.api.v1.mutation.IAgriMutation) WorldHelper(com.infinityraider.infinitylib.utility.WorldHelper) Optional(java.util.Optional) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) Objects(java.util.Objects) IAgriMutation(com.infinityraider.agricraft.api.v1.mutation.IAgriMutation) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed)

Aggregations

AgriSeed (com.infinityraider.agricraft.api.v1.seed.AgriSeed)6 IAgriStat (com.infinityraider.agricraft.api.v1.stat.IAgriStat)6 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)5 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)3 PlantStats (com.infinityraider.agricraft.farming.PlantStats)3 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)2 Optional (java.util.Optional)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 IAgriAdapter (com.infinityraider.agricraft.api.v1.adapter.IAgriAdapter)1 IAgriCrossStrategy (com.infinityraider.agricraft.api.v1.mutation.IAgriCrossStrategy)1 IAgriMutation (com.infinityraider.agricraft.api.v1.mutation.IAgriMutation)1 FuzzyStack (com.infinityraider.agricraft.api.v1.util.FuzzyStack)1 AgriCraftConfig (com.infinityraider.agricraft.reference.AgriCraftConfig)1 StackHelper (com.infinityraider.agricraft.utility.StackHelper)1 IMessageReader (com.infinityraider.infinitylib.network.serialization.IMessageReader)1 IMessageWriter (com.infinityraider.infinitylib.network.serialization.IMessageWriter)1 WorldHelper (com.infinityraider.infinitylib.utility.WorldHelper)1 List (java.util.List)1 Objects (java.util.Objects)1 Random (java.util.Random)1