Added argument for catenary direction

This commit is contained in:
Jesse Boyd 2018-07-21 22:42:15 +10:00
parent 074cf281c9
commit dc593a4667
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 28 additions and 7 deletions

View File

@ -131,6 +131,7 @@ public enum BBC {
BRUSH_SMOOTH("Note: Use the blend brush if you want to smooth overhangs or caves.", "WorldEdit.Brush"), BRUSH_SMOOTH("Note: Use the blend brush if you want to smooth overhangs or caves.", "WorldEdit.Brush"),
BRUSH_SPLINE("Click to add a point, click the same spot to finish", "WorldEdit.Brush"), BRUSH_SPLINE("Click to add a point, click the same spot to finish", "WorldEdit.Brush"),
BRUSH_LINE_PRIMARY("Added point %s0, click another position to create the line", "WorldEdit.Brush"), BRUSH_LINE_PRIMARY("Added point %s0, click another position to create the line", "WorldEdit.Brush"),
BRUSH_CATENARY_DIRECTION("Added point %s0, click the direction you want to create the spline", "WorldEdit.Brush"),
BRUSH_LINE_SECONDARY("Created spline", "WorldEdit.Brush"), BRUSH_LINE_SECONDARY("Created spline", "WorldEdit.Brush"),
BRUSH_SPLINE_PRIMARY_2("Added position, Click the same spot to join!", "WorldEdit.Brush"), BRUSH_SPLINE_PRIMARY_2("Added position, Click the same spot to join!", "WorldEdit.Brush"),
BRUSH_SPLINE_SECONDARY_ERROR("Not enough positions set!", "WorldEdit.Brush"), BRUSH_SPLINE_SECONDARY_ERROR("Not enough positions set!", "WorldEdit.Brush"),

View File

@ -7,18 +7,24 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.util.Location;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class CatenaryBrush implements Brush, ResettableTool { public class CatenaryBrush implements Brush, ResettableTool {
private final boolean shell, select; private final boolean shell, select, direction;
private final double slack; private final double slack;
private Vector pos1;
public CatenaryBrush(boolean shell, boolean select, double lengthFactor) { private Vector pos1;
private Vector pos2;
private Vector vertex;
public CatenaryBrush(boolean shell, boolean select, boolean direction, double lengthFactor) {
this.shell = shell; this.shell = shell;
this.select = select; this.select = select;
this.direction = direction;
this.slack = lengthFactor; this.slack = lengthFactor;
} }
@ -32,8 +38,21 @@ public class CatenaryBrush implements Brush, ResettableTool {
} }
return; return;
} }
Vector vertex = getVertex(pos1, pos2, slack); if (this.vertex == null) {
vertex = getVertex(pos1, pos2, slack);
if (this.direction) {
BBC.BRUSH_CATENARY_DIRECTION.send(editSession.getPlayer(), 2);
return;
}
} else if (this.direction) {
Location loc = editSession.getPlayer().getPlayer().getLocation();
Vector facing = loc.getDirection().normalize();
Vector midpoint = pos1.add(pos2).divide(2);
Vector offset = midpoint.subtract(vertex);
vertex = midpoint.add(facing.multiply(offset.length()));
}
List<Vector> nodes = Arrays.asList(pos1, vertex, pos2); List<Vector> nodes = Arrays.asList(pos1, vertex, pos2);
vertex = null;
editSession.drawSpline(pattern, nodes, 0, 0, 0, 10, size, !shell); editSession.drawSpline(pattern, nodes, 0, 0, 0, 10, size, !shell);
if (!visual) { if (!visual) {
BBC.BRUSH_LINE_SECONDARY.send(editSession.getPlayer()); BBC.BRUSH_LINE_SECONDARY.send(editSession.getPlayer());

View File

@ -221,15 +221,16 @@ public class BrushCommands extends BrushProcessor {
help = "Create a hanging line between two points.\n" + help = "Create a hanging line between two points.\n" +
"The lengthFactor controls how long the line is\n" + "The lengthFactor controls how long the line is\n" +
"The -h flag creates only a shell\n" + "The -h flag creates only a shell\n" +
"The -s flag selects the clicked point after drawing\n", "The -s flag selects the clicked point after drawing\n" +
"The -d flag sags the catenary toward the facing direction\n",
min = 1, min = 1,
max = 3 max = 3
) )
@CommandPermissions("worldedit.brush.spline") @CommandPermissions("worldedit.brush.spline")
public BrushSettings catenaryBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("1.2") @Range(min=1) double lengthFactor, @Optional("0") double radius, @Switch('h') boolean shell, @Switch('s') boolean select, CommandContext context) throws WorldEditException { public BrushSettings catenaryBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("1.2") @Range(min=1) double lengthFactor, @Optional("0") double radius, @Switch('h') boolean shell, @Switch('s') boolean select, @Switch('d') boolean facingDirection, CommandContext context) throws WorldEditException {
getWorldEdit().checkMaxBrushRadius(radius); getWorldEdit().checkMaxBrushRadius(radius);
return set(session, context, return set(session, context,
new CatenaryBrush(shell, select, lengthFactor)) new CatenaryBrush(shell, select, facingDirection, lengthFactor))
.setSize(radius) .setSize(radius)
.setFill(fill); .setFill(fill);
} }