Search in sources :

Example 6 with IAgriPlant

use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.

the class AgriMutationRegistry method add.

@Override
public boolean add(@Nonnull String id, double chance, @Nonnull String childId, @Nonnull List<String> parentIds) {
    // Step I. Validate Parameters.
    Objects.requireNonNull(id, "The id of a mutation may not be null!");
    Objects.requireNonNull(childId, "The id of the child plant for a mutation may not be null!");
    Objects.requireNonNull(parentIds, "The supplied list of parents for a mutation may not be null!");
    // Step II. Validate Parents.
    parentIds.forEach(parentId -> Objects.requireNonNull(parentId, "The id of a parent for a mutation may not be null!"));
    // Step III. Map Child.
    final IAgriPlant childPlant = AgriApi.getPlantRegistry().get(id).orElse(null);
    // Step IV. Abort If Child Missing.
    if (childPlant == null) {
        // We tried, so don't throw error, just return false.
        return false;
    }
    // Step V. Allocate Parent Plant List.
    final List<IAgriPlant> parentPlants = new ArrayList<>(parentIds.size());
    // Step VI. Map Parents, Aborting If Missing.
    for (String parentId : parentIds) {
        final IAgriPlant parentPlant = AgriApi.getPlantRegistry().get(parentId).orElse(null);
        if (parentPlant != null) {
            parentPlants.add(parentPlant);
        } else {
            return false;
        }
    }
    // Step VII. Create the new mutation.
    final IAgriMutation mutation = new Mutation(id, chance, childPlant, parentPlants);
    // Step VIII. Register the new muation.
    return this.add(mutation);
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) ArrayList(java.util.ArrayList) IAgriMutation(com.infinityraider.agricraft.api.v1.mutation.IAgriMutation) IAgriMutation(com.infinityraider.agricraft.api.v1.mutation.IAgriMutation) Mutation(com.infinityraider.agricraft.farming.mutation.Mutation)

Example 7 with IAgriPlant

use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.

the class ItemAgriSeed method getAllTextures.

@Override
@SideOnly(Side.CLIENT)
public List<ResourceLocation> getAllTextures() {
    final Collection<IAgriPlant> plants = AgriApi.getPlantRegistry().all();
    final List<ResourceLocation> textures = new ArrayList<>(plants.size());
    textures.add(new ResourceLocation("agricraft:items/seed_unknown"));
    for (IAgriPlant p : AgriApi.getPlantRegistry().all()) {
        textures.add(p.getSeedTexture());
    }
    return textures;
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 8 with IAgriPlant

use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.

the class TileEntityCrop method readTileNBT.

@Override
public void readTileNBT(@Nonnull NBTTagCompound tag) {
    Preconditions.checkNotNull(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 9 with IAgriPlant

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

Example 10 with IAgriPlant

use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.

the class TileEntityCrop method spread.

@Override
public boolean spread() {
    // If remote, abort.
    if (this.isRemote()) {
        return false;
    }
    // Fetch the seed;
    final AgriSeed seed = this.getSeed();
    // If don't have plant, abort.
    if (seed == null) {
        return false;
    }
    final IAgriPlant plant = seed.getPlant();
    // If don't roll a spread event, abort.
    if (plant.getSpreadChance() <= this.getRandom().nextDouble()) {
        for (IAgriCrop crop : WorldHelper.getTileNeighbors(worldObj, pos, IAgriCrop.class)) {
            final AgriSeed other = crop.getSeed();
            if (other == null) {
                if (!crop.isCrossCrop()) {
                    crop.setSeed(seed);
                    return true;
                }
            } else if (canOvertake(seed, other, this.getRandom())) {
                crop.setCrossCrop(false);
                crop.setSeed(seed);
                return true;
            }
        }
    }
    // The spreading failed.
    return false;
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed)

Aggregations

IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)15 AgriSeed (com.infinityraider.agricraft.api.v1.seed.AgriSeed)7 IAgriStat (com.infinityraider.agricraft.api.v1.stat.IAgriStat)5 PlantStats (com.infinityraider.agricraft.farming.PlantStats)5 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)3 IAgriMutation (com.infinityraider.agricraft.api.v1.mutation.IAgriMutation)3 ItemStack (net.minecraft.item.ItemStack)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)2 Mutation (com.infinityraider.agricraft.farming.mutation.Mutation)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 AgriMutation (com.agricraft.agricore.plant.AgriMutation)1 AgriPlant (com.agricraft.agricore.plant.AgriPlant)1 IAgriAdapter (com.infinityraider.agricraft.api.v1.adapter.IAgriAdapter)1 IAgriCrossStrategy (com.infinityraider.agricraft.api.v1.mutation.IAgriCrossStrategy)1 FuzzyStack (com.infinityraider.agricraft.api.v1.util.FuzzyStack)1 AgriCraftConfig (com.infinityraider.agricraft.reference.AgriCraftConfig)1 StackHelper (com.infinityraider.agricraft.utility.StackHelper)1 WorldHelper (com.infinityraider.infinitylib.utility.WorldHelper)1