redscript-mc 1.2.14 → 1.2.15

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.
@@ -50,10 +50,8 @@ const types_1 = require("../events/types");
50
50
  // as literal values (coordinates, entity types, block types), so they
51
51
  // require MC macro syntax when called with runtime variables.
52
52
  // ---------------------------------------------------------------------------
53
- const MACRO_AWARE_BUILTINS = new Set([
54
- 'summon', 'particle', 'setblock', 'fill', 'clone',
55
- 'playsound', 'tp', 'tp_to', 'effect', 'effect_clear', 'give',
56
- ]);
53
+ // All builtins support macro parameters - any arg that's a function param
54
+ // will automatically use MC 1.20.2+ macro syntax when needed
57
55
  // ---------------------------------------------------------------------------
58
56
  // Builtin Functions
59
57
  // ---------------------------------------------------------------------------
@@ -313,7 +311,7 @@ class Lowering {
313
311
  }
314
312
  }
315
313
  preScanExpr(expr, paramNames, macroParams) {
316
- if (expr.kind === 'call' && MACRO_AWARE_BUILTINS.has(expr.fn)) {
314
+ if (expr.kind === 'call' && BUILTINS[expr.fn] !== undefined) {
317
315
  // All ident args to macro-aware builtins that are params → macro params
318
316
  for (const arg of expr.args) {
319
317
  if (arg.kind === 'ident' && paramNames.has(arg.name)) {
@@ -2197,28 +2195,17 @@ class Lowering {
2197
2195
  }
2198
2196
  return { kind: 'const', value: 0 };
2199
2197
  }
2200
- // For macro-aware builtins, check if any arg is a param needing macro treatment
2201
- if (MACRO_AWARE_BUILTINS.has(name)) {
2202
- const argResults = args.map(arg => this.exprToBuiltinArg(arg));
2203
- const hasMacroArg = argResults.some(r => r.macroParam !== undefined);
2204
- if (hasMacroArg) {
2205
- argResults.forEach(r => { if (r.macroParam)
2206
- this.currentFnMacroParams.add(r.macroParam); });
2207
- }
2208
- const strArgs = argResults.map(r => r.str);
2209
- const cmd = BUILTINS[name]?.(strArgs);
2210
- if (cmd) {
2211
- this.builder.emitRaw(hasMacroArg ? `$${cmd}` : cmd);
2212
- }
2213
- return { kind: 'const', value: 0 };
2198
+ // All builtins support macro params - check if any arg is a param needing macro treatment
2199
+ const argResults = args.map(arg => this.exprToBuiltinArg(arg));
2200
+ const hasMacroArg = argResults.some(r => r.macroParam !== undefined);
2201
+ if (hasMacroArg) {
2202
+ argResults.forEach(r => { if (r.macroParam)
2203
+ this.currentFnMacroParams.add(r.macroParam); });
2214
2204
  }
2215
- // Convert args to strings for builtin (use SNBT for struct/array literals)
2216
- const strArgs = args.map(arg => arg.kind === 'struct_lit' || arg.kind === 'array_lit'
2217
- ? this.exprToSnbt(arg)
2218
- : this.exprToString(arg));
2219
- const cmd = BUILTINS[name](strArgs);
2205
+ const strArgs = argResults.map(r => r.str);
2206
+ const cmd = BUILTINS[name]?.(strArgs);
2220
2207
  if (cmd) {
2221
- this.builder.emitRaw(cmd);
2208
+ this.builder.emitRaw(hasMacroArg ? `$${cmd}` : cmd);
2222
2209
  }
2223
2210
  return { kind: 'const', value: 0 };
2224
2211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redscript-mc",
3
- "version": "1.2.14",
3
+ "version": "1.2.15",
4
4
  "description": "A high-level programming language that compiles to Minecraft datapacks",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -25,10 +25,8 @@ import { EVENT_TYPES, getEventParamSpecs, isEventTypeName } from '../events/type
25
25
  // require MC macro syntax when called with runtime variables.
26
26
  // ---------------------------------------------------------------------------
27
27
 
28
- const MACRO_AWARE_BUILTINS = new Set([
29
- 'summon', 'particle', 'setblock', 'fill', 'clone',
30
- 'playsound', 'tp', 'tp_to', 'effect', 'effect_clear', 'give',
31
- ])
28
+ // All builtins support macro parameters - any arg that's a function param
29
+ // will automatically use MC 1.20.2+ macro syntax when needed
32
30
 
33
31
  // ---------------------------------------------------------------------------
34
32
  // Builtin Functions
@@ -335,7 +333,7 @@ export class Lowering {
335
333
  }
336
334
 
337
335
  private preScanExpr(expr: Expr, paramNames: Set<string>, macroParams: Set<string>): void {
338
- if (expr.kind === 'call' && MACRO_AWARE_BUILTINS.has(expr.fn)) {
336
+ if (expr.kind === 'call' && BUILTINS[expr.fn] !== undefined) {
339
337
  // All ident args to macro-aware builtins that are params → macro params
340
338
  for (const arg of expr.args) {
341
339
  if (arg.kind === 'ident' && paramNames.has(arg.name)) {
@@ -2528,30 +2526,16 @@ export class Lowering {
2528
2526
  return { kind: 'const', value: 0 }
2529
2527
  }
2530
2528
 
2531
- // For macro-aware builtins, check if any arg is a param needing macro treatment
2532
- if (MACRO_AWARE_BUILTINS.has(name)) {
2533
- const argResults = args.map(arg => this.exprToBuiltinArg(arg))
2534
- const hasMacroArg = argResults.some(r => r.macroParam !== undefined)
2535
- if (hasMacroArg) {
2536
- argResults.forEach(r => { if (r.macroParam) this.currentFnMacroParams.add(r.macroParam) })
2537
- }
2538
- const strArgs = argResults.map(r => r.str)
2539
- const cmd = BUILTINS[name]?.(strArgs)
2540
- if (cmd) {
2541
- this.builder.emitRaw(hasMacroArg ? `$${cmd}` : cmd)
2542
- }
2543
- return { kind: 'const', value: 0 }
2529
+ // All builtins support macro params - check if any arg is a param needing macro treatment
2530
+ const argResults = args.map(arg => this.exprToBuiltinArg(arg))
2531
+ const hasMacroArg = argResults.some(r => r.macroParam !== undefined)
2532
+ if (hasMacroArg) {
2533
+ argResults.forEach(r => { if (r.macroParam) this.currentFnMacroParams.add(r.macroParam) })
2544
2534
  }
2545
-
2546
- // Convert args to strings for builtin (use SNBT for struct/array literals)
2547
- const strArgs = args.map(arg =>
2548
- arg.kind === 'struct_lit' || arg.kind === 'array_lit'
2549
- ? this.exprToSnbt(arg)
2550
- : this.exprToString(arg)
2551
- )
2552
- const cmd = BUILTINS[name](strArgs)
2535
+ const strArgs = argResults.map(r => r.str)
2536
+ const cmd = BUILTINS[name]?.(strArgs)
2553
2537
  if (cmd) {
2554
- this.builder.emitRaw(cmd)
2538
+ this.builder.emitRaw(hasMacroArg ? `$${cmd}` : cmd)
2555
2539
  }
2556
2540
 
2557
2541
  return { kind: 'const', value: 0 }