Search in sources :

Example 1 with MethodResult

use of com.infinityraider.agricraft.api.v1.util.MethodResult in project AgriCraft by AgriCraft.

the class AgriCraftFarmerBehavior method tryHarvestPlant.

@Override
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer) {
    // Attempt to resolve crops instance.
    final Optional<IAgriCrop> agriCrop = WorldHelper.getTile(world, pos, IAgriCrop.class);
    // If crops are there, do the thing.
    if (agriCrop.isPresent()) {
        // Ensure enough energy.
        if (farmer.getEnergy() < ActuallyAdditionsPlugin.ENERGY_COST) {
            return FarmerResult.STOP_PROCESSING;
        }
        final List<ItemStack> products = new ArrayList<>();
        final MethodResult result = agriCrop.get().onHarvest(products::add, null);
        if (result == MethodResult.SUCCESS) {
            farmer.extractEnergy(ActuallyAdditionsPlugin.ENERGY_COST);
            farmer.addToOutputInventory(products, true);
            return FarmerResult.SUCCESS;
        }
    }
    // Otherwise fail.
    return FarmerResult.FAIL;
}
Also used : IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) MethodResult(com.infinityraider.agricraft.api.v1.util.MethodResult)

Example 2 with MethodResult

use of com.infinityraider.agricraft.api.v1.util.MethodResult in project AgriCraft by AgriCraft.

the class AgriCraftFarmerBehavior method tryPlantSeed.

@Override
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer) {
    // Attempt to resolve seed and crops instance.
    final Optional<AgriSeed> agriSeed = AgriApi.getSeedRegistry().valueOf(seed);
    final Optional<IAgriCrop> agriCrop = WorldHelper.getTile(world, pos, IAgriCrop.class);
    // If both are there, attempt to plant.
    if (agriSeed.isPresent() && agriCrop.isPresent()) {
        // Ensure enough energy.
        if (farmer.getEnergy() < ActuallyAdditionsPlugin.ENERGY_COST) {
            return FarmerResult.STOP_PROCESSING;
        }
        final MethodResult result = agriCrop.get().onApplySeeds(agriSeed.get(), null);
        if (result == MethodResult.SUCCESS) {
            farmer.extractEnergy(250);
            return FarmerResult.SUCCESS;
        }
    }
    // Otherwise fail.
    return FarmerResult.FAIL;
}
Also used : IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed) MethodResult(com.infinityraider.agricraft.api.v1.util.MethodResult)

Aggregations

IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)2 MethodResult (com.infinityraider.agricraft.api.v1.util.MethodResult)2 AgriSeed (com.infinityraider.agricraft.api.v1.seed.AgriSeed)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1