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

Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 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
53a85ee
Fix Test
TheAbsolutionism Nov 30, 2024
38f994c
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Nov 30, 2024
f786684
Merge branch 'dev/patch' into dev/ExprBlocks-Void-to-Void
TheAbsolutionism Dec 1, 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
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/expressions/ExprBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ExprBlocks extends SimpleExpression<Block> {

static {
Skript.registerExpression(ExprBlocks.class, Block.class, ExpressionType.COMBINED,
"[(all [[of] the]|the)] blocks %direction% [%locations%]", // TODO doesn't loop all blocks?
"[(all [[of] the]|the)] blocks %direction% [%locations%]",
"[(all [[of] the]|the)] blocks from %location% [on] %direction%",
"[(all [[of] the]|the)] blocks from %location% to %location%",
"[(all [[of] the]|the)] blocks between %location% and %location%",
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/ch/njol/skript/util/BlockLineIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
package ch.njol.skript.util;

import ch.njol.skript.bukkitutil.WorldUtils;
import ch.njol.util.Math2;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.util.BlockIterator;
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 +37,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 +61,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
17 changes: 17 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test "blocks void":
set {_loc} to location(0.5, 320.5, 0.5)
set {_blocks::*} to blocks between {_loc} and ({_loc} ~ vector(10,0,0))
assert size of {_blocks::*} is 11 with "Blocks between loc and (loc~vector(10,0,0)) is not 11"
assert blocks at {_blocks::*} is void air with "Blocks can be set in the void?"
set blocks at {_blocks::*} to stone
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
assert blocks at {_blocks::*} is void air with "Blocks can be set in the void?"

test "blocks vector direction":
set {_loc} to (spawn of world "world")
set {_blocks::*} to blocks vector(1,0,0) {_loc}
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
assert size of {_blocks::*} is 100 with "Blocks vector(1,0,0) loc is not 100"
set blocks at {_blocks::*} to stone
assert blocks at {_blocks::*} is stone with "1 or more blocks were not set to stone"
set blocks at {_blocks::*} to air
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
assert blocks at {_blocks::*} is air with "1 or more blocks were not set to stone"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved

Loading