Search in sources :

Example 1 with IAgriStat

use of com.infinityraider.agricraft.api.v1.stat.IAgriStat in project AgriCraft by AgriCraft.

the class ItemAgriSeed method valueOf.

@Override
public Optional<AgriSeed> valueOf(Object obj) {
    NBTTagCompound tag = NBTHelper.asTag(obj);
    if (tag == null) {
        return Optional.empty();
    }
    IAgriPlant plant = AgriApi.getPlantRegistry().get(tag.getString(AgriNBT.SEED)).orElse(null);
    IAgriStat stat = AgriApi.getStatRegistry().valueOf(tag).orElse(null);
    if (plant != null && stat != null) {
        return Optional.of(new AgriSeed(plant, stat));
    } else {
        return Optional.empty();
    }
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed)

Example 2 with IAgriStat

use of com.infinityraider.agricraft.api.v1.stat.IAgriStat 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 IAgriStat

use of com.infinityraider.agricraft.api.v1.stat.IAgriStat 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 IAgriStat

use of com.infinityraider.agricraft.api.v1.stat.IAgriStat in project AgriCraft by AgriCraft.

the class TileEntityCrop method readTileNBT.

@Override
public void readTileNBT(NBTTagCompound tag) {
    final IAgriStat stat = AgriApi.getStatRegistry().valueOf(tag).orElse(null);
    final IAgriPlant plant = AgriApi.getPlantRegistry().get(tag.getString(AgriNBT.SEED)).orElse(null);
    if (stat != null && plant != null) {
        this.seed = new AgriSeed(plant, stat);
    } else {
        this.seed = null;
    }
    this.growthStage = tag.getInteger(AgriNBT.META);
    this.crossCrop = tag.getBoolean(AgriNBT.CROSS_CROP);
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriStat(com.infinityraider.agricraft.api.v1.stat.IAgriStat) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed)

Example 5 with IAgriStat

use of com.infinityraider.agricraft.api.v1.stat.IAgriStat 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)

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