Skip to content

Facing Relative Vector Offset #7925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: dev/feature
Choose a base branch
from

Conversation

erenkarakal
Copy link
Member

@erenkarakal erenkarakal commented Jun 6, 2025

Problem

There isn't a shorthand way to offset a location while considering rotation.

Solution

Adds a new pattern to the existing offset syntax. This can be compared to ^^^ in vanilla commands (like /summon tnt ^1 ^2 ^3)

before:

set {_v} to vector from yaw player's yaw, pitch player's pitch
set vector length of {_v} to 3
spawn tnt at player ~~ {_v}

with this PR:

set {_l} to player's location offset by vector(0, 0, 3) using local axes
spawn tnt at {_l}

and this isn't even showing the work you would've done to achieve an X or Y offset at the same time

I was going to update the syntax description but not sure how I should explain this

Testing Completed

Only manual testing was done, comparing the syntax to the vanilla Minecraft command


Completes: none
Related: none

@erenkarakal erenkarakal requested a review from a team as a code owner June 6, 2025 18:25
@erenkarakal erenkarakal requested review from Burbulinis and TheMug06 and removed request for a team June 6, 2025 18:25
@erenkarakal erenkarakal changed the title Feature/facing relative vector offset Facing Relative Vector Offset Jun 6, 2025
@sovdeeth sovdeeth added the feature Pull request adding a new feature. label Jun 6, 2025
@erenkarakal erenkarakal requested a review from sovdeeth June 15, 2025 19:38
Copy link
Contributor

@Absolutionism Absolutionism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test perchance?

Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still needs tests

Comment on lines +108 to +117
private static Location getFacingRelativeOffset(Location loc, Vector offset) {
float yawRad = (float) Math.toRadians(-loc.getYaw());
float pitchRad = (float) Math.toRadians(loc.getPitch());
float rollRad = 0f;

Quaternionf rotation = new Quaternionf().rotateYXZ(yawRad, pitchRad, rollRad);
Vector3f localOffset = offset.toVector3f();
rotation.transform(localOffset);

return loc.add(localOffset.x, localOffset.y, localOffset.z);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd make the code a bit nicer and standard if this returned a vector instead of a location, so the .add is done in the same spot as the normal add.

@sovdeeth sovdeeth moved this to In Review in 2.13 Release Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature.
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

4 participants