Common API - Nyphet/harvest-with-ease GitHub Wiki

HarvestWithEaseAPI

In both Fabric and Forge the class HarvestWithEaseAPI is available.
It contains the following 2 methods:

  • isCrop(Block)
    Returns whether the given Block is a crop, meaning it is either a subclass of CropBlock, NetherWartBlock, CocoaBlock or its resource location is one of the items inside the crops property of this mod configuration file.
    If you have a BlockState instance you can easily retrieve the Block it derives from by calling BlockState#getBlock().
  • getAge(BlockState)
    Returns the IntegerProperty age of the given crop.
    Note that is can throw NullPointerException, NoSuchElementException or ClassCastException if it was not possible to find the age property in the given BlockState, so each time you call this method you should wrap it in a try and catch block, handle the error and allow Minecraft to keep running (avoid crashes at all costs!).
  • isTallCrop(Level, BlockState, BlockPos) Returns whether the given crop is a multi-block crop, which means a crop made of at least 2 vertically aligned blocks (e.g. Thermal Cultivation crops).