event.getHitBlock() is always null

Discussion in 'Spigot Help' started by LeCanadienAlexo, Feb 8, 2020.

  1. Hi! So I'm trying to create a potion that will transform blocks in the area to something else depending on what it landed on.

    But I can't seem to get the block it landed on correctly, in the current instance, I'm looking at the PotionSplashEvent, the event always return null to a event.getHitBlock call.

    The only solution I've found that I really don't like is looking at the block under the potion, but there's a million cases where that's not the good way to go, like when the potion hits on the side of a block.. or when the potion hits the ground too fast, in which case the landing location is offsetted compared to the real location

    what's the best way to achieve that simple block it landed on check?
     
  2. *sad bump noises*
     
    • Funny Funny x 1
  3. I believe the PotionSplashEvent is purely for getting entities that the potion would affect when it 'Splashes'

    I you use a ProjectileHitEvent you can then use getHitBlock() or gethitBlockFace() for the block or blockface the projectile landed on. I believe throw-able potions do count as projectiles, therefore, this will be your solution.