Search in sources :

Example 1 with PlantStats

use of com.infinityraider.agricraft.farming.PlantStats in project AgriCraft by AgriCraft.

the class JsonPlant method getSeed.

@Override
public final ItemStack getSeed() {
    ItemStack stack = this.getSeedItems().stream().map(s -> s.toStack()).findFirst().orElse(new ItemStack(AgriItems.getInstance().AGRI_SEED));
    NBTTagCompound tag = new NBTTagCompound();
    tag.setString(AgriNBT.SEED, this.getId());
    new PlantStats().writeToNBT(tag);
    stack.setTagCompound(tag);
    return stack;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) PlantStats(com.infinityraider.agricraft.farming.PlantStats)

Example 2 with PlantStats

use of com.infinityraider.agricraft.farming.PlantStats in project AgriCraft by AgriCraft.

the class StatCalculatorBase method calculateSpreadStats.

@Override
public IAgriStat calculateSpreadStats(IAgriPlant child, Collection<IAgriCrop> parents) {
    // Validate parameters.
    Objects.requireNonNull(child, "The child plant to calculate the stats for must not be null!");
    Objects.requireNonNull(parents, "The set of parents to calculate the child's stats from must not be null!");
    // Variables
    int invalidParents = 0;
    int validParents = 0;
    int growth = 0;
    int gain = 0;
    int strength = 0;
    // Sum values
    for (IAgriCrop parent : parents) {
        // Skip parent if null.
        if (parent == null) {
            continue;
        }
        // Fetch the seed associated with the parent.
        final AgriSeed parentSeed = parent.getSeed();
        // Skip if parent seed is null.
        if (parentSeed == null) {
            continue;
        }
        // If the parent is not mature, counts as invalid parent.
        if (!parent.isMature()) {
            invalidParents++;
            continue;
        }
        // If the parent plant does not match the child plant, invalid parent.
        if (!Objects.equals(child, parentSeed.getPlant())) {
            invalidParents++;
            continue;
        }
        // Otherwise everything is aok.
        validParents++;
        growth += parentSeed.getStat().getGrowth();
        gain += parentSeed.getStat().getGain();
        strength += parentSeed.getStat().getStrength();
    }
    // Determine the stat divisor.
    final int meanDivisor = calculateStatMeanDivisor(validParents, invalidParents);
    // Perform averages.
    growth = growth / meanDivisor;
    gain = gain / meanDivisor;
    strength = strength / meanDivisor;
    // Return the new plant stat.
    return new PlantStats(calculateStat(growth, validParents, 1), calculateStat(gain, validParents, 1), calculateStat(strength, validParents, 1));
}
Also used : IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed) PlantStats(com.infinityraider.agricraft.farming.PlantStats)

Example 3 with PlantStats

use of com.infinityraider.agricraft.farming.PlantStats in project AgriCraft by AgriCraft.

the class StatCalculatorBase method calculateMutationStats.

@Override
public IAgriStat calculateMutationStats(IAgriMutation mutation, Collection<IAgriCrop> parents) {
    // Validate parameters.
    Objects.requireNonNull(mutation, "The mutation to calculate the stats for must not be null!");
    Objects.requireNonNull(parents, "The set of parents to calculate the mutation result stats from must not be null!");
    // Variables
    int invalidParents = 0;
    int validParents = 0;
    int growth = 0;
    int gain = 0;
    int strength = 0;
    // Sum values
    for (IAgriCrop parent : parents) {
        // Skip parent if null.
        if (parent == null) {
            continue;
        }
        // Fetch the seed associated with the parent.
        final AgriSeed parentSeed = parent.getSeed();
        // Skip if parent seed is null.
        if (parentSeed == null) {
            continue;
        }
        // If the parent is not mature, counts as invalid parent.
        if (!parent.isMature()) {
            invalidParents++;
            continue;
        }
        // If the parent plant does not match the child plant, invalid parent.
        if (!mutation.hasParent(parentSeed.getPlant())) {
            invalidParents++;
            continue;
        }
        // Otherwise everything is aok.
        validParents++;
        growth += parentSeed.getStat().getGrowth();
        gain += parentSeed.getStat().getGain();
        strength += parentSeed.getStat().getStrength();
    }
    // Determine the stat divisor.
    final int meanDivisor = calculateStatMeanDivisor(validParents, invalidParents);
    // Perform averages.
    growth = growth / meanDivisor;
    gain = gain / meanDivisor;
    strength = strength / meanDivisor;
    // Return the new plant stat.
    return new PlantStats(calculateStat(growth, validParents, AgriCraftConfig.cropStatDivisor), calculateStat(gain, validParents, AgriCraftConfig.cropStatDivisor), calculateStat(strength, validParents, AgriCraftConfig.cropStatDivisor));
}
Also used : IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed) PlantStats(com.infinityraider.agricraft.farming.PlantStats)

Example 4 with PlantStats

use of com.infinityraider.agricraft.farming.PlantStats in project AgriCraft by AgriCraft.

the class SeedWrapper method resolve.

private AgriSeed resolve(ItemStack stack) {
    if (!StackHelper.isValid(stack)) {
        return null;
    }
    final FuzzyStack toResolve = new FuzzyStack(stack);
    Optional<IAgriPlant> plant = AgriApi.getPlantRegistry().all().stream().filter(p -> p.getSeedItems().contains(toResolve)).findFirst();
    if (plant.isPresent()) {
        Optional<IAgriStat> stats = AgriApi.getStatRegistry().valueOf(stack.getTagCompound());
        return new AgriSeed(plant.get(), stats.orElseGet(PlantStats::new));
    } else {
        return null;
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) IAgriAdapter(com.infinityraider.agricraft.api.v1.adapter.IAgriAdapter) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed) PlantStats(com.infinityraider.agricraft.farming.PlantStats) Optional(java.util.Optional) FuzzyStack(com.infinityraider.agricraft.api.v1.util.FuzzyStack) StackHelper(com.infinityraider.agricraft.utility.StackHelper) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) FuzzyStack(com.infinityraider.agricraft.api.v1.util.FuzzyStack) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed)

Example 5 with PlantStats

use of com.infinityraider.agricraft.farming.PlantStats in project AgriCraft by AgriCraft.

the class ItemAgriSeed method getSubItems.

@Override
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list) {
    final PlantStats baseStat = new PlantStats();
    for (IAgriPlant plant : AgriApi.getPlantRegistry().all()) {
        if (plant.getSeedItems().stream().anyMatch(s -> s.isItemEqual(this))) {
            ItemStack stack = new ItemStack(item);
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString(AgriNBT.SEED, plant.getId());
            baseStat.writeToNBT(tag);
            stack.setTagCompound(tag);
            list.add(stack);
        }
    }
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) PlantStats(com.infinityraider.agricraft.farming.PlantStats)

Aggregations

PlantStats (com.infinityraider.agricraft.farming.PlantStats)7 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)4 AgriSeed (com.infinityraider.agricraft.api.v1.seed.AgriSeed)4 ItemStack (net.minecraft.item.ItemStack)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)2 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)1 IAgriAdapter (com.infinityraider.agricraft.api.v1.adapter.IAgriAdapter)1 IAgriStat (com.infinityraider.agricraft.api.v1.stat.IAgriStat)1 FuzzyStack (com.infinityraider.agricraft.api.v1.util.FuzzyStack)1 StackHelper (com.infinityraider.agricraft.utility.StackHelper)1 Optional (java.util.Optional)1