Solved change the direction of a sign

Discussion in 'Plugin Development' started by Kyorax, Apr 18, 2014.

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

    Kyorax

    Hi everyone,

    I was wondering how I could create a sign that always "looks" at the player that created it with the tool I designed in my plugin.
    You can enter the lines of the sign and then rightclick with a golden hoe to create lots of them.
    However, I don't know how to get the direction from the player, invert it and give it back to the sign.
    This is my code so far:
    Code:java
    1.  
    2. Location loc = event.getClickedBlock().getLocation();
    3. loc.add(0, 1, 0);
    4. loc.getBlock().setType(Material.SIGN_POST);
    5. Sign sign = (Sign)loc.getBlock().getState();

    Thanks in advance.

    Does anyone know how to change it into a direction like north, south, east, west at least?

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

    zDylann

    Use this:
    Where 3 is south, 2 is north, 5 is east, and 4 is west.
    Code:java
    1. sign.setRawData((byte) 3);
     
  3. Code:
        public byte getDirection(Player player){
              double rotation = (player.getLocation().getYaw() - 90) % 360;
                if (rotation < 0) {
                    rotation += 360.0;
                }
                if (0 <= rotation && rotation < 22.5) {
                    return 0xC; //S > E
                } else if (22.5 <= rotation && rotation < 67.5) {
                    return 0xE; //SW > SE
                } else if (67.5 <= rotation && rotation < 112.5) {
                    return 0x0; //W > E
                } else if (112.5 <= rotation && rotation < 157.5) {
                    return 0x2; //NW > SW
                } else if (157.5 <= rotation && rotation < 202.5) {
                    return 0x4; //N > W
                } else if (202.5 <= rotation && rotation < 247.5) {
                    return 0x6; //NE > NW
                } else if (247.5 <= rotation && rotation < 292.5) {
                    return 0x8; //E > N
                } else if (292.5 <= rotation && rotation < 337.5) {
                    return 0xA; //SE > NE
                } else if (337.5 <= rotation && rotation < 360.0) {
                    return 0xC; //S > E
                } else {
                    return null;
                }
            }
    
    Taken from: https://forums.bukkit.org/threads/solved-player-direction.72789/#post-1094604

    You can modify this to your needs.
     
  4. Offline

    Kyorax

    I get something like 0x2 now, but how do I make the sign go into that direction?

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page