redscript-mc 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast/types.d.ts +1 -0
- package/dist/lowering/index.js +3 -2
- package/dist/parser/index.js +13 -1
- package/examples/spiral.mcrs +4 -2
- package/package.json +1 -1
- package/src/ast/types.ts +1 -1
- package/src/lowering/index.ts +3 -2
- package/src/parser/index.ts +15 -1
package/dist/ast/types.d.ts
CHANGED
package/dist/lowering/index.js
CHANGED
|
@@ -757,8 +757,9 @@ class Lowering {
|
|
|
757
757
|
// Extract body into a separate function
|
|
758
758
|
const subFnName = `${this.currentFn}/foreach_${this.foreachCounter++}`;
|
|
759
759
|
const selector = this.exprToString(stmt.iterable);
|
|
760
|
-
// Emit execute as ... run function ...
|
|
761
|
-
|
|
760
|
+
// Emit execute as ... [context modifiers] run function ...
|
|
761
|
+
const execContext = stmt.executeContext ? ` ${stmt.executeContext}` : '';
|
|
762
|
+
this.builder.emitRaw(`execute as ${selector}${execContext} run function ${this.namespace}:${subFnName}`);
|
|
762
763
|
// Create the sub-function
|
|
763
764
|
const savedBuilder = this.builder;
|
|
764
765
|
const savedVarMap = new Map(this.varMap);
|
package/dist/parser/index.js
CHANGED
|
@@ -534,8 +534,20 @@ class Parser {
|
|
|
534
534
|
this.expect('in');
|
|
535
535
|
const iterable = this.parseExpr();
|
|
536
536
|
this.expect(')');
|
|
537
|
+
// Parse optional execute context modifiers (at, positioned, rotated, facing, etc.)
|
|
538
|
+
let executeContext;
|
|
539
|
+
// Check for 'at' keyword or identifiers like 'positioned', 'rotated', 'facing', 'anchored', 'align'
|
|
540
|
+
const execIdentKeywords = ['positioned', 'rotated', 'facing', 'anchored', 'align'];
|
|
541
|
+
if (this.check('at') || this.check('in') || (this.check('ident') && execIdentKeywords.includes(this.peek().value))) {
|
|
542
|
+
// Collect everything until we hit '{'
|
|
543
|
+
let context = '';
|
|
544
|
+
while (!this.check('{') && !this.check('eof')) {
|
|
545
|
+
context += this.advance().value + ' ';
|
|
546
|
+
}
|
|
547
|
+
executeContext = context.trim();
|
|
548
|
+
}
|
|
537
549
|
const body = this.parseBlock();
|
|
538
|
-
return this.withLoc({ kind: 'foreach', binding, iterable, body }, foreachToken);
|
|
550
|
+
return this.withLoc({ kind: 'foreach', binding, iterable, body, executeContext }, foreachToken);
|
|
539
551
|
}
|
|
540
552
|
parseMatchStmt() {
|
|
541
553
|
const matchToken = this.expect('match');
|
package/examples/spiral.mcrs
CHANGED
|
@@ -12,8 +12,10 @@ let running: bool = false;
|
|
|
12
12
|
// 每 tick 增加计数器
|
|
13
13
|
counter = counter + 1;
|
|
14
14
|
|
|
15
|
-
//
|
|
16
|
-
|
|
15
|
+
// 在每个玩家位置生成粒子
|
|
16
|
+
foreach (p in @a) at @s {
|
|
17
|
+
particle("minecraft:end_rod", ~0, ~1, ~0, 0.5, 0.5, 0.5, 0.1, 5);
|
|
18
|
+
}
|
|
17
19
|
|
|
18
20
|
// 每 20 ticks (1秒) 报告一次
|
|
19
21
|
if (counter % 20 == 0) {
|
package/package.json
CHANGED
package/src/ast/types.ts
CHANGED
|
@@ -192,7 +192,7 @@ export type Stmt =
|
|
|
192
192
|
| { kind: 'if'; cond: Expr; then: Block; else_?: Block; span?: Span }
|
|
193
193
|
| { kind: 'while'; cond: Expr; body: Block; span?: Span }
|
|
194
194
|
| { kind: 'for'; init?: Stmt; cond: Expr; step: Expr; body: Block; span?: Span }
|
|
195
|
-
| { kind: 'foreach'; binding: string; iterable: Expr; body: Block; span?: Span }
|
|
195
|
+
| { kind: 'foreach'; binding: string; iterable: Expr; body: Block; executeContext?: string; span?: Span }
|
|
196
196
|
| { kind: 'for_range'; varName: string; start: Expr; end: Expr; body: Block; span?: Span }
|
|
197
197
|
| { kind: 'match'; expr: Expr; arms: { pattern: Expr | null; body: Block }[]; span?: Span }
|
|
198
198
|
| { kind: 'as_block'; selector: EntitySelector; body: Block; span?: Span }
|
package/src/lowering/index.ts
CHANGED
|
@@ -898,8 +898,9 @@ export class Lowering {
|
|
|
898
898
|
const subFnName = `${this.currentFn}/foreach_${this.foreachCounter++}`
|
|
899
899
|
const selector = this.exprToString(stmt.iterable)
|
|
900
900
|
|
|
901
|
-
// Emit execute as ... run function ...
|
|
902
|
-
|
|
901
|
+
// Emit execute as ... [context modifiers] run function ...
|
|
902
|
+
const execContext = stmt.executeContext ? ` ${stmt.executeContext}` : ''
|
|
903
|
+
this.builder.emitRaw(`execute as ${selector}${execContext} run function ${this.namespace}:${subFnName}`)
|
|
903
904
|
|
|
904
905
|
// Create the sub-function
|
|
905
906
|
const savedBuilder = this.builder
|
package/src/parser/index.ts
CHANGED
|
@@ -645,9 +645,23 @@ export class Parser {
|
|
|
645
645
|
this.expect('in')
|
|
646
646
|
const iterable = this.parseExpr()
|
|
647
647
|
this.expect(')')
|
|
648
|
+
|
|
649
|
+
// Parse optional execute context modifiers (at, positioned, rotated, facing, etc.)
|
|
650
|
+
let executeContext: string | undefined
|
|
651
|
+
// Check for 'at' keyword or identifiers like 'positioned', 'rotated', 'facing', 'anchored', 'align'
|
|
652
|
+
const execIdentKeywords = ['positioned', 'rotated', 'facing', 'anchored', 'align']
|
|
653
|
+
if (this.check('at') || this.check('in') || (this.check('ident') && execIdentKeywords.includes(this.peek().value))) {
|
|
654
|
+
// Collect everything until we hit '{'
|
|
655
|
+
let context = ''
|
|
656
|
+
while (!this.check('{') && !this.check('eof')) {
|
|
657
|
+
context += this.advance().value + ' '
|
|
658
|
+
}
|
|
659
|
+
executeContext = context.trim()
|
|
660
|
+
}
|
|
661
|
+
|
|
648
662
|
const body = this.parseBlock()
|
|
649
663
|
|
|
650
|
-
return this.withLoc({ kind: 'foreach', binding, iterable, body }, foreachToken)
|
|
664
|
+
return this.withLoc({ kind: 'foreach', binding, iterable, body, executeContext }, foreachToken)
|
|
651
665
|
}
|
|
652
666
|
|
|
653
667
|
private parseMatchStmt(): Stmt {
|