Have upperY and lowerY on GroundFindingFunction be set via mutators.

This commit is contained in:
sk89q 2014-03-01 12:03:10 -08:00
parent 6f116cd564
commit 504c7a5ff1
6 changed files with 28 additions and 23 deletions

View File

@ -2757,7 +2757,9 @@ public class EditSession {
double density, TreeGenerator treeGenerator) double density, TreeGenerator treeGenerator)
throws WorldEditException { throws WorldEditException {
ForestGenerator generator = new ForestGenerator(this, treeGenerator, lowerY, upperY); ForestGenerator generator = new ForestGenerator(this, treeGenerator);
generator.setLowerY(lowerY);
generator.setUpperY(upperY);
generator.setDensity(density); generator.setDensity(density);
int affected = 0; int affected = 0;

View File

@ -576,10 +576,9 @@ public class RegionCommands {
flatRegion = CuboidRegion.makeCuboid(region); flatRegion = CuboidRegion.makeCuboid(region);
} }
int upperY = flatRegion.getMaximumY(); FloraPlacer generator = new FloraPlacer(editSession);
int lowerY = flatRegion.getMinimumY(); generator.setLowerY(flatRegion.getMinimumY());
generator.setUpperY(flatRegion.getMaximumY());
FloraPlacer generator = new FloraPlacer(editSession, lowerY, upperY);
generator.setDensity(density); generator.setDensity(density);
int affected = 0; int affected = 0;

View File

@ -44,11 +44,9 @@ public class FloraPlacer extends GroundGenerator {
* Create a new instance. * Create a new instance.
* *
* @param editSession the edit session * @param editSession the edit session
* @param lowerY the lower Y
* @param upperY the upper Y (lowerY <= upperY)
*/ */
public FloraPlacer(EditSession editSession, int lowerY, int upperY) { public FloraPlacer(EditSession editSession) {
super(editSession, lowerY, upperY); super(editSession);
this.editSession = editSession; this.editSession = editSession;
} }

View File

@ -40,11 +40,9 @@ public class ForestGenerator extends GroundGenerator {
* *
* @param editSession the edit session * @param editSession the edit session
* @param treeGenerator a tree generator * @param treeGenerator a tree generator
* @param lowerY the lower Y boundary to end the ground search from
* @param upperY the upper Y boundary to start the ground search at
*/ */
public ForestGenerator(EditSession editSession, TreeGenerator treeGenerator, int lowerY, int upperY) { public ForestGenerator(EditSession editSession, TreeGenerator treeGenerator) {
super(editSession, lowerY, upperY); super(editSession);
this.editSession = editSession; this.editSession = editSession;
this.treeGenerator = treeGenerator; this.treeGenerator = treeGenerator;
} }

View File

@ -34,11 +34,9 @@ public abstract class GroundGenerator extends GroundFindingFunction {
* Create a new instance. * Create a new instance.
* *
* @param editSession the edit session * @param editSession the edit session
* @param lowerY the lower Y
* @param upperY the upper Y (lowerY <= upperY)
*/ */
protected GroundGenerator(EditSession editSession, int lowerY, int upperY) { protected GroundGenerator(EditSession editSession) {
super(editSession, lowerY, upperY); super(editSession);
} }
/** /**

View File

@ -26,6 +26,13 @@ import com.sk89q.worldedit.blocks.BlockID;
/** /**
* 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 ground, which is considered to be any non-air block.
* <p>
* It functions by starting from the upperY in each column and traversing
* down the column until it finds the first non-air block, at which point
* {@link #apply(com.sk89q.worldedit.Vector, com.sk89q.worldedit.blocks.BaseBlock)}
* is called on that non-air block. {@link #shouldContinue(com.sk89q.worldedit.Vector2D)}
* is called before each column is traversed, which allows implementations
* to "skip" a column and avoid the ground search.
*/ */
public abstract class GroundFindingFunction implements FlatRegionFunction { public abstract class GroundFindingFunction implements FlatRegionFunction {
@ -37,13 +44,9 @@ public abstract class GroundFindingFunction implements FlatRegionFunction {
* Create a new instance. * Create a new instance.
* *
* @param editSession the edit session * @param editSession the edit session
* @param lowerY the lower Y
* @param upperY the upper Y (lowerY <= upperY)
*/ */
protected GroundFindingFunction(EditSession editSession, int lowerY, int upperY) { protected GroundFindingFunction(EditSession editSession) {
this.editSession = editSession; this.editSession = editSession;
this.lowerY = lowerY;
this.upperY = upperY;
checkYBounds(); checkYBounds();
} }
@ -118,7 +121,8 @@ public abstract class GroundFindingFunction implements FlatRegionFunction {
} }
/** /**
* Returns whether a search for the ground should be performed for the given point. * Returns whether a search for the ground should be performed for the given
* column. Return false if the column is to be skipped.
* *
* @param pt the point * @param pt the point
* @return true if the search should begin * @return true if the search should begin
@ -129,6 +133,12 @@ public abstract class GroundFindingFunction implements FlatRegionFunction {
/** /**
* Apply the function to the given ground block. * Apply the function to the given ground block.
* <p>
* The block above the given ground block may or may not be air, but it is
* a block that can be replaced. For example, this block may be a tall
* 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 pt the position
* @param block the block * @param block the block