mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-07 15:42:19 -07:00
#809: Throw a more clear error for BlockIterators with zero direction, add Vector#isZero()
By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.util;
|
||||
|
||||
import static org.bukkit.util.NumberConversions.*;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import org.bukkit.Location;
|
||||
@@ -53,6 +54,11 @@ public class BlockIterator implements Iterator<Block> {
|
||||
*
|
||||
*/
|
||||
public BlockIterator(@NotNull World world, @NotNull Vector start, @NotNull Vector direction, double yOffset, int maxDistance) {
|
||||
Preconditions.checkArgument(world != null, "world must not be null");
|
||||
Preconditions.checkArgument(start != null, "start must not be null");
|
||||
Preconditions.checkArgument(direction != null, "direction must not be null");
|
||||
Preconditions.checkArgument(!direction.isZero(), "direction must have at least one non-zero component");
|
||||
|
||||
this.world = world;
|
||||
this.maxDistance = maxDistance;
|
||||
|
||||
|
@@ -365,6 +365,15 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not each component of this vector is equal to 0.
|
||||
*
|
||||
* @return true if equal to zero, false if at least one component is non-zero
|
||||
*/
|
||||
public boolean isZero() {
|
||||
return x == 0 && y == 0 && z == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts each component of value <code>-0.0</code> to <code>0.0</code>.
|
||||
*
|
||||
|
Reference in New Issue
Block a user