1.15.2 How to check crop growth level?

Discussion in 'Spigot Plugin Development' started by Msql, Mar 4, 2020.

  1. How to check crop growth level in 1.15?
    In 1.13 I was getting data value of block and it was returning 0-7 but now I have noticed that data value of crop in any growth level is always 0 :/
  2. Code (Java):
  3. Oh so to retrieve crop growth you have to cast the block data to ageable

    Code (Java):
    Ageable ageable = (Ageable) event.getBlock().getBlockData()

    • Useful Useful x 1
  4. Up from which version it is required to get block age like this?
  5. 1.13 and onwards I believe, 1.12 and below involved casting material data to crops
  6. Unlucky, Ageable is not solution for my problem.
    Code (Java):
    event.getBlock().getBlockData() instanceof Ageable
    never returns true. Tried with all possible crops.
    Also, in javadoc:
    it is described as:
    Code (Text):
    public interface Ageable extends Creature
    Represents an entity that can age and breed.
  7. You imported wrong Ageable

    • Agree Agree x 1
  8. FrostedSnowman

    Resource Staff

    That's the wrong Ageable :). You're looking for org.bukkit.block.data.Ageable


    • Agree Agree x 2
  9. Nevermind, I did bad import.
    There are two Ageable interfaces (org.bukkit.entity.Ageable) and (org.bukkit.block.data.Ageable). I will try with block one and I will post results.

    Edit: Wow, we all posted in exactly same moment :x
  10. Snippet
    Code (Text):
     Location cord= new Location(center.getWorld(), x, min.getY(), z);
                    Block block = cord.getBlock();
                    if(block.getBlockData() instanceof Ageable) {
                        if(block.getType() != Material.FROSTED_ICE) {
                            Ageable ab = (Ageable) block.getBlockData();
                            if(ab.getAge() == ab.getMaximumAge()) {
                                Block pchest = block.getWorld().getBlockAt(center.getBlockX(),center.getBlockY()+1,center.getBlockZ());
                                Chest chest = (Chest) pchest.getState();
                                if(pchest.getType() == Material.CHEST) {
                                    if(block.getType() == Material.WHEAT) {
                                        addToChest(chest,new ItemStack(Material.WHEAT,3));
                                    }else {
                                        if(block.getType() == Material.CARROTS) {
                                            addToChest(chest,new ItemStack(Material.CARROT,3));
                                        else {
                                            if(block.getType() == Material.POTATOES) {
                                                addToChest(chest,new ItemStack(Material.POTATO,3));