PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
10.04k stars 2.34k forks source link

Get closest yaw from a certain blockface! #9778

Closed kohlerpop1 closed 10 months ago

kohlerpop1 commented 1 year ago

Is your feature request related to a problem?

Changing the rotation of using Entity#setRotation(float yaw, float pitch) requires a yaw and pitch. I am currently using Player#getFacing() to get the facing of the player and wanting the entity to face the same direction but there is no method to set the entity facing using this method. I therefore have to call the alternative method I considered to convert it to a yaw then call the Entity#setRotation method. I know some will say just teleport the entity to the same location just with player yaw but then I just feel this disregards the purpose of having the setRotation method in the entity class meaning it should be removed if that is the solution.

Describe the solution you'd like.

Method in BlockFace class! Method name does not matter. getYaw() or asYaw() or toYaw() all work!

public float getYaw() or asYaw() or toYaw() { return // Computed Yaw or cached yaw; }

Describe alternatives you've considered.

Currently I just have a basic method to do what I please. However, I feel some others may also do this and it would be a nice tiny addition to the Paper API. private float facingToYaw(BlockFace facing) { return switch (facing) { case NORTH -> 180F; case EAST -> -90F; case SOUTH -> 0F; case WEST -> 90F; default -> throw new IllegalStateException("Unexpected value: " + facing); }; }

Other

It would take meer minutes to add this and I think it would be very useful.

SplotyCode commented 1 year ago

Putting BlockFace#getDirection into atan2 should give similar results and will work on NORTH_EAST, EAST_SOUTH_EAST etc. You mide need to invert the result because minecraft rotation is wired