Class BreadthFirstSearch
java.lang.Object
com.sk89q.worldedit.function.visitor.BreadthFirstSearch
- All Implemented Interfaces:
Operation
- Direct Known Subclasses:
RecursiveVisitor
Performs a breadth-first search starting from points added with
visit(BlockVector3)
. The search continues
to a certain adjacent point provided that the method
isVisitable(BlockVector3, BlockVector3)
returns true for that point.
As an abstract implementation, this class can be used to implement functionality that starts at certain points and extends outward from those points.
-
Field Summary
Fields inherited from interface com.sk89q.worldedit.function.operation.Operation
warnedDeprecatedClasses
-
Constructor Summary
ModifierConstructorDescriptionprotected
BreadthFirstSearch
(RegionFunction function) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAxes()
Add the directions along the axes as directions to visit.protected void
Add the diagonal directions as directions to visit.void
cancel()
Abort the current task.int
Get the number of affected objects.protected Collection<BlockVector3>
Get the list of directions will be visited.Iterable<com.sk89q.worldedit.util.formatting.text.Component>
Gets an iterable of messages that describe the current status of the operation.protected abstract boolean
isVisitable
(BlockVector3 from, BlockVector3 to) Return whether the given 'to' block should be visited, starting from the 'from' block.resume
(RunContext run) Complete the next step.void
visit
(BlockVector3 position) Add the given location to the list of locations to visit, provided that it has not been visited.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.sk89q.worldedit.function.operation.Operation
addStatusMessages
-
Constructor Details
-
BreadthFirstSearch
Create a new instance.- Parameters:
function
- the function to apply to visited blocks
-
-
Method Details
-
getDirections
Get the list of directions will be visited.Directions are
BlockVector3
s that determine what adjacent points area available. Vectors should not be unit vectors. An example of a valid direction isBlockVector3.at(1, 0, 1)
.The list of directions can be cleared.
- Returns:
- the list of directions
-
addAxes
protected void addAxes()Add the directions along the axes as directions to visit. -
addDiagonal
protected void addDiagonal()Add the diagonal directions as directions to visit. -
visit
Add the given location to the list of locations to visit, provided that it has not been visited. The position passed to this method will still be visited even if it failsisVisitable(BlockVector3, BlockVector3)
.This method should be used before the search begins, because if the position does fail the test, and the search has already visited it (because it is connected to another root point), the search will mark the position as "visited" and a call to this method will do nothing.
- Parameters:
position
- the position
-
isVisitable
Return whether the given 'to' block should be visited, starting from the 'from' block.- Parameters:
from
- the origin blockto
- the block under question- Returns:
- true if the 'to' block should be visited
-
getAffected
public int getAffected()Get the number of affected objects.- Returns:
- the number of affected
-
resume
Description copied from interface:Operation
Complete the next step. If this method returns true, then the method may be called again in the future, or possibly never. If this method returns false, then this method should not be called again.- Specified by:
resume
in interfaceOperation
- Parameters:
run
- describes information about the current run- Returns:
- another operation to run that operation again, or null to stop
- Throws:
WorldEditException
- an error
-
cancel
public void cancel()Description copied from interface:Operation
Abort the current task. After the this method is called,Operation.resume(RunContext)
should not be called at any point in the future. This method should not be called after successful completion of the operation. This method must be called if the operation is interrupted before completion. -
getStatusMessages
Description copied from interface:Operation
Gets an iterable of messages that describe the current status of the operation.- Specified by:
getStatusMessages
in interfaceOperation
- Returns:
- The status messages
-