redscript-mc 1.2.26 → 1.2.27
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/README.md +67 -9
- package/README.zh.md +61 -4
- package/dist/__tests__/stdlib-advanced.test.js +114 -0
- package/dist/__tests__/stdlib-bigint.test.d.ts +7 -0
- package/dist/__tests__/stdlib-bigint.test.js +428 -0
- package/dist/data/arena/function/__load.mcfunction +6 -0
- package/dist/data/arena/function/__tick.mcfunction +2 -0
- package/dist/data/arena/function/announce_leaders/else_1.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/then_0.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0.mcfunction +7 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders/foreach_1.mcfunction +6 -0
- package/dist/data/arena/function/announce_leaders/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders.mcfunction +6 -0
- package/dist/data/arena/function/arena_tick/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/arena_tick/then_0.mcfunction +4 -0
- package/dist/data/arena/function/arena_tick.mcfunction +11 -0
- package/dist/data/counter/function/__load.mcfunction +5 -0
- package/dist/data/counter/function/__tick.mcfunction +2 -0
- package/dist/data/counter/function/counter_tick/merge_2.mcfunction +1 -0
- package/dist/data/counter/function/counter_tick/then_0.mcfunction +3 -0
- package/dist/data/counter/function/counter_tick.mcfunction +11 -0
- package/dist/data/gcd2/function/__load.mcfunction +3 -0
- package/dist/data/gcd2/function/abs/merge_2.mcfunction +3 -0
- package/dist/data/gcd2/function/abs/then_0.mcfunction +5 -0
- package/dist/data/gcd2/function/abs.mcfunction +7 -0
- package/dist/data/gcd2/function/gcd/loop_body_1.mcfunction +7 -0
- package/dist/data/gcd2/function/gcd/loop_check_0.mcfunction +5 -0
- package/dist/data/gcd2/function/gcd/loop_exit_2.mcfunction +3 -0
- package/dist/data/gcd2/function/gcd.mcfunction +14 -0
- package/dist/data/gcd3/function/__load.mcfunction +3 -0
- package/dist/data/gcd3/function/abs/merge_2.mcfunction +3 -0
- package/dist/data/gcd3/function/abs/then_0.mcfunction +5 -0
- package/dist/data/gcd3/function/abs.mcfunction +7 -0
- package/dist/data/gcd3/function/gcd/loop_body_1.mcfunction +7 -0
- package/dist/data/gcd3/function/gcd/loop_check_0.mcfunction +5 -0
- package/dist/data/gcd3/function/gcd/loop_exit_2.mcfunction +3 -0
- package/dist/data/gcd3/function/gcd.mcfunction +14 -0
- package/dist/data/gcd3/function/test.mcfunction +7 -0
- package/dist/data/gcd3nm/function/__load.mcfunction +3 -0
- package/dist/data/gcd3nm/function/abs/merge_2.mcfunction +3 -0
- package/dist/data/gcd3nm/function/abs/then_0.mcfunction +5 -0
- package/dist/data/gcd3nm/function/abs.mcfunction +7 -0
- package/dist/data/gcd3nm/function/gcd/loop_body_1.mcfunction +7 -0
- package/dist/data/gcd3nm/function/gcd/loop_check_0.mcfunction +5 -0
- package/dist/data/gcd3nm/function/gcd/loop_exit_2.mcfunction +3 -0
- package/dist/data/gcd3nm/function/gcd.mcfunction +14 -0
- package/dist/data/gcd3nm/function/test.mcfunction +7 -0
- package/dist/data/gcd_test/function/__load.mcfunction +3 -0
- package/dist/data/gcd_test/function/abs/merge_2.mcfunction +3 -0
- package/dist/data/gcd_test/function/abs/then_0.mcfunction +5 -0
- package/dist/data/gcd_test/function/abs.mcfunction +7 -0
- package/dist/data/gcd_test/function/gcd/loop_body_1.mcfunction +7 -0
- package/dist/data/gcd_test/function/gcd/loop_check_0.mcfunction +5 -0
- package/dist/data/gcd_test/function/gcd/loop_exit_2.mcfunction +3 -0
- package/dist/data/gcd_test/function/gcd.mcfunction +14 -0
- package/dist/data/isqrttest/function/__load.mcfunction +6 -0
- package/dist/data/isqrttest/function/isqrt/loop_body_4.mcfunction +12 -0
- package/dist/data/isqrttest/function/isqrt/loop_check_3.mcfunction +5 -0
- package/dist/data/isqrttest/function/isqrt/loop_exit_5.mcfunction +3 -0
- package/dist/data/isqrttest/function/isqrt/merge_2.mcfunction +4 -0
- package/dist/data/isqrttest/function/isqrt/merge_8.mcfunction +6 -0
- package/dist/data/isqrttest/function/isqrt/then_0.mcfunction +3 -0
- package/dist/data/isqrttest/function/isqrt/then_6.mcfunction +3 -0
- package/dist/data/isqrttest/function/isqrt.mcfunction +7 -0
- package/dist/data/isqrttest/function/test.mcfunction +6 -0
- package/dist/data/mathtest/function/__load.mcfunction +3 -0
- package/dist/data/mathtest/function/abs/merge_2.mcfunction +3 -0
- package/dist/data/mathtest/function/abs/then_0.mcfunction +5 -0
- package/dist/data/mathtest/function/abs.mcfunction +6 -0
- package/dist/data/mathtest/function/test.mcfunction +5 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/minecraft/tags/function/tick.json +5 -0
- package/dist/data/mypack/function/__load.mcfunction +13 -0
- package/dist/data/mypack/function/_atan_init.mcfunction +2 -0
- package/dist/data/mypack/function/abs/merge_2.mcfunction +3 -0
- package/dist/data/mypack/function/abs/then_0.mcfunction +5 -0
- package/dist/data/mypack/function/abs.mcfunction +6 -0
- package/dist/data/mypack/function/atan2_fixed/__sgi_1.mcfunction +2 -0
- package/dist/data/mypack/function/atan2_fixed/else_34.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/loop_body_31.mcfunction +19 -0
- package/dist/data/mypack/function/atan2_fixed/loop_check_30.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/loop_exit_32.mcfunction +6 -0
- package/dist/data/mypack/function/atan2_fixed/merge_11.mcfunction +6 -0
- package/dist/data/mypack/function/atan2_fixed/merge_14.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/merge_17.mcfunction +6 -0
- package/dist/data/mypack/function/atan2_fixed/merge_2.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/merge_20.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/merge_23.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/merge_26.mcfunction +6 -0
- package/dist/data/mypack/function/atan2_fixed/merge_29.mcfunction +4 -0
- package/dist/data/mypack/function/atan2_fixed/merge_38.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/merge_41.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/merge_44.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/merge_47.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/merge_5.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/merge_8.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/then_0.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/then_12.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/then_15.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/then_18.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/then_21.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/then_24.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/then_27.mcfunction +6 -0
- package/dist/data/mypack/function/atan2_fixed/then_3.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/then_33.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/then_36.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/then_39.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/then_42.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/then_45.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed/then_6.mcfunction +3 -0
- package/dist/data/mypack/function/atan2_fixed/then_9.mcfunction +5 -0
- package/dist/data/mypack/function/atan2_fixed.mcfunction +7 -0
- package/dist/data/mypack/function/my_game.mcfunction +10 -0
- package/dist/data/quiz/function/__load.mcfunction +16 -0
- package/dist/data/quiz/function/__tick.mcfunction +6 -0
- package/dist/data/quiz/function/__trigger_quiz_a_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_b_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_c_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_start_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/answer_a.mcfunction +4 -0
- package/dist/data/quiz/function/answer_b.mcfunction +4 -0
- package/dist/data/quiz/function/answer_c.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_4.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_7.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/merge_2.mcfunction +1 -0
- package/dist/data/quiz/function/ask_question/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/then_0.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_3.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_6.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question.mcfunction +7 -0
- package/dist/data/quiz/function/finish_quiz.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/else_10.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_16.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_4.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_7.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/merge_11.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_14.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_17.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_2.mcfunction +8 -0
- package/dist/data/quiz/function/handle_answer/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/then_0.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_12.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_15.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_3.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_6.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_9.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer.mcfunction +11 -0
- package/dist/data/quiz/function/start_quiz.mcfunction +5 -0
- package/dist/data/reqtest/function/__load.mcfunction +4 -0
- package/dist/data/reqtest/function/_table_init.mcfunction +2 -0
- package/dist/data/reqtest/function/no_trig.mcfunction +3 -0
- package/dist/data/reqtest/function/use_table.mcfunction +4 -0
- package/dist/data/reqtest2/function/__load.mcfunction +3 -0
- package/dist/data/reqtest2/function/no_trig.mcfunction +3 -0
- package/dist/data/runtime/function/__load.mcfunction +5 -0
- package/dist/data/runtime/function/__tick.mcfunction +2 -0
- package/dist/data/runtime/function/counter_tick/then_0.mcfunction +3 -0
- package/dist/data/runtime/function/counter_tick.mcfunction +13 -0
- package/dist/data/shop/function/__load.mcfunction +7 -0
- package/dist/data/shop/function/__tick.mcfunction +3 -0
- package/dist/data/shop/function/__trigger_shop_buy_dispatch.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/else_1.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_4.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_7.mcfunction +3 -0
- package/dist/data/shop/function/complete_purchase/merge_2.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_5.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_8.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/then_0.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_3.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_6.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase.mcfunction +7 -0
- package/dist/data/shop/function/handle_shop_trigger.mcfunction +3 -0
- package/dist/data/swap_test/function/__load.mcfunction +3 -0
- package/dist/data/swap_test/function/gcd_old/loop_body_1.mcfunction +7 -0
- package/dist/data/swap_test/function/gcd_old/loop_check_0.mcfunction +5 -0
- package/dist/data/swap_test/function/gcd_old/loop_exit_2.mcfunction +3 -0
- package/dist/data/swap_test/function/gcd_old.mcfunction +8 -0
- package/dist/data/turret/function/__load.mcfunction +5 -0
- package/dist/data/turret/function/__tick.mcfunction +4 -0
- package/dist/data/turret/function/__trigger_deploy_turret_dispatch.mcfunction +4 -0
- package/dist/data/turret/function/deploy_turret.mcfunction +8 -0
- package/dist/data/turret/function/turret_tick/at_1.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_0.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_2.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/tick_body.mcfunction +3 -0
- package/dist/data/turret/function/turret_tick/tick_skip.mcfunction +1 -0
- package/dist/data/turret/function/turret_tick.mcfunction +5 -0
- package/dist/gcd2.map.json +15 -0
- package/dist/gcd3.map.json +17 -0
- package/dist/gcd_test.map.json +15 -0
- package/dist/isqrttest.map.json +15 -0
- package/dist/lowering/index.js +71 -4
- package/dist/mathtest.map.json +6 -0
- package/dist/mypack.map.json +27 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/reqtest.map.json +4 -0
- package/dist/reqtest2.map.json +4 -0
- package/dist/runtime/index.js +26 -5
- package/dist/runtime.map.json +7 -0
- package/dist/swap_test.map.json +14 -0
- package/editors/vscode/package-lock.json +2 -2
- package/editors/vscode/package.json +1 -1
- package/examples/showcase.mcrs +505 -0
- package/package.json +1 -1
- package/src/__tests__/stdlib-advanced.test.ts +120 -0
- package/src/__tests__/stdlib-bigint.test.ts +427 -0
- package/src/lowering/index.ts +75 -4
- package/src/runtime/index.ts +27 -5
- package/src/stdlib/advanced.mcrs +81 -0
- package/src/stdlib/bigint.mcrs +205 -0
- package/src/stdlib/math.mcrs +19 -6
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
// ╔══════════════════════════════════════════════════════════════════════╗
|
|
2
|
+
// ║ RedScript v1.2.26 — Capability Showcase ║
|
|
3
|
+
// ║ ║
|
|
4
|
+
// ║ Demonstrates every major feature in one datapack: ║
|
|
5
|
+
// ║ • Math stdlib: sin/cos table, sqrt_fixed, atan2, smoothstep ║
|
|
6
|
+
// ║ • Vec stdlib: 2D length, normalize, rotate ║
|
|
7
|
+
// ║ • BigInt: arbitrary-precision Fibonacci up to F(100) ║
|
|
8
|
+
// ║ • Advanced: primes, Collatz, Bézier, noise, Mandelbrot ║
|
|
9
|
+
// ║ • Language: structs, impl blocks, enums, match, lambdas, ║
|
|
10
|
+
// ║ @tick/@load, foreach, f-strings, break/continue ║
|
|
11
|
+
// ║ • Game effects: particles, actionbar, fireworks, titles ║
|
|
12
|
+
// ║ ║
|
|
13
|
+
// ║ Usage: ║
|
|
14
|
+
// ║ /function showcase:start begin the showcase ║
|
|
15
|
+
// ║ /function showcase:stop stop everything ║
|
|
16
|
+
// ║ /function showcase:dump_math print math table to chat ║
|
|
17
|
+
// ║ /function showcase:dump_bigint print Fibonacci to chat ║
|
|
18
|
+
// ╚══════════════════════════════════════════════════════════════════════╝
|
|
19
|
+
|
|
20
|
+
import "../src/stdlib/math.mcrs"
|
|
21
|
+
import "../src/stdlib/vec.mcrs"
|
|
22
|
+
import "../src/stdlib/bigint.mcrs"
|
|
23
|
+
import "../src/stdlib/advanced.mcrs"
|
|
24
|
+
|
|
25
|
+
// ── Enums ─────────────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
enum Phase {
|
|
28
|
+
Idle, // 0 — waiting
|
|
29
|
+
Math, // 1 — trig / fixed-point showcase
|
|
30
|
+
BigInt, // 2 — arbitrary-precision arithmetic
|
|
31
|
+
Advanced, // 3 — primes, noise, fractals
|
|
32
|
+
Visual, // 4 — live particle ring + sin/cos actionbar
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ── State struct ───────────────────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
struct ShowcaseState {
|
|
38
|
+
phase: int, // current Phase
|
|
39
|
+
tick: int, // frame counter since start
|
|
40
|
+
angle: int, // 0–359 degrees; advances 2°/tick during Visual phase
|
|
41
|
+
running: bool
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let state: ShowcaseState = {
|
|
45
|
+
phase: 0,
|
|
46
|
+
tick: 0,
|
|
47
|
+
angle: 0,
|
|
48
|
+
running: false
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// ── Timer (OOP demo) ───────────────────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
struct ptimer {
|
|
54
|
+
interval: int, // ticks between phase advances
|
|
55
|
+
elapsed: int
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
impl ptimer {
|
|
59
|
+
fn new(interval: int) -> ptimer {
|
|
60
|
+
return { interval: interval, elapsed: 0 };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn tick(self) -> bool {
|
|
64
|
+
self.elapsed = self.elapsed + 1;
|
|
65
|
+
if (self.elapsed >= self.interval) {
|
|
66
|
+
self.elapsed = 0;
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fn reset(self) {
|
|
73
|
+
self.elapsed = 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let phase_timer: ptimer = { interval: 200, elapsed: 0 }; // advance every 10 seconds
|
|
78
|
+
|
|
79
|
+
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
fn _divider() {
|
|
82
|
+
say("§8§m══════════════════════════════");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
fn _section(title: string) {
|
|
86
|
+
_divider();
|
|
87
|
+
say(f"§6§l {title}");
|
|
88
|
+
_divider();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Format a fixed-point ×1000 value as "X.XXX"
|
|
92
|
+
fn _fp(n: int) -> int {
|
|
93
|
+
// Just return raw for now; f-string handles display
|
|
94
|
+
return n;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── @load ─────────────────────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
@load
|
|
100
|
+
fn showcase_load() {
|
|
101
|
+
say("§a[Showcase] §rRedScript v1.2.26 loaded.");
|
|
102
|
+
say("§7 /function showcase:start §f— begin the showcase");
|
|
103
|
+
say("§7 /function showcase:dump_math §f— print math tables");
|
|
104
|
+
say("§7 /function showcase:dump_bigint §f— print big Fibonacci numbers");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ── @tick ──────────────────────────────────────────────────────────────────
|
|
108
|
+
|
|
109
|
+
@tick
|
|
110
|
+
fn showcase_tick() {
|
|
111
|
+
if (!state.running) { return; }
|
|
112
|
+
|
|
113
|
+
state.tick = state.tick + 1;
|
|
114
|
+
|
|
115
|
+
// Advance phase on timer
|
|
116
|
+
if (phase_timer.tick()) {
|
|
117
|
+
_next_phase();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Per-phase work
|
|
121
|
+
match (state.phase) {
|
|
122
|
+
Phase.Math => { _tick_math(); }
|
|
123
|
+
Phase.BigInt => { _tick_bigint_live(); }
|
|
124
|
+
Phase.Advanced => { _tick_advanced_live(); }
|
|
125
|
+
Phase.Visual => { _tick_visual(); }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
fn _next_phase() {
|
|
130
|
+
state.phase = state.phase + 1;
|
|
131
|
+
if (state.phase > 4) { state.phase = 1; }
|
|
132
|
+
|
|
133
|
+
match (state.phase) {
|
|
134
|
+
Phase.Math => { _dump_math_phase(); }
|
|
135
|
+
Phase.BigInt => { _dump_bigint_phase(); }
|
|
136
|
+
Phase.Advanced => { _dump_advanced_phase(); }
|
|
137
|
+
Phase.Visual => {
|
|
138
|
+
_section("Live Visual FX");
|
|
139
|
+
say("§bOrbital ring + live sin/cos on actionbar.");
|
|
140
|
+
say("§7(runs for 10 seconds, then loops back to Math)");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ── Phase 1: Math Stdlib ──────────────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
fn _dump_math_phase() {
|
|
148
|
+
_section("Math Stdlib — Fixed-Point Trigonometry");
|
|
149
|
+
|
|
150
|
+
// Sin/cos table samples
|
|
151
|
+
say("§eTrig (×1000 fixed-point):");
|
|
152
|
+
let deg: int = 0;
|
|
153
|
+
while (deg <= 90) {
|
|
154
|
+
let s: int = sin_fixed(deg);
|
|
155
|
+
let c: int = cos_fixed(deg);
|
|
156
|
+
say(f" sin({deg}°)={s} cos({deg}°)={c}");
|
|
157
|
+
deg = deg + 15;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// sqrt, pow, gcd, lcm
|
|
161
|
+
say("§eRoots & Powers:");
|
|
162
|
+
say(f" sqrt_fixed(2) = {sqrt_fixed(2)} (expect 1414)");
|
|
163
|
+
say(f" sqrt_fixed(3) = {sqrt_fixed(3)} (expect 1732)");
|
|
164
|
+
say(f" isqrt(360000000000) = {isqrt(360000000000)} (expect 600000)");
|
|
165
|
+
say(f" pow_int(2, 20) = {pow_int(2, 20)} (expect 1048576)");
|
|
166
|
+
|
|
167
|
+
say("§eNumber Theory:");
|
|
168
|
+
say(f" gcd(48, 36) = {gcd(48, 36)} (expect 12)");
|
|
169
|
+
say(f" lcm(4, 6) = {lcm(4, 6)} (expect 12)");
|
|
170
|
+
say(f" log2_int(1024) = {log2_int(1024)} (expect 10)");
|
|
171
|
+
|
|
172
|
+
say("§eInterpolation:");
|
|
173
|
+
say(f" lerp(0, 1000, 250) = {lerp(0, 1000, 250)} (expect 250)");
|
|
174
|
+
say(f" smoothstep(0,1000,0) = {smoothstep(0, 1000, 0)}");
|
|
175
|
+
say(f" smoothstep(0,1000,500) = {smoothstep(0, 1000, 500)} (expect ~500)");
|
|
176
|
+
say(f" smoothstep(0,1000,1000)= {smoothstep(0, 1000, 1000)}");
|
|
177
|
+
say(f" smootherstep(0,1000,500)={smootherstep(0, 1000, 500)}");
|
|
178
|
+
|
|
179
|
+
say("§eFixed-Point Multiply/Divide:");
|
|
180
|
+
say(f" mulfix(1414, 1414) = {mulfix(1414, 1414)} (≈ 2×1000=2000)");
|
|
181
|
+
say(f" divfix(1000, 3) = {divfix(1000, 3)} (≈ 333)");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
fn _tick_math() {
|
|
185
|
+
// Animate: show atan2 of a rotating unit vector on actionbar
|
|
186
|
+
state.angle = (state.angle + 3) % 360;
|
|
187
|
+
let s: int = sin_fixed(state.angle);
|
|
188
|
+
let c: int = cos_fixed(state.angle);
|
|
189
|
+
let theta: int = atan2_fixed(s, c); // returns degrees directly
|
|
190
|
+
foreach (p in @a[limit=1]) {
|
|
191
|
+
actionbar(p, f"§bsin={s} §dcos={c} §eatan2={theta}°");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ── Phase 2: BigInt ───────────────────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
fn _dump_bigint_phase() {
|
|
198
|
+
_section("BigInt — 32-Digit Arbitrary Precision");
|
|
199
|
+
|
|
200
|
+
say("§eFibonacci sequence (BigInt, base-10000 limbs):");
|
|
201
|
+
|
|
202
|
+
// Small Fibonacci — fits in single limb
|
|
203
|
+
let i: int = 0;
|
|
204
|
+
while (i <= 20) {
|
|
205
|
+
bigint_fib(i);
|
|
206
|
+
let v: int = bigint_get_a(0);
|
|
207
|
+
say(f" F({i}) = {v}");
|
|
208
|
+
i = i + 5;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// F(50) = 12,586,269,025 (3 limbs)
|
|
212
|
+
bigint_fib(50);
|
|
213
|
+
let f50_2: int = bigint_get_a(2);
|
|
214
|
+
let f50_1: int = bigint_get_a(1);
|
|
215
|
+
let f50_0: int = bigint_get_a(0);
|
|
216
|
+
say(f" F(50) = {f50_2}_{f50_1}_{f50_0} [= 12,586,269,025]");
|
|
217
|
+
|
|
218
|
+
// F(100) = 354,224,848,179,261,915,075 (6 limbs)
|
|
219
|
+
bigint_fib(100);
|
|
220
|
+
let f100_5: int = bigint_get_a(5);
|
|
221
|
+
let f100_4: int = bigint_get_a(4);
|
|
222
|
+
let f100_3: int = bigint_get_a(3);
|
|
223
|
+
let f100_2: int = bigint_get_a(2);
|
|
224
|
+
let f100_1: int = bigint_get_a(1);
|
|
225
|
+
let f100_0: int = bigint_get_a(0);
|
|
226
|
+
say(f" F(100)= {f100_5}_{f100_4}_{f100_3}_{f100_2}_{f100_1}_{f100_0}");
|
|
227
|
+
say(f" [= 354,224,848,179,261,915,075]");
|
|
228
|
+
|
|
229
|
+
// BigInt multiplication: 999999999 × 999999999
|
|
230
|
+
say("§eBigInt Multiply:");
|
|
231
|
+
bigint_init();
|
|
232
|
+
bigint_from_int_a(999999999);
|
|
233
|
+
bigint_from_int_b(999999999);
|
|
234
|
+
bigint_mul();
|
|
235
|
+
let m2: int = bigint_get_c(2);
|
|
236
|
+
let m1: int = bigint_get_c(1);
|
|
237
|
+
let m0: int = bigint_get_c(0);
|
|
238
|
+
say(f" 999999999² = {m2}_{m1}_{m0}");
|
|
239
|
+
say(f" [= 999999998_000000001]");
|
|
240
|
+
|
|
241
|
+
// BigInt subtract
|
|
242
|
+
say("§eBigInt Subtract:");
|
|
243
|
+
bigint_init();
|
|
244
|
+
bigint_from_int_a(1000000000);
|
|
245
|
+
bigint_from_int_b(1);
|
|
246
|
+
bigint_sub();
|
|
247
|
+
let s0: int = bigint_get_c(0);
|
|
248
|
+
let s1: int = bigint_get_c(1);
|
|
249
|
+
say(f" 1,000,000,000 - 1 = {s1}_{s0} [= 999999999]");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
fn _tick_bigint_live() {
|
|
253
|
+
// Show incremental Fibonacci on actionbar
|
|
254
|
+
if (state.tick % 10 == 0) {
|
|
255
|
+
let n: int = (state.tick / 10) % 30;
|
|
256
|
+
bigint_fib(n);
|
|
257
|
+
let v0: int = bigint_get_a(0);
|
|
258
|
+
let v1: int = bigint_get_a(1);
|
|
259
|
+
foreach (p in @a[limit=1]) {
|
|
260
|
+
actionbar(p, f"§dF({n}) limb[1]={v1} limb[0]={v0}");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ── Phase 3: Advanced Stdlib ──────────────────────────────────────────────
|
|
266
|
+
|
|
267
|
+
fn _dump_advanced_phase() {
|
|
268
|
+
_section("Advanced Stdlib — Number Theory & More");
|
|
269
|
+
|
|
270
|
+
// Primes
|
|
271
|
+
say("§ePrime numbers up to 50:");
|
|
272
|
+
let j: int = 2;
|
|
273
|
+
while (j <= 50) {
|
|
274
|
+
if (is_prime(j) == 1) {
|
|
275
|
+
say(f" {j}");
|
|
276
|
+
}
|
|
277
|
+
j = j + 1;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Collatz conjecture
|
|
281
|
+
say("§eCollatz sequences:");
|
|
282
|
+
say(f" collatz_steps(27) = {collatz_steps(27)} (expect 111)");
|
|
283
|
+
say(f" collatz_steps(97) = {collatz_steps(97)}");
|
|
284
|
+
say(f" collatz_steps(871) = {collatz_steps(871)} (longest for n≤1000)");
|
|
285
|
+
|
|
286
|
+
// Number utilities
|
|
287
|
+
say("§eNumber Utilities:");
|
|
288
|
+
say(f" digit_sum(9999) = {digit_sum(9999)} (expect 36)");
|
|
289
|
+
say(f" reverse_int(12345)= {reverse_int(12345)} (expect 54321)");
|
|
290
|
+
say(f" digital_root(493) = {digital_root(493)} (expect 7)");
|
|
291
|
+
|
|
292
|
+
// Hash & noise
|
|
293
|
+
say("§eHash (splitmix32) & 1D Noise:");
|
|
294
|
+
say(f" hash_int(0) = {hash_int(0)}");
|
|
295
|
+
say(f" hash_int(1) = {hash_int(1)}");
|
|
296
|
+
say(f" noise1d(0,42) = {noise1d(0, 42)}");
|
|
297
|
+
say(f" noise1d(1,42) = {noise1d(1, 42)}");
|
|
298
|
+
say(f" noise1d(2,42) = {noise1d(2, 42)}");
|
|
299
|
+
|
|
300
|
+
// Modular exponentiation
|
|
301
|
+
say("§eModular Exponentiation:");
|
|
302
|
+
say(f" mod_pow(2, 10, 1000) = {mod_pow(2, 10, 1000)} (expect 24)");
|
|
303
|
+
say(f" mod_pow(7, 5, 13) = {mod_pow(7, 5, 13)} (expect 11) // NOTE: m<46340 to avoid INT32 overflow");
|
|
304
|
+
|
|
305
|
+
// Bézier curve
|
|
306
|
+
say("§eQuadratic Bézier (P0=0, P1=1000, P2=0) — shape like ∩:");
|
|
307
|
+
let t: int = 0;
|
|
308
|
+
while (t <= 1000) {
|
|
309
|
+
let bz: int = bezier_quad(0, 1000, 0, t);
|
|
310
|
+
say(f" t={t} → {bz}");
|
|
311
|
+
t = t + 200;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Mandelbrot iteration counts at selected points
|
|
315
|
+
say("§eMandelbrot Iteration Counts:");
|
|
316
|
+
say(f" (0, 0) → {mandelbrot_iter(0, 0, 50)} iters [inside set]");
|
|
317
|
+
say(f" (2000, 0) → {mandelbrot_iter(2000, 0, 50)} iters [outside]");
|
|
318
|
+
say(f" (-1250, 0) → {mandelbrot_iter(-1250, 0, 50)} iters [boundary]");
|
|
319
|
+
say(f" (-750, 1000) → {mandelbrot_iter(-750, 1000, 50)} iters [boundary]");
|
|
320
|
+
|
|
321
|
+
// Vec math
|
|
322
|
+
say("§eVector Math (×1000 fixed-point):");
|
|
323
|
+
say(f" length2d_fixed(3, 4) = {length2d_fixed(3, 4)} (expect 5000)");
|
|
324
|
+
say(f" dot2d(1000,0, 0,1000) = {dot2d(1000, 0, 0, 1000)} (perpendicular = 0)");
|
|
325
|
+
say(f" dot2d(1000,0, 1000,0) = {dot2d(1000, 0, 1000, 0)} (parallel = 1e6)");
|
|
326
|
+
say(f" atan2_fixed(1000, 1000) = {atan2_fixed(1000, 1000)}° (expect 45)");
|
|
327
|
+
say(f" normalize2d_x(3, 4) = {normalize2d_x(3, 4)} (expect 600)");
|
|
328
|
+
say(f" normalize2d_y(3, 4) = {normalize2d_y(3, 4)} (expect 800)");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
fn _tick_advanced_live() {
|
|
332
|
+
// Scan Mandelbrot x-axis in real time on actionbar
|
|
333
|
+
if (state.tick % 5 == 0) {
|
|
334
|
+
let cx: int = -2000 + (state.tick % 200) * 20; // -2000 to 2000
|
|
335
|
+
let iters: int = mandelbrot_iter(cx, 0, 30);
|
|
336
|
+
foreach (p in @a[limit=1]) {
|
|
337
|
+
actionbar(p, f"§aMandelbrot scan: cx={cx} iters={iters}");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// ── Phase 4: Visual Effects ────────────────────────────────────────────────
|
|
343
|
+
|
|
344
|
+
fn _tick_visual() {
|
|
345
|
+
// Advance rotation angle
|
|
346
|
+
state.angle = (state.angle + 2) % 360;
|
|
347
|
+
|
|
348
|
+
// Live sin/cos on actionbar
|
|
349
|
+
let s: int = sin_fixed(state.angle);
|
|
350
|
+
let c: int = cos_fixed(state.angle);
|
|
351
|
+
let len: int = length2d_fixed(s, c);
|
|
352
|
+
foreach (p in @a[limit=1]) {
|
|
353
|
+
actionbar(p, f"§6angle={state.angle}° §bsin={s} §dcos={c} §alen={len}");
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Particle ring: 8 cardinal + diagonal points pulsing in Y
|
|
357
|
+
// Y-offset is driven by sin (rises and falls with angle)
|
|
358
|
+
// Note: ~Y syntax uses a macro param; we use fixed ~1 here and
|
|
359
|
+
// place two rings (ground ~0 and elevated ~2) at alternating ticks
|
|
360
|
+
if (state.tick % 2 == 0) {
|
|
361
|
+
foreach (p in @a[limit=1]) at @s {
|
|
362
|
+
// Cardinal — end_rod (blue-white)
|
|
363
|
+
particle("minecraft:end_rod", ~0, ~1, ~5, 0, 0, 0, 0, 1);
|
|
364
|
+
particle("minecraft:end_rod", ~5, ~1, ~0, 0, 0, 0, 0, 1);
|
|
365
|
+
particle("minecraft:end_rod", ~0, ~1, ~-5, 0, 0, 0, 0, 1);
|
|
366
|
+
particle("minecraft:end_rod", ~-5, ~1, ~0, 0, 0, 0, 0, 1);
|
|
367
|
+
// Diagonal — flame (orange)
|
|
368
|
+
particle("minecraft:flame", ~3, ~1, ~3, 0, 0, 0, 0, 1);
|
|
369
|
+
particle("minecraft:flame", ~-3, ~1, ~3, 0, 0, 0, 0, 1);
|
|
370
|
+
particle("minecraft:flame", ~3, ~1, ~-3, 0, 0, 0, 0, 1);
|
|
371
|
+
particle("minecraft:flame", ~-3, ~1, ~-3, 0, 0, 0, 0, 1);
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
foreach (p in @a[limit=1]) at @s {
|
|
375
|
+
// Upper ring offset by 2 (creates helix effect alternating ticks)
|
|
376
|
+
particle("minecraft:end_rod", ~0, ~3, ~5, 0, 0, 0, 0, 1);
|
|
377
|
+
particle("minecraft:end_rod", ~5, ~3, ~0, 0, 0, 0, 0, 1);
|
|
378
|
+
particle("minecraft:end_rod", ~0, ~3, ~-5, 0, 0, 0, 0, 1);
|
|
379
|
+
particle("minecraft:end_rod", ~-5, ~3, ~0, 0, 0, 0, 0, 1);
|
|
380
|
+
particle("minecraft:flame", ~3, ~3, ~3, 0, 0, 0, 0, 1);
|
|
381
|
+
particle("minecraft:flame", ~-3, ~3, ~3, 0, 0, 0, 0, 1);
|
|
382
|
+
particle("minecraft:flame", ~3, ~3, ~-3, 0, 0, 0, 0, 1);
|
|
383
|
+
particle("minecraft:flame", ~-3, ~3, ~-3, 0, 0, 0, 0, 1);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Firework burst at tick multiples of 100
|
|
388
|
+
if (state.tick % 100 == 0) {
|
|
389
|
+
foreach (p in @a[limit=1]) at @s {
|
|
390
|
+
summon("minecraft:firework_rocket", ~0, ~2, ~0);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// ── Public commands ────────────────────────────────────────────────────────
|
|
396
|
+
|
|
397
|
+
fn start() {
|
|
398
|
+
state.running = true;
|
|
399
|
+
state.phase = 0;
|
|
400
|
+
state.tick = 0;
|
|
401
|
+
state.angle = 0;
|
|
402
|
+
phase_timer.reset();
|
|
403
|
+
|
|
404
|
+
_section("RedScript v1.2.26 Showcase");
|
|
405
|
+
say("§aStarting capability demo — phases cycle every 10 seconds.");
|
|
406
|
+
say("§7Math → BigInt → Advanced → Visual FX → (repeat)");
|
|
407
|
+
say("§7Use §f/function showcase:dump_math §7or §f/function showcase:dump_bigint");
|
|
408
|
+
say("§7for the full printed output at any time.");
|
|
409
|
+
|
|
410
|
+
// Kick off phase 1 immediately
|
|
411
|
+
_next_phase();
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
fn stop() {
|
|
415
|
+
state.running = false;
|
|
416
|
+
foreach (p in @a[limit=1]) {
|
|
417
|
+
actionbar(p, "§c[Showcase stopped]");
|
|
418
|
+
}
|
|
419
|
+
say("§c[Showcase] §rStopped.");
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Stand-alone dump commands for reference
|
|
423
|
+
|
|
424
|
+
fn dump_math() {
|
|
425
|
+
_dump_math_phase();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
fn dump_bigint() {
|
|
429
|
+
_dump_bigint_phase();
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
fn dump_advanced() {
|
|
433
|
+
_dump_advanced_phase();
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// ── BigInt step-by-step debug ─────────────────────────────────────────────
|
|
437
|
+
// /function showcase:debug_bigint
|
|
438
|
+
fn debug_bigint() {
|
|
439
|
+
say("§e=== BigInt Debug ===");
|
|
440
|
+
|
|
441
|
+
// Step 0: check scoreboard objective 'rs' exists (set by __load)
|
|
442
|
+
// If this reads 0, __load hasn't run — do /reload first!
|
|
443
|
+
scoreboard_set("__dbgcheck", #rs, 9999);
|
|
444
|
+
let rs_check: int = scoreboard_get("__dbgcheck", #rs);
|
|
445
|
+
say(f"§7[0] rs-objective check={rs_check} (expect 9999; if 0 → run /reload first!)");
|
|
446
|
+
|
|
447
|
+
// Step 1: init
|
|
448
|
+
bigint_init();
|
|
449
|
+
say("§7[1] bigint_init() done");
|
|
450
|
+
|
|
451
|
+
// Step 2: from_int_a (STATIC index writes, no macro)
|
|
452
|
+
bigint_from_int_a(12345);
|
|
453
|
+
// 2a: static read (data get storage rs:bigint a[0] — NO macro)
|
|
454
|
+
let direct0: int = storage_get_int("rs:bigint", "a", 0);
|
|
455
|
+
let direct1: int = storage_get_int("rs:bigint", "a", 1);
|
|
456
|
+
say(f"§7[2a] static-read a[0]={direct0} a[1]={direct1} (expect 2345,1)");
|
|
457
|
+
// 2b: macro read (bigint_get_a uses macro sub-function)
|
|
458
|
+
let a0: int = bigint_get_a(0);
|
|
459
|
+
let a1: int = bigint_get_a(1);
|
|
460
|
+
say(f"§7[2b] macro-read a[0]={a0} a[1]={a1} (expect 2345,1)");
|
|
461
|
+
|
|
462
|
+
// Step 3: fib(1) = 1 (no carry, simplest case)
|
|
463
|
+
bigint_fib(1);
|
|
464
|
+
let f1: int = bigint_get_a(0);
|
|
465
|
+
say(f"§7[3] fib(1) → get_a(0)={f1} (expect 1)");
|
|
466
|
+
|
|
467
|
+
// Step 4: fib(5) = 5
|
|
468
|
+
bigint_fib(5);
|
|
469
|
+
let f5: int = bigint_get_a(0);
|
|
470
|
+
say(f"§7[4] fib(5) → get_a(0)={f5} (expect 5)");
|
|
471
|
+
|
|
472
|
+
// Step 5: fib(10) = 55
|
|
473
|
+
bigint_fib(10);
|
|
474
|
+
let f10: int = bigint_get_a(0);
|
|
475
|
+
say(f"§7[5] fib(10) → get_a(0)={f10} (expect 55)");
|
|
476
|
+
|
|
477
|
+
// Step 6: fib(20) = 6765
|
|
478
|
+
bigint_fib(20);
|
|
479
|
+
let f20: int = bigint_get_a(0);
|
|
480
|
+
say(f"§7[6] fib(20) → get_a(0)={f20} (expect 6765)");
|
|
481
|
+
|
|
482
|
+
// Step 7: manual add — bigint_add() writes via __ssi macro
|
|
483
|
+
bigint_init();
|
|
484
|
+
bigint_from_int_a(1);
|
|
485
|
+
bigint_from_int_b(1);
|
|
486
|
+
bigint_add();
|
|
487
|
+
let c0: int = bigint_get_c(0);
|
|
488
|
+
say(f"§7[7] 1+1=? get_c(0)={c0} (expect 2)");
|
|
489
|
+
|
|
490
|
+
say("§a=== Done ===");
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// ── Lambda demo (standalone — shows higher-order functions work) ───────────
|
|
494
|
+
|
|
495
|
+
fn _apply(f: (int) -> int, x: int) -> int {
|
|
496
|
+
return f(x);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
fn lambda_demo() {
|
|
500
|
+
let double: (int) -> int = (x: int) => x * 2;
|
|
501
|
+
let square: (int) -> int = (x: int) => x * x;
|
|
502
|
+
|
|
503
|
+
say(f" double(7) = {_apply(double, 7)}");
|
|
504
|
+
say(f" square(9) = {_apply(square, 9)}");
|
|
505
|
+
}
|
package/package.json
CHANGED
|
@@ -257,3 +257,123 @@ describe('julia_iter', () => {
|
|
|
257
257
|
expect(scoreOf(rt, 'r')).toBe(0)
|
|
258
258
|
})
|
|
259
259
|
})
|
|
260
|
+
|
|
261
|
+
// ─── Experiment: cross-stdlib (vec + math + advanced) ────────────────────────
|
|
262
|
+
|
|
263
|
+
const VEC_SRC = fs.readFileSync(path.join(__dirname, '../../src/stdlib/vec.mcrs'), 'utf-8')
|
|
264
|
+
|
|
265
|
+
function runAll(driver: string): MCRuntime {
|
|
266
|
+
const result = compile(driver, {
|
|
267
|
+
namespace: 'exptest',
|
|
268
|
+
librarySources: [MATH_SRC, VEC_SRC, ADV_SRC],
|
|
269
|
+
})
|
|
270
|
+
if (!result.success) throw new Error(result.error?.message ?? 'compile failed: ' + result.error?.message)
|
|
271
|
+
const rt = new MCRuntime('exptest')
|
|
272
|
+
for (const file of result.files ?? []) {
|
|
273
|
+
if (!file.path.endsWith('.mcfunction')) continue
|
|
274
|
+
const match = file.path.match(/data\/([^/]+)\/function\/(.+)\.mcfunction$/)
|
|
275
|
+
if (!match) continue
|
|
276
|
+
rt.loadFunction(`${match[1]}:${match[2]}`, file.content.split('\n'))
|
|
277
|
+
}
|
|
278
|
+
rt.load()
|
|
279
|
+
return rt
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function exp(rt: MCRuntime, key: string): number {
|
|
283
|
+
return rt.getScore('out', `exptest.${key}`) ?? 0
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
describe('newton_sqrt', () => {
|
|
287
|
+
it('newton_sqrt(25) == 5', () => {
|
|
288
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", newton_sqrt(25)); }`)
|
|
289
|
+
rt.execFunction('test')
|
|
290
|
+
expect(exp(rt, 'r')).toBe(5)
|
|
291
|
+
})
|
|
292
|
+
it('newton_sqrt(100) == 10', () => {
|
|
293
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", newton_sqrt(100)); }`)
|
|
294
|
+
rt.execFunction('test')
|
|
295
|
+
expect(exp(rt, 'r')).toBe(10)
|
|
296
|
+
})
|
|
297
|
+
it('newton_sqrt(2) == 1', () => {
|
|
298
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", newton_sqrt(2)); }`)
|
|
299
|
+
rt.execFunction('test')
|
|
300
|
+
expect(exp(rt, 'r')).toBe(1)
|
|
301
|
+
})
|
|
302
|
+
it('newton_sqrt(0) == 0', () => {
|
|
303
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", newton_sqrt(0)); }`)
|
|
304
|
+
rt.execFunction('test')
|
|
305
|
+
expect(exp(rt, 'r')).toBe(0)
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
describe('digital_root', () => {
|
|
310
|
+
it('digital_root(493) == 7', () => {
|
|
311
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", digital_root(493)); }`)
|
|
312
|
+
rt.execFunction('test')
|
|
313
|
+
expect(exp(rt, 'r')).toBe(7)
|
|
314
|
+
})
|
|
315
|
+
it('digital_root(9) == 9', () => {
|
|
316
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", digital_root(9)); }`)
|
|
317
|
+
rt.execFunction('test')
|
|
318
|
+
expect(exp(rt, 'r')).toBe(9)
|
|
319
|
+
})
|
|
320
|
+
it('digital_root(0) == 0', () => {
|
|
321
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", digital_root(0)); }`)
|
|
322
|
+
rt.execFunction('test')
|
|
323
|
+
expect(exp(rt, 'r')).toBe(0)
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
describe('spiral_ring', () => {
|
|
328
|
+
it('spiral_ring(1) == 0', () => {
|
|
329
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", spiral_ring(1)); }`)
|
|
330
|
+
rt.execFunction('test')
|
|
331
|
+
expect(exp(rt, 'r')).toBe(0)
|
|
332
|
+
})
|
|
333
|
+
it('spiral_ring(9) == 1', () => {
|
|
334
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", spiral_ring(9)); }`)
|
|
335
|
+
rt.execFunction('test')
|
|
336
|
+
expect(exp(rt, 'r')).toBe(1)
|
|
337
|
+
})
|
|
338
|
+
it('spiral_ring(25) == 2', () => {
|
|
339
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", spiral_ring(25)); }`)
|
|
340
|
+
rt.execFunction('test')
|
|
341
|
+
expect(exp(rt, 'r')).toBe(2)
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
describe('clamp_circle', () => {
|
|
346
|
+
it('point inside: clamp_circle_x(3,4,10) == 3', () => {
|
|
347
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", clamp_circle_x(3, 4, 10)); }`)
|
|
348
|
+
rt.execFunction('test')
|
|
349
|
+
expect(exp(rt, 'r')).toBe(3)
|
|
350
|
+
})
|
|
351
|
+
it('point outside: clamp_circle_x(600,0,500) == 500', () => {
|
|
352
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", clamp_circle_x(600, 0, 500)); }`)
|
|
353
|
+
rt.execFunction('test')
|
|
354
|
+
expect(exp(rt, 'r')).toBe(500)
|
|
355
|
+
})
|
|
356
|
+
it('clamp_circle_y(0,600,500) == 500', () => {
|
|
357
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", clamp_circle_y(0, 600, 500)); }`)
|
|
358
|
+
rt.execFunction('test')
|
|
359
|
+
expect(exp(rt, 'r')).toBe(500)
|
|
360
|
+
})
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
describe('angle_between', () => {
|
|
364
|
+
it('perpendicular vectors: angle_between(1000,0,0,1000) == 90', () => {
|
|
365
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", angle_between(1000, 0, 0, 1000)); }`)
|
|
366
|
+
rt.execFunction('test')
|
|
367
|
+
expect(exp(rt, 'r')).toBe(90)
|
|
368
|
+
})
|
|
369
|
+
it('parallel vectors: angle_between(1000,0,1000,0) == 0', () => {
|
|
370
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", angle_between(1000, 0, 1000, 0)); }`)
|
|
371
|
+
rt.execFunction('test')
|
|
372
|
+
expect(exp(rt, 'r')).toBe(0)
|
|
373
|
+
})
|
|
374
|
+
it('opposite vectors: angle_between(1000,0,-1000,0) == 180', () => {
|
|
375
|
+
const rt = runAll(`fn test() { scoreboard_set("out", "r", angle_between(1000, 0, -1000, 0)); }`)
|
|
376
|
+
rt.execFunction('test')
|
|
377
|
+
expect(exp(rt, 'r')).toBe(180)
|
|
378
|
+
})
|
|
379
|
+
})
|