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