I am trying to paste a schematic from world edit, but it needs to paste in front of the player. I was wondering how to get the direction the player is looking, and make the schematic paste facing that direction. (Hopefully the schematics front is set when you copy it.)
Yes, but the direction is a vector. I was hoping some had code or knew how to calculate north, east ect.
Check the player yaw against certain bounds. (basically every 90 degrees if you just want the cardinals) Also: "I was hoping some had code" doesnt work here.
http://www2.clarku.edu/~djoyce/trig/ Here is a hint. EDIT: Actually, not even that. Do as mentioned above: I wasn't thinking
It's just god dang math, I had hopes someone made a class so I didn't have to spend hours, guess not... To the work factory. ):
I found some stuff/made some stuff, and since I am nice I will share it in case anyone else wants this. Code (Text): public static final BlockFace[] axis = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; public static final BlockFace[] radial = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST }; private static String getFacing(float yaw){ BlockFace bf = yawToFace(yaw); if(bf.equals(BlockFace.NORTH)){ return "SOUTH"; }else if(bf.equals(BlockFace.EAST)){ return "WEST"; }else if(bf.equals(BlockFace.SOUTH)){ return "NORTH"; }else return "EAST"; } public static BlockFace yawToFace(float yaw) { return yawToFace(yaw, false); } public static BlockFace yawToFace(float yaw, boolean useSubCardinalDirections) { if (useSubCardinalDirections) { return radial[Math.round(yaw / 45f) & 0x7]; } else { return axis[Math.round(yaw / 90f) & 0x3]; } } public static float getLookAtYaw(Vector motion) { double dx = motion.getX(); double dz = motion.getZ(); double yaw = 0; // Set yaw if (dx != 0) { // Set yaw start value based on dx if (dx < 0) { yaw = 1.5 * Math.PI; } else { yaw = 0.5 * Math.PI; } yaw -= Math.atan(dz / dx); } else if (dz < 0) { yaw = Math.PI; } return (float) (-yaw * 180 / Math.PI - 90); }
Wow, you are saying you are going to have to work to get your work done? Woahhhhhhh Sorry, SpigotMC isn't your personal code factory.
Neither is google. You have to do this yourself. Also, hours of work? This can be done in 10 minutes.
You can get the players' location using this method: Code (Text): private String translateDirection(Player player) { double r = ( player.getLocation().getY() - 90 ) % 360; if(r <= 0) { r += 360D; } if (0 <= r && r < 22.5) { return "N"; } if (22.5 <= r && r < 67.5) { return "NE"; } if (67.5 <= r && r < 112.5) { return "E"; } if (112.5 <= r && r < 157.5) { return "SE"; } if (157.5 <= r && r < 202.5) { return "S"; } if (202.5 <= r && r < 247.5) { return "SW"; } if (247.5 <= r && r < 292.5) { return "W"; } if (292.5 <= r && r < 337.5) { return "NW"; } if (337.5 <= r && r < 360.0) { return "N"; } return null; }
OH. WELL WHAT DO YOU KNOW?! WHAT A NICE GOOGLE SEARCH http://lmgtfy.com/?q=Get+direction+of+player (first result)
Thanks. Time is a precious virtue and is a waste if someone takes' hours of their time to figure out something which takes under 60 seconds.
I said doing it myself could take hours, calculating all he maths ect. There are usually methods already made for that, which there was!
wow.... thats so much math checking a value against certain bounds... wow... especially since the javadocs already explain what the values returned are: You cant call yourself a developer when you didnt even read the docs
Anyway guys, I solved way frken up there before anyone posted code. Sometimes I feel lazy, and its OK. Just don't post if you don't like it.