Jump to content

Is there a way to get the ForgeDirection a Vec3 is pointing?


Recommended Posts

Hi everybody.  I am wondering if there is a easy way or method to get the ForgeDirection that a Vec3 (or any other type of 3D vector) is pointing?  I am trying to make a block that blends in to it's souroundings, if it makes any difference.  Thank you in advance.

Link to comment
Share on other sites



I don't know of a  vanilla function for this but it is easy enough to do yourself.


Find which of the three components [x, y, z] have the largest absolute magnitude.  The vector is pointing mostly in that direction.


eg [0.5, -0.6, 0.9] is pointing mostly in the positive z direction

[0, -0.7, 0.3] is pointing mostly in the negative y direction



Link to comment
Share on other sites

This is what I'm going to try to use.  Fell free to use it yourself :)



public static ForgeDirection getForgeDirection(Vec3 vec) {


	double pitchR = Math.atan(vec.yCoord / Math.sqrt(Math.pow(vec.xCoord, 2) + Math.pow(vec.zCoord, 2)));
	double yawR = Math.atan2(-vec.zCoord, vec.xCoord);
	double pi = Math.PI;

	ForgeDirection dir = ForgeDirection.UNKNOWN;

	System.out.println("Pitch: " + pitchR + ", Yaw: " + yawR);

	if(yawR < -pi || yawR > pi)
		System.err.println("Yaw is too big!!");

	if(pitchR > -pi/4 && pitchR < pi/4){ // if the vector is mostly horizontal

		if(yawR >= -pi/4 && yawR <= pi/4)
			dir = ForgeDirection.EAST;
		else if(yawR < -pi/4 && yawR >= -3*pi/4)
			dir = ForgeDirection.SOUTH;
		else if(yawR > pi/4 && yawR <= 3*pi/4)
			dir = ForgeDirection.NORTH;
		else if(yawR < -3*pi/4 || yawR > 3*pi/4)
			dir = ForgeDirection.WEST;

	} else if(pitchR >= pi/4)
		dir = ForgeDirection.UP;
		dir = ForgeDirection.DOWN;

	return dir;


Edit:  I have a gitch where it sometimes thinks South is West, and I have no idea why.

Edit 2: I fixed it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.