Skip to content

Commit b87787c

Browse files
authored
Fix BlockLineIterator error due to floating point error near edges of blocks. (SkriptLang#7769)
* Update BlockLineIterator.java * forgot the negative sign * add regression test
1 parent 43dee01 commit b87787c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/ch/njol/skript/util/BlockLineIterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public boolean hasNext() {
7373
public Block next() {
7474
if (!hasNext()) throw new NoSuchElementException("Reached the final block destination");
7575
// sanity check (is the current->end vector pointing away from step)
76-
if (end.sub(current, new Vector3d()).dot(step) < 0) throw new NoSuchElementException("Overshot the final block!");
76+
if (end.sub(current, new Vector3d()).dot(step) < -1) throw new NoSuchElementException("Overshot the final block!");
7777
// get block and check end
7878
Vector3d center = centered(current);
7979
Block block = getBlock(center, world);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test "block line overshoot too aggressive":
2+
set {_loc} to location(0,-0.9,0,world "world")
3+
set {_step} to vector(0,0.001,0)
4+
loop 200 times:
5+
assert (size of blocks above {_loc}) is 100 with "failed to get blocks above %{_loc}%"
6+
set {_loc} to {_loc} ~ {_step}

0 commit comments

Comments
 (0)