Add directional generator utility helpers#19
Conversation
| * @param second The second vector | ||
| * @return Whether both vectors have the same block coordinates | ||
| */ | ||
| public static boolean isSameBlock(Vector first, Vector second) { |
There was a problem hiding this comment.
Why does we need this again? We can just use equals afaik
There was a problem hiding this comment.
.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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| * @param second The second vector | ||
| * @return Whether both vectors have the same block coordinates | ||
| */ | ||
| public static boolean isSameBlock(Vector first, Vector second) { |
There was a problem hiding this comment.
.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
Summary
Adds shared
GeneratorUtilshelpers for directional block states and cardinal facing calculation.Changes
getBlockStateWithFacing(...)for directional blocks.getFacing(...)helpers for vector-to-vector and delta-based direction lookup.