Solved Checking Wheat Growthstage

Discussion in 'Spigot Plugin Development' started by Geekenex, Apr 4, 2020.

Thread Status:
Not open for further replies.
  1. Hey! I am currently trying to make a feature where when you break a fully grown wheat with a hoe, the wheat is automatically replanted and the wheat goes into your inventory. However, in 1.15.2 I'm not finding a way to make an if statement checking the growth state of the wheat.
    It seems as if most methods I see online when researching are all deprecated.
    Anyone know how to properly do what I'm trying to make?
    Thanks.
     
  2. Code (Java):
    Ageable ageable = (Ageable) block.getBlockData();

    ageable.getAge();
     
  3. There are two ways.
    This one works for every crops (wheat, carrots, potatoes, etc.)
    Code (Java):
    event.getClickedBlock().getState().getData() instanceof Crops && ((Crops) event.getClickedBlock().getState().getData()).getState() == CropState.RIPE
    There other way is using the crops age
    Code (Java):
    if (event.getClickedBlock().getType() == Material.WHEAT)
            {
                final Ageable ageable = (Ageable) event.getClickedBlock().getState().getBlockData();
                if (ageable.getAge() != 7) return;
    As you can see, age 7 means it is fully grown.
     
    • Like Like x 1
  4. In addition to your self defined fully grown state.
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/Ageable.html#getMaximumAge--
     
    • Agree Agree x 1
  5. Thank you guys so much! It's greatly appreciated :)
     
Thread Status:
Not open for further replies.