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;
}
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;
}
Aggregations