Added GroundFindingFunction.shouldPassThrough().

Dieser Commit ist enthalten in:
sk89q 2014-03-01 14:08:17 -08:00
Ursprung 31060e1e0c
Commit 0402faa839

Datei anzeigen

@ -29,14 +29,16 @@ import com.sk89q.worldedit.regions.Region;
/** /**
* An abstract implementation of {@link com.sk89q.worldedit.operation.FlatRegionFunction} * An abstract implementation of {@link com.sk89q.worldedit.operation.FlatRegionFunction}
* that searches for the ground, which is considered to be any non-air block. * that searches for the first "ground" block." A ground block is found when the
* method {@link #shouldPassThrough(Vector, BaseBlock)} returns false, which, by default,
* does so for all non-air blocks.
* <p> * <p>
* It functions by starting from the upperY in each column and traversing * This function starts from the provided upperY in each block column and traverses
* down the column until it finds the first non-air block, at which point * down the column until it finds the first ground block, at which point
* {@link #apply(com.sk89q.worldedit.Vector, com.sk89q.worldedit.blocks.BaseBlock)} * {@link #apply(Vector, BaseBlock)} is called with the position and the
* is called on that non-air block. {@link #shouldContinue(com.sk89q.worldedit.Vector2D)} * {@link BaseBlock} for the found ground block. Implementations that want
* is called before each column is traversed, which allows implementations * to skip certain columns (and avoid the ground search) can override
* to "skip" a column and avoid the ground search. * {@link #shouldContinue(com.sk89q.worldedit.Vector2D)} and return true as necessary.
*/ */
public abstract class GroundFindingFunction implements FlatRegionFunction { public abstract class GroundFindingFunction implements FlatRegionFunction {
@ -130,7 +132,7 @@ public abstract class GroundFindingFunction implements FlatRegionFunction {
Vector testPt = pt.toVector(y); Vector testPt = pt.toVector(y);
BaseBlock block = editSession.getBlock(testPt); BaseBlock block = editSession.getBlock(testPt);
if (block.getType() != BlockID.AIR) { if (!shouldPassThrough(testPt, block)) {
return apply(testPt, block); return apply(testPt, block);
} }
} }
@ -149,20 +151,38 @@ public abstract class GroundFindingFunction implements FlatRegionFunction {
return true; return true;
} }
/**
* Returns whether the given block should be "passed through" when
* conducting the ground search.
* <p>
* 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.
* <p>
* The default implementation only returns true for air blocks.
*
* @param position the position
* @param block the block
* @return true if the block should be passed through during the ground search
*/
protected boolean shouldPassThrough(Vector position, BaseBlock block) {
return block.getType() == BlockID.AIR;
}
/** /**
* Apply the function to the given ground block. * Apply the function to the given ground block.
* <p> * <p>
* The block above the given ground block may or may not be air, but it is * Naive implementations may provide flowers, tall grass, and other
* a block that can be replaced. For example, this block may be a tall * blocks not often considered to be the ground as the ground block.
* grass block or a flower. However, the ground block also could be
* the flower or grass block itself, depending on the configuration of the
* GroundFindingFunction.
* *
* @param pt the position * @param position the position
* @param block the block * @param block the block
* @return true if something was changed * @return true if something was changed
* @throws WorldEditException thrown on an error * @throws WorldEditException thrown on an error
*/ */
protected abstract boolean apply(Vector pt, BaseBlock block) throws WorldEditException; protected abstract boolean apply(Vector position, BaseBlock block) throws WorldEditException;
} }