Detect what block is under the chicken

Discussion in 'Plugin Development' started by PistoFrancoPuumm, Jul 17, 2016.

Thread Status:
Not open for further replies.
  1. Hello, i've found some issues trying to detect what block is under the chicken.
    i've got this, but (if) cannot parse Entity to Material... (obiously)

    now that's my code...

    Code:
    public class RunnableChikn extends BukkitRunnable {
    @Overridepublic void run() {
    for (Player player : Bukkit.getOnlinePlayers()) {
    Chicken chicken = (Chicken)player.getLocation().getBlock().getRelative(BlockFace.DOWN); if (chicken.getType() != Material.STAINED_CLAY);}
    }
    }
    
    I didn't know how to detect what block is under him... can you help me? thank you!
     
  2. @PistoFrancoPuumm
    You cannot cast Chicken to Block! Also Bukkit.getOnlinePlayers() returns players! Not Chickens! Instead what you need to do is loop through
    Code:
    World.getEntities()
    and check if the entity is a chicken, and then subtract one on the y value of its position.
     
    Last edited: Jul 17, 2016
  3. Rayzr522 and CodePlaysMinecraft like this.
  4. Offline

    mine-care

    How does the chicken relate to the code above?
     
    Rayzr522 likes this.
  5. i need to detect if the chicken is on the ground, then kill him and add a score

    i want to get if chicken is in STAINED_CLAY then kill him

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 17, 2016
  6. Offline

    I Al Istannen

    @PistoFrancoPuumm
    Entity#isOnGround()?

    Now, your last message came through.
    In this case you will need to get the block at "Chicken#getLocation()#subtract(0,1,0)#getBlock()#getType()".
    Chicken#getLocation() ==> The loation
    Location#subtract(0, 1, 0) ==> The block one below, as the second is the y axis
    Location#getBlock() ==> The block at the location
    Block#getType() ==> The Material of a Block

    This won't work if the chicken stands on the edge of a single clay block floating in the air, but fixing this could become quite annoying.
     
    bwfcwalshy and mine-care like this.
  7. Offline

    Firestar311

    First you need this method then use the instanceof statement to check to see if the Entity is a Chicken, Then you can set the chicken and use the above methods from @I Al Istannen
     
Thread Status:
Not open for further replies.

Share This Page