How do I get the direction a dispenser is facing?

Discussion in 'Plugin Development' started by MrSnare, Mar 22, 2013.

  1. I was using this code pre-1.5 but it just returns EAST for every direction now. So im looking for another way.

    PHP:
    1.             MaterialData d = block.getState().getData();
    2.             Dispenser disp = (Dispenser) d;
    3.             BlockFace face = disp.getFacing();
     
  2. I also need a work around :(
     
  3. For now
    you can do it yourself

    put a dispenser in world and make a temporary way to get its data value
    then compare them for the directions and make a case statement like this

    code

    (keep in mind thos values are probably horribly wrong becasue I am just demonstrating my idea
    etc.
     
  4. my bad i didnt read the bug repoert properly

    i thought it was the same bug as that all the directions are were wrong all the time beforehand.
     
  5. I got a dirty fix thats mostly working.

    Code:java
    1.  
    2. Dispenser disp = (Dispenser) event.getBlock().getState().getData();
    3.  
    4. BlockFace face = disp.getFacing();
    5.  
    6.  
    7. if (face == BlockFace.EAST){ //temp fix
    8.  
    9.  
    10. if( event.getBlock().getData() == 8) face = BlockFace.DOWN;
    11. if( event.getBlock().getData() == 9) face = BlockFace.UP;
    12. if( event.getBlock().getData() == 10) face = BlockFace.NORTH;
    13. if( event.getBlock().getData() == 11) face = BlockFace.SOUTH;
    14. if( event.getBlock().getData() == 12) face = BlockFace.WEST;
    15. if( event.getBlock().getData() == 13) face = BlockFace.EAST;
    16.  
    17. if( event.getBlock().getData() < 8 || event.getBlock().getData() > 13)
    18. Smart_Items.info("New Direction! " +event.getBlock().getData());
    19.  
    20. }
    21.  
    22. Block target = event.getBlock().getRelative(face);
    23.  



    Every so often I get a "New Direction! 0" in the log i think the values are different for unpowerd.
     
    MrSnare likes this.

Share This Page