Common API - Crystal-Nest/harvest-with-ease GitHub Wiki
In both Fabric and Forge the class HarvestWithEaseAPI
is available.
It contains the following methods:
-
isCrop(Block)
Returns whether the givenBlock
is a crop, meaning it is either a subclass ofCropBlock
,NetherWartBlock
,CocoaBlock
or its resource location is one of the items inside the crops property of this mod configuration file.
If you have aBlockState
instance you can easily retrieve theBlock
it derives from by callingBlockState#getBlock()
. -
getAge(BlockState)
Returns theIntProperty
age of the given crop.
Note that is can throwNullPointerException
,NoSuchElementException
orClassCastException
if it was not possible to find the age property in the givenBlockState
, 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!). -
isMature(BlockState)
/isMature(BlockState, IntProperty)
Returns whether the given crop is a mature crop by checking itsage
property against the givenage
property. When noage
property is provided, the one present in the givenBlockState
is used instead. -
isTallCrop(World, 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). -
isTierForMultiHarvest(TieredItem)
Returns whether the given tool has an high enough tier for multi-harvest.
Note: this method only checks the tool tier, but does not check whether the tool is a hoe. -
isTierIn(List<Tier>, String)
/isTierIn(List<Tier>, ResourceLocation)
/isTierIn(List<Tier>, Tier)
Returns whether the givenTier
is in the given list of tiers.
Note: theResourceLocation
overload is available only on Forge/NeoForge. -
getTierLevel(Tier)
/getTierLevel(ResourceLocation)
/getTierLevel(String)
Returns the level of the givenTier
.
Note: theResourceLocation
overload is available only on Forge/NeoForge. -
matchesTier(String, Tier)
Returns whether the givenString
matches the givenTier
.