Easiest way to rotate a dispenser?

Discussion in 'Plugin Development' started by Pocketkid2, Jul 26, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Pocketkid2

    I am making a plugin that lets you rotate dispensers, what is the easiest way to do that? I know there is a class called Dispenser, which is a subclass of FurnaceAndDispenser, which is a subclass of DirectionalContainer, which is a subclass of MaterialData. I have no idea how to get a instance of that DIspenser class. Can someone help me figure out how to get one starting with a Block class instance, and the best way to rotate it?
     
  2. Offline

    Zaaryus

    As I shouldn't give you the code, but just give hints.. I would say get the block with location, cast it to Dispenser then probably use setFacingDirection? I have not tried, but I'll test it and tell you how it goes.
     
  3. Offline

    Pocketkid2

    I was thinking the same thing, but I was totally unsure. I will try it too.

    okay, so I got it to recognize the Dispenser class, but now I have problems changing it! I have this code which just reads the facing direction and cycles it, but all I see is the direction printing in the console, but no real rotation!

    Code:java
    1. public void rotate(Dispenser dispenser) {
    2. BlockFace face = dispenser.getFacing();
    3. System.out.println(face.toString());
    4. switch (face) {
    5. case DOWN:
    6. face = BlockFace.EAST;
    7. break;
    8. case EAST:
    9. face = BlockFace.NORTH;
    10. break;
    11. case NORTH:
    12. face = BlockFace.SOUTH;
    13. break;
    14. case SOUTH:
    15. face = BlockFace.UP;
    16. break;
    17. case UP:
    18. face = BlockFace.WEST;
    19. break;
    20. case WEST:
    21. face = BlockFace.DOWN;
    22. break;
    23. default:
    24. break;
    25.  
    26. }
    27. dispenser.setFacingDirection(face);
    28. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    Zaaryus

    I have the dispenser and I'm pretty sure getFacing() doesn't exist in the API
     
  5. Offline

    Pocketkid2

    That's funny, as it seems to get it 100% properly. I can see the dispenser face direction in the console just fine when I call the function.
     
  6. Offline

    Zaaryus

    Weird, what version are you using?
     
  7. Offline

    Pocketkid2

    Latest spigot 1.7.10, I was reading the dev javadocs: http://jd.bukkit.org/dev/apidocs/

    the Dispenser class I am using is implementing Directional, which has getFace() and setFacingDirection()

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  8. Offline

    Zaaryus

    Wow, I'm apparently using Bukkit 1.7.9, so it's probably new?
     
  9. Offline

    Pocketkid2

    I would not think so.
     
Thread Status:
Not open for further replies.

Share This Page