Search in sources :

Example 1 with IAgriPlant

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()));
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) AgriMutation(com.agricraft.agricore.plant.AgriMutation) IAgriMutation(com.infinityraider.agricraft.api.v1.mutation.IAgriMutation) Mutation(com.infinityraider.agricraft.farming.mutation.Mutation) Nonnull(javax.annotation.Nonnull)

Example 2 with IAgriPlant

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());
    }
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) AgriPlant(com.agricraft.agricore.plant.AgriPlant)

Example 3 with IAgriPlant

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

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));
        }
    }
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState)

Example 5 with IAgriPlant

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

Aggregations

IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)32 ItemStack (net.minecraft.item.ItemStack)8 AgriSeed (com.infinityraider.agricraft.api.v1.seed.AgriSeed)7 Nonnull (javax.annotation.Nonnull)6 IAgriStat (com.infinityraider.agricraft.api.v1.stat.IAgriStat)5 PlantStats (com.infinityraider.agricraft.farming.PlantStats)5 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)4 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)3 IAgriMutation (com.infinityraider.agricraft.api.v1.mutation.IAgriMutation)3 IAgriGrowthRequirement (com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement)3 AgriMutation (com.agricraft.agricore.plant.AgriMutation)2 ImmutableList (com.google.common.collect.ImmutableList)2 IAgriJournalItem (com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem)2 IAgriGrowthStage (com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage)2 IAgriMutation (com.infinityraider.agricraft.api.v1.genetics.IAgriMutation)2 AgriPlantIngredient (com.infinityraider.agricraft.api.v1.plant.AgriPlantIngredient)2 IAgriWeed (com.infinityraider.agricraft.api.v1.plant.IAgriWeed)2 IAgriSoil (com.infinityraider.agricraft.api.v1.requirement.IAgriSoil)2 IAgriStatsMap (com.infinityraider.agricraft.api.v1.stat.IAgriStatsMap)2 BlockCropPlant (com.infinityraider.agricraft.content.core.BlockCropPlant)2