Get dispenser face

Discussion in 'Plugin Development' started by Someone_Like_You, Mar 12, 2014.

Thread Status:
Not open for further replies.
  1. How can I get dispenser face? All Im getting from BlockFace is "SELF"....
     
  2. Offline

    Maurdekye

    You'd need to parse the block's metadata value, and determine the face yourself.
     
  3. Maurdekye Its always return 3, no matter how I placed the block itself.... :/
     
  4. Offline

    Garris0n

    BlockFace is used for getting relative blocks. You're looking for Directional.
     
    Someone_Like_You likes this.
  5. Garris0n Thanks, no idea how to cast it tho...
    Dropper d = (Dropper) e.getBlock().getState();
    BlockFace bf = d.getFacing();
    :/
     
  6. Offline

    Garris0n

    It's MaterialData, you get it from BlockState.getData().
     
    Someone_Like_You likes this.
  7. Garris0n Still, no success :/
    Dropper d = (Dropper) e.getBlock().getState();
    BlockState bf = d.getData().getFacing();
    EDIT: working thanks! :)
     
  8. Offline

    Garris0n

    I see you solved it, but for the sake of archives, the first one is a BlockState and the second one is a Dropper.
     
    Someone_Like_You likes this.
  9. Garris0n How do I get up and down direction? Cant get it :/ only return south
     
  10. Offline

    Garris0n

    Can you post the code you have?
     
  11. Garris0n I have to cancel the event if the dropper facing up/down, and afterwards, getting the direction of it..
    Code:java
    1. @EventHandler
    2. public void onDropperPlace(BlockPlaceEvent e){
    3. if(e.getPlayer().getItemInHand() != null && e.getPlayer().getItemInHand().getType() == Material.DROPPER &&
    4. (e.getBlockAgainst().getType() == Material.DIRT || e.getBlockAgainst().getType() == Material.GRASS)){
    5. Player p = e.getPlayer();
    6. ItemStack i = p.getItemInHand();
    7. if(i.getItemMeta().hasDisplayName() && !e.isCancelled()){
    8. Dropper d = (Dropper) e.getBlockPlaced().getState();
    9. Bukkit.broadcastMessage(((Directional) d.getData()).getFacing() + " test");
    10. }
    11. }
    12. }
     
  12. Offline

    Garris0n

    Do you not get a ClassCastException from that? It appears dropper doesn't even implement Directional (not sure why...)

    Edit: Wait, that's the Dropper block. Apparently there isn't even a Dropper MaterialData.

    Edit: Okay, after way more searching than it probably should've taken, I can confirm that Dropper blocks return Dispenser MaterialData. Now to try to figure out what's actually wrong.

    Still not really sure, but I might just be tired. Try checking the facing direction a tick after the event is fired, see if anything changes.
     
  13. Garris0n I did, its accualy returned the correct direction, but I need to get the actual direction while the block is beeing placed... any ideas?
     
  14. Offline

    Garris0n

    Well, here's the code the server calculates the direction with (well, I think...).
    It would be nice if that was processed before the event so the information could be retrieved...
     
  15. Garris0n Any ideas what I can do about it?...
     
  16. Offline

    Garris0n

    If you can't get it from the event, either wait one tick or use what I posted above to calculate the direction yourself.
     
Thread Status:
Not open for further replies.

Share This Page