Skip to content

Commit 0224da1

Browse files
committed
Added curve command
1 parent 6d49ae9 commit 0224da1

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/server/commands/command_list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import "./region/smooth.js";
6666
import "./region/faces.js";
6767
import "./region/hollow.js";
6868
import "./region/line.js";
69+
import "./region/curve.js";
6970
import "./region/center.js";
7071

7172
import "./utilities/fill.js";
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { assertSelection } from "@modules/assert.js";
2+
import { Pattern } from "@modules/pattern.js";
3+
import { CommandInfo, RawText, regionBounds } from "@notbeer-api";
4+
import { registerCommand } from "../register_commands.js";
5+
import { Jobs } from "@modules/jobs.js";
6+
import { balloonPath, plotCurve } from "./paths_func.js";
7+
import config from "config.js";
8+
9+
const registerInformation: CommandInfo = {
10+
name: "curve",
11+
permission: "worldedit.region.curve",
12+
description: "commands.wedit:curve.description",
13+
usage: [
14+
{ name: "pattern", type: "Pattern" },
15+
{ name: "thickness", type: "int", range: [0, config.maxBrushRadius], default: 0 },
16+
],
17+
};
18+
19+
registerCommand(registerInformation, function* (session, builder, args) {
20+
assertSelection(session);
21+
if (session.selection.mode != "convex") throw "commands.wedit:curve.invalidType";
22+
if (args.get("_using_item") && session.globalPattern.empty()) throw "worldEdit.selectionFill.noPattern";
23+
const thickness = <number>args.get("thickness");
24+
25+
const points = session.selection.points;
26+
const [start, end] = session.selection.getRange();
27+
28+
const dim = builder.dimension;
29+
const pattern = (<Pattern>(args.get("_using_item") ? session.globalPattern : args.get("pattern"))).withContext(session, [start, end]);
30+
const mask = session.globalMask.withContext(session);
31+
let count: number;
32+
33+
yield* Jobs.run(session, 1, function* () {
34+
const history = session.history;
35+
const record = history.record();
36+
try {
37+
const blocks = yield* balloonPath(plotCurve(points), thickness);
38+
const [start, end] = regionBounds(blocks);
39+
40+
yield* history.trackRegion(record, start, end);
41+
count = 0;
42+
for (const point of blocks) {
43+
const block = dim.getBlock(point) ?? (yield* Jobs.loadBlock(point));
44+
if (mask.matchesBlock(block) && pattern.setBlock(block)) count++;
45+
yield;
46+
}
47+
48+
history.trackSelection(record);
49+
yield* history.commit(record);
50+
} catch (e) {
51+
history.cancel(record);
52+
throw e;
53+
}
54+
});
55+
56+
return RawText.translate("commands.blocks.wedit:changed").with(`${count}`);
57+
});

texts/en_US.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ msgid "commands.wedit:count.description"
487487
msgstr "Count the number of blocks that match a mask"
488488
msgid "commands.wedit:count.explain"
489489
msgstr "Found %s blocks."
490+
msgid "commands.wedit:curve.description"
491+
msgstr "Create a curve between multiple selection points"
492+
msgid "commands.wedit:curve.invalidType"
493+
msgstr "this command only works with convex selections"
490494
msgid "commands.wedit:cut.description"
491495
msgstr "Remove your current selection and place it in the clipboard"
492496
msgid "commands.wedit:cut.explain"

0 commit comments

Comments
 (0)