Solved Not detecting block

Discussion in 'Plugin Development' started by Blackwing_Forged, Aug 26, 2017.

Thread Status:
Not open for further replies.
  1. Im trying to see if the player is looking at a chest, if so do something, this is what ive tried so far:

    Code:
    Block look = p.getTargetBlock((Set<Material>)null, 1);
    if(look instanceof Chest)
    {
            //Do something
    }
    Code:
    Block look = p.getEyeLocation().getBlock();
    if(look instanceof Chest)
    {
            //Do something
    }
    Code:
    Material look = p.getEyeLocation().getBlock().getType();
    if(look == Material.CHEST || look.equals(Material.CHEST))
    {
            //Do something
    }
    and its not working, if anyone can help that'd be great, thanks.
     
  2. Offline

    Zombie_Striker

    @Blackwing_Forged
    The first option was sort of correct; The 1 should have been replaced with a 6 (since that is the maximum distance bukkit will check for).
     
  3. @Zombie_Striker
    I changed it to this now and still isn't working

    Block look = p.getTargetBlock((Set<Material>)null, 6);

    Edit: It does work but now i have a new problem, how to I change the block to be a chest, i tried to do

    Chest c = (Chest) look;
    and it gives me this error:

    27.08 16:15:13 [Server] INFO Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_11_R1.block.CraftBlock cannot be cast to org.bukkit.block.Chest

    Edit: I fixed it, i forgot to do look.getState(); :/
     
    Last edited: Aug 27, 2017
  4. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page