From 81050634381612ca5ba4e7d8b3ec9016179dc1db Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Mon, 9 Sep 2024 05:34:57 -0400 Subject: [PATCH 01/10] Starter Commit Changed, fitInWorld function Fixed, Using vector function --- .../njol/skript/expressions/ExprBlocks.java | 3 +++ .../njol/skript/util/BlockLineIterator.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprBlocks.java b/src/main/java/ch/njol/skript/expressions/ExprBlocks.java index a6cae9350a3..99c3b63feb1 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBlocks.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBlocks.java @@ -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; @@ -157,6 +158,8 @@ public Iterator iterator(Event event) { if (number != null) distance = number.intValue(); } + } else if (this.direction instanceof ExprFunctionCall) { + distance = (int) this.direction.getSingle(event).getDirection().length(); } return new BlockLineIterator(location, vector, distance); } else { diff --git a/src/main/java/ch/njol/skript/util/BlockLineIterator.java b/src/main/java/ch/njol/skript/util/BlockLineIterator.java index e67fbd02b0f..b078af69174 100644 --- a/src/main/java/ch/njol/skript/util/BlockLineIterator.java +++ b/src/main/java/ch/njol/skript/util/BlockLineIterator.java @@ -18,6 +18,7 @@ */ package ch.njol.skript.util; +import ch.njol.skript.Skript; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.util.BlockIterator; @@ -37,8 +38,12 @@ public class BlockLineIterator extends StoppableIterator { * @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 new NullableChecker() { private final double overshotSq = Math.pow(start.getLocation().distance(end.getLocation()) + 2, 2); @@ -59,7 +64,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() { + super(new BlockIterator(start.getWorld(), start.toVector(), direction, 0, 0), new NullableChecker() { private final double distSq = distance * distance; @Override @@ -87,14 +92,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(); } } From 0967fda30a32bef18cae65f07b83b44304e453ec Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Mon, 9 Sep 2024 05:49:44 -0400 Subject: [PATCH 02/10] Cleanup --- .../java/ch/njol/skript/util/BlockLineIterator.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/njol/skript/util/BlockLineIterator.java b/src/main/java/ch/njol/skript/util/BlockLineIterator.java index b078af69174..28b968f4440 100644 --- a/src/main/java/ch/njol/skript/util/BlockLineIterator.java +++ b/src/main/java/ch/njol/skript/util/BlockLineIterator.java @@ -18,15 +18,12 @@ */ package ch.njol.skript.util; -import ch.njol.skript.Skript; 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; @@ -38,11 +35,9 @@ public class BlockLineIterator extends StoppableIterator { * @throws IllegalStateException randomly (Bukkit bug) */ public BlockLineIterator(Block start, Block end) throws IllegalStateException { - super(new BlockIterator( - start.getWorld(), - start.getLocation().toVector(), - end.equals(start) ? new Vector(1, 0, 0) : end.getLocation().subtract(start.getLocation()).toVector(), - 0, 0 + 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 new NullableChecker() { private final double overshotSq = Math.pow(start.getLocation().distance(end.getLocation()) + 2, 2); From ff5c7caa237f3f04edfb3cf0879d57943af44381 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:46:55 -0400 Subject: [PATCH 03/10] Test --- .../tests/syntaxes/expressions/ExprBlocks.sk | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk b/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk new file mode 100644 index 00000000000..d7d8e94507a --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk @@ -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 + 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") ~ vector(10,10,0) + set {_blocks::*} to blocks vector(10,0,0) {_loc} + assert size of {_blocks::*} is 10 with "Blocks vector(10,0,0) loc is not 10" + 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 + assert blocks at {_blocks::*} is air with "1 or more blocks were not set to stone" + From bae602f6d1b1dd1fca7ec6df5a682020b09763da Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:08:26 -0400 Subject: [PATCH 04/10] Revert --- .../java/ch/njol/skript/util/BlockLineIterator.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/util/BlockLineIterator.java b/src/main/java/ch/njol/skript/util/BlockLineIterator.java index 28b968f4440..dcdf1e55698 100644 --- a/src/main/java/ch/njol/skript/util/BlockLineIterator.java +++ b/src/main/java/ch/njol/skript/util/BlockLineIterator.java @@ -18,6 +18,8 @@ */ 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; @@ -87,7 +89,14 @@ public BlockLineIterator(Block start, Vector direction, double distance) throws * @return The newly modified Vector if needed. */ private static Vector fitInWorld(Location location, Vector direction) { - return location.toVector(); + 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()); } } From 3eff459d328edbd429a52d41e31d3dd1890a5fed Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:40:03 -0400 Subject: [PATCH 05/10] Remove check --- src/main/java/ch/njol/skript/expressions/ExprBlocks.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprBlocks.java b/src/main/java/ch/njol/skript/expressions/ExprBlocks.java index 99c3b63feb1..a6cae9350a3 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBlocks.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBlocks.java @@ -20,7 +20,6 @@ import java.util.Iterator; -import ch.njol.skript.lang.function.ExprFunctionCall; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.block.Block; @@ -158,8 +157,6 @@ public Iterator iterator(Event event) { if (number != null) distance = number.intValue(); } - } else if (this.direction instanceof ExprFunctionCall) { - distance = (int) this.direction.getSingle(event).getDirection().length(); } return new BlockLineIterator(location, vector, distance); } else { From 684b736b7db665043f83f7f174106245ff54d0e8 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:43:20 -0400 Subject: [PATCH 06/10] Fix Test --- src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk b/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk index d7d8e94507a..3ff8c843b1c 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk @@ -7,9 +7,9 @@ test "blocks void": 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") ~ vector(10,10,0) - set {_blocks::*} to blocks vector(10,0,0) {_loc} - assert size of {_blocks::*} is 10 with "Blocks vector(10,0,0) loc is not 10" + set {_loc} to (spawn of world "world") + set {_blocks::*} to blocks vector(1,0,0) {_loc} + 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 From 92ce257ab816e548888dd0f4cdb4214ab34c7d56 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 1 Oct 2024 18:08:58 -0400 Subject: [PATCH 07/10] Removed TODO --- src/main/java/ch/njol/skript/expressions/ExprBlocks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprBlocks.java b/src/main/java/ch/njol/skript/expressions/ExprBlocks.java index a6cae9350a3..84dd96811ca 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBlocks.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBlocks.java @@ -58,7 +58,7 @@ public class ExprBlocks extends SimpleExpression { 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%", From 8295f21486910adbde5695be41628052b4c86eb7 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:41:39 -0400 Subject: [PATCH 08/10] Fix 1.13.2 --- src/main/java/ch/njol/skript/expressions/ExprBlocks.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprBlocks.java b/src/main/java/ch/njol/skript/expressions/ExprBlocks.java index 84dd96811ca..fbc9683db1e 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBlocks.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBlocks.java @@ -56,6 +56,8 @@ @Since("1.0, 2.5.1 (within/cuboid/chunk)") public class ExprBlocks extends SimpleExpression { + private static final boolean SUPPORTS_WORLD_LOADED = Skript.methodExists(Location.class, "isWorldLoaded"); + static { Skript.registerExpression(ExprBlocks.class, Block.class, ExpressionType.COMBINED, "[(all [[of] the]|the)] blocks %direction% [%locations%]", @@ -116,7 +118,11 @@ protected Block[] get(Event event) { return from.stream(event) .filter(Location.class::isInstance) .map(Location.class::cast) - .filter(Location::isWorldLoaded) + .filter(location -> { + if (SUPPORTS_WORLD_LOADED) + return location.isWorldLoaded(); + return location.getChunk().isLoaded(); + }) .map(direction::getRelative) .map(Location::getBlock) .toArray(Block[]::new); From 75366bb3a3373941fb562cbd1b66d2fb9faf2c1d Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:04:38 -0500 Subject: [PATCH 09/10] Requested Changes --- .../njol/skript/util/BlockLineIterator.java | 22 ++----------------- .../tests/syntaxes/expressions/ExprBlocks.sk | 5 ++--- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/main/java/ch/njol/skript/util/BlockLineIterator.java b/src/main/java/ch/njol/skript/util/BlockLineIterator.java index dcdf1e55698..201f031cc4d 100644 --- a/src/main/java/ch/njol/skript/util/BlockLineIterator.java +++ b/src/main/java/ch/njol/skript/util/BlockLineIterator.java @@ -1,21 +1,3 @@ -/** - * This file is part of Skript. - * - * Skript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Skript is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Skript. If not, see . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ package ch.njol.skript.util; import ch.njol.skript.bukkitutil.WorldUtils; @@ -38,9 +20,9 @@ public class BlockLineIterator extends StoppableIterator { */ public BlockLineIterator(Block start, Block end) throws IllegalStateException { super(new BlockIterator(start.getWorld(), start.getLocation().toVector(), - end.equals(start) ? new Vector(1, 0, 0) : end.getLocation().subtract(start.getLocation()).toVector(), + end.equals(start) ? new Vector(1, 0, 0) : end.getLocation().subtract(start.getLocation()).toVector(), // should prevent an error if start = end 0, 0 - ), // should prevent an error if start = end + ), new NullableChecker() { private final double overshotSq = Math.pow(start.getLocation().distance(end.getLocation()) + 2, 2); diff --git a/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk b/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk index 3ff8c843b1c..1f7d174fec6 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk @@ -7,11 +7,10 @@ test "blocks void": 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 {_loc} to location(0.5, 20.5, 0.5) set {_blocks::*} to blocks vector(1,0,0) {_loc} 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 - assert blocks at {_blocks::*} is air with "1 or more blocks were not set to stone" - + assert blocks at {_blocks::*} is air with "1 or more blocks were not set to air" From 53a85ee259a2f47e0cc8f75fb2a8410abfb78f06 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sat, 30 Nov 2024 17:49:59 -0500 Subject: [PATCH 10/10] Fix Test --- src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk b/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk index 1f7d174fec6..0b954dc9a0b 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprBlocks.sk @@ -14,3 +14,5 @@ test "blocks vector direction": assert blocks at {_blocks::*} is stone with "1 or more blocks were not set to stone" set blocks at {_blocks::*} to air assert blocks at {_blocks::*} is air with "1 or more blocks were not set to air" + loop {_blocks::*}: + set block at loop-value to loop-value