Search in sources :

Example 11 with AgriSeed

use of com.infinityraider.agricraft.api.v1.seed.AgriSeed 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 12 with AgriSeed

use of com.infinityraider.agricraft.api.v1.seed.AgriSeed in project AgriCraft by AgriCraft.

the class ItemTrowel method onItemUse.

// this is called when you right click with this item in hand
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitx, float hity, float hitz) {
    TileEntity te = world.getTileEntity(pos);
    if (te instanceof IAgriCrop) {
        IAgriCrop crop = (IAgriCrop) te;
        Optional<AgriSeed> seed = AgriApi.getSeedRegistry().valueOf(stack);
        if (crop.hasSeed() && !seed.isPresent()) {
            seed = Optional.ofNullable(crop.getSeed());
            crop.setSeed(null);
            if (seed.isPresent()) {
                NBTTagCompound tag = new NBTTagCompound();
                tag.setString(AgriNBT.SEED, seed.get().getPlant().getId());
                seed.get().getStat().writeToNBT(tag);
                stack.setTagCompound(tag);
                stack.setItemDamage(1);
                return EnumActionResult.SUCCESS;
            } else {
                return EnumActionResult.FAIL;
            }
        } else if (seed.isPresent() && !crop.hasSeed()) {
            if (crop.setSeed(seed.get())) {
                stack.setTagCompound(new NBTTagCompound());
                stack.setItemDamage(0);
                return EnumActionResult.SUCCESS;
            } else {
                return EnumActionResult.FAIL;
            }
        }
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed)

Example 13 with AgriSeed

use of com.infinityraider.agricraft.api.v1.seed.AgriSeed in project AgriCraft by AgriCraft.

the class TileEntityCrop method setSeed.

@Override
public boolean setSeed(AgriSeed seed) {
    final AgriSeed oldSeed = this.seed;
    this.seed = seed;
    this.markForUpdate();
    return this.seed != oldSeed;
}
Also used : AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed)

Example 14 with AgriSeed

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

Example 15 with AgriSeed

use of com.infinityraider.agricraft.api.v1.seed.AgriSeed in project AgriCraft by AgriCraft.

the class TileEntityCrop method spawn.

// =========================================================================
// IWeedable Methods
// =========================================================================
@Override
public boolean spawn() {
    // If in remote world, abort!
    if (this.isRemote()) {
        return false;
    }
    // If already have plant, abort!
    if (this.hasSeed()) {
        return false;
    }
    // Attempt to spawn plant.
    for (IAgriPlant p : AgriApi.getPlantRegistry().all()) {
        if (p.getSpawnChance() > this.getRandom().nextDouble() && this.isFertile(p)) {
            this.setCrossCrop(false);
            this.setSeed(new AgriSeed(p, new PlantStats()));
            return true;
        }
    }
    // The operation was a failure.
    return false;
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed) PlantStats(com.infinityraider.agricraft.farming.PlantStats)

Aggregations

AgriSeed (com.infinityraider.agricraft.api.v1.seed.AgriSeed)18 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)8 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)6 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)5 Optional (java.util.Optional)5 IAgriStat (com.infinityraider.agricraft.api.v1.stat.IAgriStat)4 PlantStats (com.infinityraider.agricraft.farming.PlantStats)4 List (java.util.List)4 TileEntity (net.minecraft.tileentity.TileEntity)4 ItemStack (net.minecraft.item.ItemStack)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 IAgriCrossStrategy (com.infinityraider.agricraft.api.v1.mutation.IAgriCrossStrategy)2 AgriCraftConfig (com.infinityraider.agricraft.reference.AgriCraftConfig)2 WorldHelper (com.infinityraider.infinitylib.utility.WorldHelper)2 Random (java.util.Random)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Side (net.minecraftforge.fml.relauncher.Side)2 AgriCore (com.agricraft.agricore.core.AgriCore)1 IAgriAdapter (com.infinityraider.agricraft.api.v1.adapter.IAgriAdapter)1 IAgriFertilizer (com.infinityraider.agricraft.api.v1.fertilizer.IAgriFertilizer)1