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