1.17.x Check whether there are up to x blocks above the player

Discussion in 'Spigot Plugin Development' started by Gaming12846, Jul 17, 2021.

  1. Hello Community,

    I want to check if there are x blocks above the player. I already got it working to check if there are blocks up to the maximum height
    Code (Java):
    if (target.getLocation().getBlockY() < target.getWorld().getHighestBlockYAt(target.getLocation())) {}
    But I just want to check if there are x blocks above the player. I allready tried
    Code (Java):
    if (target.getLocation().getBlockY() < target.getLocation().getBlockY() + x) {}
    and tried it with a while loop.

    Yes, I know that I have to substitute a number for x.


    Thanks in advance
     
  2. Fix:
    Code (Java):
    if (target.getLocation().getBlockY() < target.getLocation()[B][U].clone()[/U][/B].add(0, x, 0).getBlockY()) {}
    Remember that Location#add doesn't return a new Location after adding the values - it changes the values of the existing one then returns itself.
    This can cause MAJOR issues if you're not careful, so always clone a Location before changing it!