use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.
the class JsonHelper method wrap.
@Nonnull
public static Optional<IAgriMutation> wrap(@Nullable AgriMutation mutation) {
// Step I. Abort If Null Mutation.
if (mutation == null) {
return Optional.empty();
}
// Step II. Determine Chance.
final double chance = mutation.getChance();
// Step III. Determine ID.
final String mutationId = mutation.getChild().getId().replace("_plant", "_mutation");
// Step IV. Determine Child.
final Optional<IAgriPlant> child = AgriApi.getPlantRegistry().get(mutation.getChild().getId());
// Step V. Abort If Child Missing.
if (!child.isPresent()) {
return Optional.empty();
}
// Step VI. Determine Parents.
final Optional<IAgriPlant> parentOne = AgriApi.getPlantRegistry().get(mutation.getParent1().getId());
final Optional<IAgriPlant> parentTwo = AgriApi.getPlantRegistry().get(mutation.getParent2().getId());
// Step VII. Abort If Missing Parent.
if ((!parentOne.isPresent()) && (!parentTwo.isPresent())) {
return Optional.empty();
}
// Step VIII. Create New Mutation
return Optional.of(new Mutation(mutationId, chance, child.get(), parentOne.get(), parentTwo.get()));
}
use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.
the class CoreHandler method initPlants.
public static void initPlants() {
// Announce Progress
AgriCore.getLogger("agricraft").info("Registering Plants!");
// See if plants are valid...
final int raw = AgriCore.getPlants().getAll().size();
AgriCore.getPlants().validate();
final int count = AgriCore.getPlants().getAll().size();
// Transfer
AgriCore.getPlants().validate();
AgriCore.getPlants().getAll().stream().filter(AgriPlant::isEnabled).map(JsonPlant::new).forEach(AgriApi.getPlantRegistry()::add);
// Display Plants
AgriCore.getLogger("agricraft").info("Registered Plants ({0}/{1}):", count, raw);
for (IAgriPlant plant : AgriApi.getPlantRegistry().all()) {
AgriCore.getLogger("agricraft").info(" - {0}", plant.getPlantName());
}
}
use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant 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.plant.IAgriPlant in project AgriCraft by AgriCraft.
the class RenderCrop method renderWorldBlockStatic.
@Override
public void renderWorldBlockStatic(ITessellator tessellator, IBlockState state, BlockCrop block, EnumFacing side) {
TextureAtlasSprite sprite = RenderCrop.getIcon(TEXTURE);
this.renderBaseQuads(tessellator, side, sprite);
if (state instanceof IExtendedBlockState) {
IExtendedBlockState extendedState = (IExtendedBlockState) state;
IAgriPlant plant = extendedState.getValue(AgriProperties.CROP_PLANT);
int growthstage = extendedState.getValue(AgriProperties.GROWTH_STAGE);
if (extendedState.getValue(AgriProperties.CROSS_CROP)) {
tessellator.drawScaledPrism(0, 10, 2, 16, 11, 3, sprite);
tessellator.drawScaledPrism(0, 10, 13, 16, 11, 14, sprite);
tessellator.drawScaledPrism(2, 10, 0, 3, 11, 16, sprite);
tessellator.drawScaledPrism(13, 10, 0, 14, 11, 16, sprite);
}
if (plant != null) {
tessellator.addQuads(plant.getPlantQuads(extendedState, growthstage, side, tessellator));
}
}
}
use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant 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();
}
}
Aggregations