Skip to content
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

ExprDirection - deep cleaning #6637

Draft
wants to merge 4 commits into
base: dev/feature
Choose a base branch
from

Conversation

Fusezion
Copy link
Contributor

@Fusezion Fusezion commented May 3, 2024

Description

This pr is a continuation of #6626 along side fixing my mistake in it. This pr now target dev/feature as that should be the next release and allowed me to remove some patterns I found in poor taste.

Test is possibly a bit too excessive however with direction being a huge part in skript ensuring nothing breaks is important as such not only is there testing in action but also use of parse section ensuring patterns are passing and not randomly breaking down. Sadly the parse section is a huge hinder at the same time as it doesn't explicitly state the line number that errored only the error. So if a test breaks and the error is something like "cannnot use variables here" loading on the test server is kind of needed.

Unlike the previous pr this one makes use of the Patterns class instead to handle pattern splitting, patterns using BlockFace.SELF are both technically correct and incorrect sadly since the class refuses to accept null as a value and will throw a stack trace I am forced into that decision.

ENTITY TESTING
I was unable to think of a safe way to do entity test that ensure there's never a possibility in the entity turning causing a slight offset of locations. As such only block test were included if you have any ideas on how to test entities without unforeseen failures please give me feedback.


Target Minecraft Versions: any
Requirements: none
Related Issues: none

@Fusezion Fusezion marked this pull request as ready for review May 3, 2024 00:51
Comment on lines +152 to +155
if (relativeObject == null)
return new Direction[0];
if (o instanceof Block) {
final BlockFace f = Direction.getFacing((Block) o);
if (f == BlockFace.SELF || horizontal && (f == BlockFace.UP || f == BlockFace.DOWN))
return new Direction[] {Direction.ZERO};
return new Direction[] {new Direction(f, ln)};
} else {
final Location l = ((Entity) o).getLocation();
if (!horizontal) {
if (!facing) {
final Vector v = l.getDirection().normalize().multiply(ln);
assert v != null;
return new Direction[] {new Direction(v)};
}
final double pitch = Direction.pitchToRadians(l.getPitch());

if (relativeObject instanceof Block) {
Copy link
Member

Choose a reason for hiding this comment

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

This little guy can probably join the if/else chain :)

Comment on lines +204 to +208
this.amount != null ? amount.toString(event, debug) + " meter(s) " : "",
(isHorizontal ? "horizontally " : ""), (isFacing ? "facing " : ""),
this.directionVector != null ? Direction.toString(directionVector) :
this.relativeTo != null ? "of " + relativeTo.toString(event, debug) :
Direction.toString(0, yaw, 1)
Copy link
Member

Choose a reason for hiding this comment

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

I think it would look nicer if you assigned these variables first rather than having 90 ternaries in the return, it's not like we're saving lines doing this anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will see what I can do

{"[%-number% [(block|meter|metre)[s]]] [to the] south[er(n|ly)|ward[s|ly]] [[side] of] [[and|,] %-direction%]", BlockFace.SOUTH},
{"[%-number% [(block|meter|metre)[s]]] [to the] west[er(n|ly)|ward[s|ly]] [[side] of] [[and|,] %-direction%]", BlockFace.WEST},
{"[%-number% [(block|meter|metre)[s]]] (above|over|up[ward[s|ly]]) [%-direction%]", BlockFace.UP},
{"[%-number% [(block|meter|metre)[s]]] (below|under|down[ward[s|ly]]) [%-direction%]", BlockFace.DOWN},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{"[%-number% [(block|meter|metre)[s]]] (below|under|down[ward[s|ly]]) [%-direction%]", BlockFace.DOWN},
{"[%-number% [(block|meter|metre)[s]]] (below|under[neath]|beneath|down[ward[s|ly]]) [%-direction%]", BlockFace.DOWN},

{"[%-number% [(block|meter|metre)[s]]] [to the] west[er(n|ly)|ward[s|ly]] [[side] of] [[and|,] %-direction%]", BlockFace.WEST},
{"[%-number% [(block|meter|metre)[s]]] (above|over|up[ward[s|ly]]) [%-direction%]", BlockFace.UP},
{"[%-number% [(block|meter|metre)[s]]] (below|under|down[ward[s|ly]]) [%-direction%]", BlockFace.DOWN},
{"[%-number% [(block|meter|metre)[s]]] [in [the]] [:horizontal] (direction|:facing) of %entity/block% [of|from]", BlockFace.SELF},
Copy link
Member

Choose a reason for hiding this comment

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

Conflicts with exprfacing, I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will neee to look into this or ExprFacing as a whole. Iirc, this is a pattern existing before I edited, so it existed for a while.

Optionally, if this is creating conflicts, it might be worth seeing about a merge.

I intend to add opposite facing into a few, and I know there is a pr that wants to add it to expr facing.

Could also remove pattern, but I dont think I want them in two places. Thoughts on if a merge is ideal?
Both return directions, iirc.

Copy link
Member

Choose a reason for hiding this comment

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

The previous pattern had a required in

@sovdeeth
Copy link
Member

sovdeeth commented May 3, 2024

Re: tests, you can do all the testing in one tick, no time for the entity to turn.

@sovdeeth sovdeeth added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label May 3, 2024
@Fusezion Fusezion marked this pull request as draft May 11, 2024 03:00
@Fusezion
Copy link
Contributor Author

Converting to draft, due to health issues arising and being unsure how much freetime I'll have during the next week or longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants