Skip to content

Commit

Permalink
Few fixes for feature brushes (#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 14, 2023
1 parent 7f81aad commit d623488
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public void feature(Player player, LocalSession localSession,
@Arg(desc = "The type of feature to use")
ConfiguredFeatureType type) throws WorldEditException {
setOperationBasedBrush(player, localSession, radius,
new Paint(new FeatureGeneratorFactory(type), density / 100), shape, "worldedit.brush.feature");
new ApplyRegion(new FeatureGeneratorFactory(type, density / 100)), shape, "worldedit.brush.feature");
}

@Command(
Expand Down Expand Up @@ -650,6 +650,7 @@ public void biome(Player player, LocalSession localSession,
setOperationBasedBrush(player, localSession, radius,
new ApplyRegion(new BiomeFactory(biomeType)), shape, "worldedit.brush.biome");
player.printInfo(TranslatableComponent.of("worldedit.setbiome.warning"));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}

@Command(
Expand Down Expand Up @@ -677,6 +678,7 @@ public void morph(Player player, LocalSession session,
tool.setSize(brushSize);

player.printInfo(TranslatableComponent.of("worldedit.brush.morph.equip", TextComponent.of((int) brushSize)));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}

@Command(
Expand All @@ -696,6 +698,7 @@ public void erode(Player player, LocalSession session,
tool.setSize(brushSize);

player.printInfo(TranslatableComponent.of("worldedit.brush.morph.equip", TextComponent.of((int) brushSize)));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}

@Command(
Expand All @@ -715,6 +718,7 @@ public void dilate(Player player, LocalSession session,
tool.setSize(brushSize);

player.printInfo(TranslatableComponent.of("worldedit.brush.morph.equip", TextComponent.of((int) brushSize)));
ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}

static void setOperationBasedBrush(Player player, LocalSession session, double radius,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.function.Contextual;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.RegionMaskingFilter;
import com.sk89q.worldedit.function.generator.FeatureGenerator;
import com.sk89q.worldedit.function.mask.NoiseFilter;
import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;

public final class FeatureGeneratorFactory implements Contextual<FeatureGenerator> {
public final class FeatureGeneratorFactory implements Contextual<RegionMaskingFilter> {
private final ConfiguredFeatureType type;
private final double density;

public FeatureGeneratorFactory(ConfiguredFeatureType type) {
public FeatureGeneratorFactory(ConfiguredFeatureType type, double density) {
this.type = type;
this.density = density;
}

@Override
public FeatureGenerator createFromContext(EditContext input) {
return new FeatureGenerator((EditSession) input.getDestination(), type);
public RegionMaskingFilter createFromContext(EditContext input) {
return new RegionMaskingFilter(
new NoiseFilter(new RandomNoise(), this.density),
new FeatureGenerator((EditSession) input.getDestination(), this.type)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;

/**
* Generates forests by searching for the ground starting from the given upper Y
* coordinate for every column given.
* Attempt to generate features for every location in the given region.
*/
public class FeatureGenerator implements RegionFunction {

Expand Down

0 comments on commit d623488

Please sign in to comment.