use of com.sk89q.worldedit.command.tool.brush.Brush in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method scatterBrush.
@Command(name = "scatter", desc = "Scatter a pattern on a surface", descFooter = "Set a number of blocks randomly on a surface each a certain distance apart.\n" + "Video: https://youtu.be/RPZIaTbqoZw?t=34s")
@CommandPermissions("worldedit.brush.scatter")
public void scatterBrush(InjectedValueAccess context, @Arg(desc = "Pattern") Pattern fill, @Arg(desc = "radius", def = "5") Expression radius, @Arg(desc = "points", def = "5") double points, @Arg(desc = "distance", def = "1") double distance, @Switch(name = 'o', desc = "Overlay the block") boolean overlay) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
Brush brush;
if (overlay) {
brush = new ScatterOverlayBrush((int) points, (int) distance);
} else {
brush = new ScatterBrush((int) points, (int) distance);
}
set(context, brush, "worldedit.brush.scatter").setSize(radius).setFill(fill);
}
use of com.sk89q.worldedit.command.tool.brush.Brush in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method sphereBrush.
@Command(name = "sphere", aliases = { "s" }, desc = "Choose the sphere brush")
@CommandPermissions("worldedit.brush.sphere")
public void sphereBrush(Player player, InjectedValueAccess context, @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Arg(desc = "The radius of the sphere", def = "2") Expression radius, @Switch(name = 'h', desc = "Create hollow spheres instead") boolean hollow, @Switch(name = 'f', desc = "Create falling spheres instead") boolean falling) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
Brush brush;
if (hollow) {
brush = new HollowSphereBrush();
} else {
// FAWE start - Suggest different brush material if sand or gravel is used
if (pattern instanceof BlockStateHolder) {
BlockType type = ((BlockStateHolder) pattern).getBlockType();
switch(type.getId()) {
case "minecraft:sand":
case "minecraft:gravel":
player.print(Caption.of("fawe.worldedit.brush.brush.try.other"));
falling = true;
break;
default:
break;
}
}
if (falling) {
brush = new FallingSphere();
} else {
brush = new SphereBrush();
}
}
// FAWE end
set(context, brush, "worldedit.brush.sphere").setSize(radius).setFill(pattern);
}
use of com.sk89q.worldedit.command.tool.brush.Brush in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method blobBrush.
@Command(name = "rock", aliases = { "blob" }, desc = "Creates a distorted sphere")
@CommandPermissions("worldedit.brush.rock")
public void blobBrush(InjectedValueAccess context, @Arg(desc = "Pattern") Pattern fill, @Arg(desc = "radii to multiply x,y,z by", def = "10") Vector3 radius, @Arg(name = "roundness", desc = "roundness", def = "100") double sphericity, @Arg(desc = "double", def = "30") double frequency, @Arg(desc = "double", def = "50") double amplitude) throws WorldEditException {
double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ());
worldEdit.checkMaxBrushRadius(max);
Brush brush = new BlobBrush(radius.divide(max), frequency / 100, amplitude / 100, sphericity / 100);
set(context, brush, "worldedit.brush.rock").setSize(max).setFill(fill);
}
use of com.sk89q.worldedit.command.tool.brush.Brush in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method set.
public BrushSettings set(InjectedValueAccess context, Brush brush, String permission) throws InvalidToolBindException {
Player player = context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"));
LocalSession session = player.getSession();
BrushSettings bs = new BrushSettings();
BrushTool tool = session.getBrushTool(player, false);
if (tool != null) {
BrushSettings currentContext = tool.getContext();
if (currentContext != null) {
Brush currentBrush = currentContext.getBrush();
if (currentBrush != null && currentBrush.getClass() == brush.getClass()) {
bs = currentContext;
}
}
}
Arguments arguments = context.injectedValue(Key.of(Arguments.class)).orElse(null);
if (arguments != null) {
String args = arguments.get();
bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1));
}
bs.addPermission(permission);
bs.setBrush(brush);
return process(player, arguments, bs);
}
use of com.sk89q.worldedit.command.tool.brush.Brush in project FastAsyncWorldEdit by IntellectualSites.
the class BrushTool method act.
public boolean act(BrushAction action, Player player, LocalSession session) {
switch(action) {
case PRIMARY:
setContext(primary);
break;
case SECONDARY:
setContext(secondary);
break;
default:
throw new IllegalStateException("Unexpected value: " + action);
}
BrushSettings current = getContext();
Brush brush = current.getBrush();
if (brush == null) {
return false;
}
if (!current.canUse(player)) {
player.print(Caption.of("fawe.error.no-perm", StringMan.join(current.getPermissions(), ",")));
return false;
}
try (EditSession editSession = session.createEditSession(player, current.toString())) {
Location target = player.getBlockTrace(getRange(), true, traceMask);
if (target == null) {
editSession.cancel();
player.print(Caption.of("worldedit.tool.no-block"));
return true;
}
BlockBag bag = session.getBlockBag(player);
Request.request().setEditSession(editSession);
Mask mask = current.getMask();
if (mask != null) {
Mask existingMask = editSession.getMask();
if (existingMask == null) {
editSession.setMask(mask);
} else if (existingMask instanceof MaskIntersection) {
((MaskIntersection) existingMask).add(mask);
} else {
MaskIntersection newMask = new MaskIntersection(existingMask);
newMask.add(mask);
editSession.setMask(newMask);
}
}
Mask sourceMask = current.getSourceMask();
if (sourceMask != null) {
editSession.addSourceMask(sourceMask);
}
ResettableExtent transform = current.getTransform();
if (transform != null) {
editSession.addTransform(transform);
}
try {
new PatternTraverser(current).reset(editSession);
double size = current.getSize();
WorldEdit.getInstance().checkMaxBrushRadius(size);
brush.build(editSession, target.toBlockPoint(), current.getMaterial(), size);
} catch (MaxChangedBlocksException e) {
player.print(Caption.of("worldedit.tool.max-block-changes"));
} finally {
session.remember(editSession);
if (bag != null) {
bag.flushChanges();
}
}
} finally {
Request.reset();
}
return true;
}
Aggregations