public abstract class GroundFindingFunction extends Object implements FlatRegionFunction
FlatRegionFunction
that searches for the first "ground" block." A ground block is found when the
method shouldPassThrough(Vector, BaseBlock) returns false, which, by default,
does so for all non-air blocks.
This function starts from the provided upperY in each block column and traverses
down the column until it finds the first ground block, at which point
apply(Vector, BaseBlock) is called with the position and the
BaseBlock for the found ground block. Implementations that want
to skip certain columns (and avoid the ground search) can override
shouldContinue(com.sk89q.worldedit.Vector2D) and return true as necessary.
| Modifier | Constructor and Description |
|---|---|
protected |
GroundFindingFunction(EditSession editSession)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
apply(Vector2D pt)
Apply the function to the given point.
|
protected abstract boolean |
apply(Vector position,
BaseBlock block)
Apply the function to the given ground block.
|
int |
getLowerY()
Get the lower Y coordinate to end the ground search at.
|
int |
getUpperY()
Get the upper Y coordinate to start the ground search from.
|
void |
raiseCeiling(int y)
Increase the upper Y by the given amount.
|
void |
setRange(int lowerY,
int upperY)
Set the range of Y coordinates to perform a search for ground within.
|
void |
setRange(Region region)
Set the range of Y coordinates to perform a search for ground within from
the minimum and maximum Y of the given region.
|
protected boolean |
shouldContinue(Vector2D pt)
Returns whether a search for the ground should be performed for the given
column.
|
protected boolean |
shouldPassThrough(Vector position,
BaseBlock block)
Returns whether the given block should be "passed through" when
conducting the ground search.
|
protected GroundFindingFunction(EditSession editSession)
editSession - the edit sessionpublic int getUpperY()
public int getLowerY()
public void setRange(int lowerY,
int upperY)
lowerY - the lower Y coordinateupperY - the upper Y coordinate (upperY >= lowerY)public void setRange(Region region)
region - the regionpublic void raiseCeiling(int y)
y - the amount to increase the upper Y bypublic final boolean apply(Vector2D pt) throws WorldEditException
FlatRegionFunctionapply in interface FlatRegionFunctionpt - the pointWorldEditException - thrown on an errorprotected boolean shouldContinue(Vector2D pt)
pt - the pointprotected boolean shouldPassThrough(Vector position, BaseBlock block)
Examples of blocks where this method could return true include snow, tall grass, shrubs, and flowers. Note that this method will also receive calls on each air block so that condition must be handled. Be aware that blocks passed through are not automatically removed from the world, so implementations may need to remove the block immediately above the ground.
The default implementation only returns true for air blocks.
position - the positionblock - the blockprotected abstract boolean apply(Vector position, BaseBlock block) throws WorldEditException
Naive implementations may provide flowers, tall grass, and other blocks not often considered to be the ground as the ground block.
position - the positionblock - the blockWorldEditException - thrown on an errorCopyright © 2010-2014. All Rights Reserved.