mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-03 11:56:40 +00:00
Made GroundScatterFunction use a NoiseGenerator.
This commit is contained in:
@ -21,18 +21,32 @@ package com.sk89q.worldedit.operation;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.generator.GroundGenerator;
|
||||
import com.sk89q.worldedit.noise.NoiseGenerator;
|
||||
import com.sk89q.worldedit.noise.RandomNoise;
|
||||
|
||||
/**
|
||||
* Randomly applies the given {@link RegionFunction} onto random ground blocks.
|
||||
* <p>
|
||||
* This class can be used to generate a structure randomly over an area.
|
||||
*/
|
||||
public class GroundScatterFunction extends GroundGenerator {
|
||||
public class GroundScatterFunction extends GroundFindingFunction {
|
||||
|
||||
private NoiseGenerator noiseGenerator;
|
||||
private RegionFunction function;
|
||||
private double density;
|
||||
|
||||
/**
|
||||
* Create a new instance using a {@link RandomNoise} as the noise generator.
|
||||
*
|
||||
* @param editSession the edit session
|
||||
* @param function the function
|
||||
*/
|
||||
public GroundScatterFunction(EditSession editSession, RegionFunction function) {
|
||||
this(editSession, function, new RandomNoise());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -40,9 +54,48 @@ public class GroundScatterFunction extends GroundGenerator {
|
||||
* @param editSession the edit session
|
||||
* @param function the function
|
||||
*/
|
||||
public GroundScatterFunction(EditSession editSession, RegionFunction function) {
|
||||
public GroundScatterFunction(EditSession editSession, RegionFunction function, NoiseGenerator noiseGenerator) {
|
||||
super(editSession);
|
||||
this.function = function;
|
||||
this.noiseGenerator = noiseGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the density (0 <= density <= 1) which indicates the threshold that
|
||||
* must be met for the function to be applied to a column.
|
||||
*
|
||||
* @return the density
|
||||
*/
|
||||
public double getDensity() {
|
||||
return density;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the density (0 <= density <= 1) which indicates the threshold that
|
||||
* must be met for the function to be applied to a column.
|
||||
*
|
||||
* @param density the density
|
||||
*/
|
||||
public void setDensity(double density) {
|
||||
this.density = density;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the noise generator.
|
||||
*
|
||||
* @return the noise generator
|
||||
*/
|
||||
public NoiseGenerator getNoiseGenerator() {
|
||||
return noiseGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the noise generator.
|
||||
*
|
||||
* @param noiseGenerator the noise generator
|
||||
*/
|
||||
public void setNoiseGenerator(NoiseGenerator noiseGenerator) {
|
||||
this.noiseGenerator = noiseGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,6 +116,11 @@ public class GroundScatterFunction extends GroundGenerator {
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldContinue(Vector2D pt) {
|
||||
return noiseGenerator.noise(pt) <= density;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean apply(Vector position, BaseBlock block) throws WorldEditException {
|
||||
return function.apply(position);
|
||||
|
Reference in New Issue
Block a user