Skip to content

Add directional generator utility helpers#19

Merged
Zoriot merged 2 commits into
AlpsBTE:mainfrom
Jasupa:main
Jun 6, 2026
Merged

Add directional generator utility helpers#19
Zoriot merged 2 commits into
AlpsBTE:mainfrom
Jasupa:main

Conversation

@Jasupa

@Jasupa Jasupa commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds shared GeneratorUtils helpers for directional block states and cardinal facing calculation.

Changes

  • Adds getBlockStateWithFacing(...) for directional blocks.
  • Adds getFacing(...) helpers for vector-to-vector and delta-based direction lookup.
  • Uses fallback directions when no clear horizontal direction exists.

@Jasupa Jasupa changed the title feature: add generator facing helpers Add directional generator utility helpers May 27, 2026

@Zoriot Zoriot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please bump the version of the lib + Rebase
Also squash the first two commits and rewrite the message of the first to include a msg in the commit title

* @param second The second vector
* @return Whether both vectors have the same block coordinates
*/
public static boolean isSameBlock(Vector first, Vector second) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does we need this again? We can just use equals afaik

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

.equals() uses fuzzy match on the floating point values of x and z, whereas this uses the floored x and z values, so its not the same. using .equals() would return false if comparing a value x=4.4 with x=4.8 for example, even though both represent the same block.
https://jd.papermc.io/paper/26.1.2/org/bukkit/util/Vector.html#equals(java.lang.Object)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As you can see in GeneratorUtils#getSelectionPointsFromRegion we already just use the block coords. So the result should be the same. It might be more resource heavy trough fine.
Even trough i think we should use block vectors because we never need a exact float vector

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well this is a library so we should assume that this method can and will be called in other places as well. The function should be evaluated on its own, and comparing float values would yield incorrect results. I would either leave this as is, or use block vectors like you suggested. both is fine by me.

@Cinnazeyy Cinnazeyy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm!

* @param second The second vector
* @return Whether both vectors have the same block coordinates
*/
public static boolean isSameBlock(Vector first, Vector second) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

.equals() uses fuzzy match on the floating point values of x and z, whereas this uses the floored x and z values, so its not the same. using .equals() would return false if comparing a value x=4.4 with x=4.8 for example, even though both represent the same block.
https://jd.papermc.io/paper/26.1.2/org/bukkit/util/Vector.html#equals(java.lang.Object)

- add setBlockStatesAtPositions utility
- add reusable block-vector and shortest-path helpers
- add bounds selection helper for generated paths
- expose vector max-height helper
@Zoriot
Zoriot merged commit dac5750 into AlpsBTE:main Jun 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants