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

ExprBlocks - BlockLineIterator #7062

Open
wants to merge 21 commits into
base: dev/patch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8105063
Starter Commit
TheAbsolutionism Sep 9, 2024
0967fda
Cleanup
TheAbsolutionism Sep 9, 2024
65f754d
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Sep 9, 2024
ff5c7ca
Test
TheAbsolutionism Sep 9, 2024
af1e4ef
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Sep 12, 2024
796533d
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Sep 18, 2024
44c75e4
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Sep 21, 2024
336dd49
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Sep 22, 2024
2173bdd
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Sep 22, 2024
bae602f
Revert
TheAbsolutionism Sep 24, 2024
af6036c
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Oct 1, 2024
3eff459
Remove check
TheAbsolutionism Oct 1, 2024
684b736
Fix Test
TheAbsolutionism Oct 1, 2024
92ce257
Removed TODO
TheAbsolutionism Oct 1, 2024
3bf72d9
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Oct 1, 2024
193f246
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Oct 1, 2024
db98d3e
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Oct 2, 2024
8248694
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Nov 1, 2024
8295f21
Fix 1.13.2
TheAbsolutionism Nov 1, 2024
68ab41b
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Nov 11, 2024
75366bb
Requested Changes
TheAbsolutionism Nov 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Iterator;

import ch.njol.skript.lang.function.ExprFunctionCall;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -157,6 +158,8 @@ public Iterator<Block> iterator(Event event) {
if (number != null)
distance = number.intValue();
}
} else if (this.direction instanceof ExprFunctionCall) {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
distance = (int) this.direction.getSingle(event).getDirection().length();
}
return new BlockLineIterator(location, vector, distance);
} else {
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/ch/njol/skript/util/BlockLineIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.bukkitutil.WorldUtils;
import ch.njol.util.Math2;
import ch.njol.util.NullableChecker;
import ch.njol.util.coll.iterator.StoppableIterator;

Expand All @@ -37,8 +35,10 @@ public class BlockLineIterator extends StoppableIterator<Block> {
* @throws IllegalStateException randomly (Bukkit bug)
*/
public BlockLineIterator(Block start, Block end) throws IllegalStateException {
super(new BlockIterator(start.getWorld(), fitInWorld(start.getLocation().add(0.5, 0.5, 0.5), end.getLocation().subtract(start.getLocation()).toVector()),
end.equals(start) ? new Vector(1, 0, 0) : end.getLocation().subtract(start.getLocation()).toVector(), 0, 0), // should prevent an error if start = end
super(new BlockIterator(start.getWorld(), start.getLocation().toVector(),
end.equals(start) ? new Vector(1, 0, 0) : end.getLocation().subtract(start.getLocation()).toVector(),
0, 0
), // should prevent an error if start = end
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
new NullableChecker<Block>() {
private final double overshotSq = Math.pow(start.getLocation().distance(end.getLocation()) + 2, 2);

Expand All @@ -59,7 +59,7 @@ public boolean check(@Nullable Block block) {
* @throws IllegalStateException randomly (Bukkit bug)
*/
public BlockLineIterator(Location start, Vector direction, double distance) throws IllegalStateException {
super(new BlockIterator(start.getWorld(), fitInWorld(start, direction), direction, 0, 0), new NullableChecker<Block>() {
super(new BlockIterator(start.getWorld(), start.toVector(), direction, 0, 0), new NullableChecker<Block>() {
private final double distSq = distance * distance;

@Override
Expand Down Expand Up @@ -87,14 +87,7 @@ public BlockLineIterator(Block start, Vector direction, double distance) throws
* @return The newly modified Vector if needed.
*/
private static Vector fitInWorld(Location location, Vector direction) {
int lowest = WorldUtils.getWorldMinHeight(location.getWorld());
int highest = location.getWorld().getMaxHeight();
Vector vector = location.toVector();
int y = location.getBlockY();
if (y >= lowest && y <= highest)
return vector;
double newY = Math2.fit(lowest, location.getY(), highest);
return new Vector(location.getX(), newY, location.getZ());
return location.toVector();
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

}