redscript-mc 1.2.21 → 1.2.25

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.
Files changed (126) hide show
  1. package/.github/workflows/publish-extension-on-ci.yml +100 -0
  2. package/dist/__tests__/entity-types.test.d.ts +1 -0
  3. package/dist/__tests__/entity-types.test.js +203 -0
  4. package/dist/__tests__/var-allocator.test.d.ts +1 -0
  5. package/dist/__tests__/var-allocator.test.js +69 -0
  6. package/dist/ast/types.d.ts +2 -1
  7. package/dist/cli.js +17 -6
  8. package/dist/codegen/mcfunction/index.d.ts +2 -0
  9. package/dist/codegen/mcfunction/index.js +52 -43
  10. package/dist/codegen/structure/index.d.ts +4 -1
  11. package/dist/codegen/structure/index.js +8 -12
  12. package/dist/codegen/var-allocator.d.ts +28 -0
  13. package/dist/codegen/var-allocator.js +78 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +8 -6
  16. package/dist/lowering/index.d.ts +2 -0
  17. package/dist/lowering/index.js +62 -3
  18. package/dist/parser/index.js +22 -1
  19. package/dist/typechecker/index.js +30 -0
  20. package/dist/types/entity-hierarchy.d.ts +29 -0
  21. package/dist/types/entity-hierarchy.js +107 -0
  22. package/editors/vscode/package-lock.json +6 -4
  23. package/editors/vscode/package.json +3 -3
  24. package/package.json +1 -1
  25. package/src/__tests__/entity-types.test.ts +236 -0
  26. package/src/__tests__/var-allocator.test.ts +75 -0
  27. package/src/ast/types.ts +8 -4
  28. package/src/cli.ts +20 -6
  29. package/src/codegen/mcfunction/index.ts +60 -48
  30. package/src/codegen/structure/index.ts +9 -14
  31. package/src/codegen/var-allocator.ts +75 -0
  32. package/src/examples/capture_the_flag.mcrs +34 -34
  33. package/src/examples/hunger_games.mcrs +59 -59
  34. package/src/examples/new_features_demo.mcrs +32 -32
  35. package/src/examples/parkour_race.mcrs +58 -58
  36. package/src/index.ts +10 -6
  37. package/src/lowering/index.ts +73 -8
  38. package/src/parser/index.ts +20 -1
  39. package/src/typechecker/index.ts +30 -0
  40. package/src/types/entity-hierarchy.ts +120 -0
  41. package/dist/data/arena/function/__load.mcfunction +0 -6
  42. package/dist/data/arena/function/__tick.mcfunction +0 -2
  43. package/dist/data/arena/function/announce_leaders/else_1.mcfunction +0 -3
  44. package/dist/data/arena/function/announce_leaders/foreach_0/merge_2.mcfunction +0 -1
  45. package/dist/data/arena/function/announce_leaders/foreach_0/then_0.mcfunction +0 -3
  46. package/dist/data/arena/function/announce_leaders/foreach_0.mcfunction +0 -7
  47. package/dist/data/arena/function/announce_leaders/foreach_1/merge_2.mcfunction +0 -1
  48. package/dist/data/arena/function/announce_leaders/foreach_1/then_0.mcfunction +0 -4
  49. package/dist/data/arena/function/announce_leaders/foreach_1.mcfunction +0 -6
  50. package/dist/data/arena/function/announce_leaders/merge_2.mcfunction +0 -1
  51. package/dist/data/arena/function/announce_leaders/then_0.mcfunction +0 -4
  52. package/dist/data/arena/function/announce_leaders.mcfunction +0 -6
  53. package/dist/data/arena/function/arena_tick/merge_2.mcfunction +0 -1
  54. package/dist/data/arena/function/arena_tick/then_0.mcfunction +0 -4
  55. package/dist/data/arena/function/arena_tick.mcfunction +0 -11
  56. package/dist/data/counter/function/__load.mcfunction +0 -5
  57. package/dist/data/counter/function/__tick.mcfunction +0 -2
  58. package/dist/data/counter/function/counter_tick/merge_2.mcfunction +0 -1
  59. package/dist/data/counter/function/counter_tick/then_0.mcfunction +0 -3
  60. package/dist/data/counter/function/counter_tick.mcfunction +0 -11
  61. package/dist/data/minecraft/tags/function/load.json +0 -5
  62. package/dist/data/minecraft/tags/function/tick.json +0 -5
  63. package/dist/data/quiz/function/__load.mcfunction +0 -16
  64. package/dist/data/quiz/function/__tick.mcfunction +0 -6
  65. package/dist/data/quiz/function/__trigger_quiz_a_dispatch.mcfunction +0 -4
  66. package/dist/data/quiz/function/__trigger_quiz_b_dispatch.mcfunction +0 -4
  67. package/dist/data/quiz/function/__trigger_quiz_c_dispatch.mcfunction +0 -4
  68. package/dist/data/quiz/function/__trigger_quiz_start_dispatch.mcfunction +0 -4
  69. package/dist/data/quiz/function/answer_a.mcfunction +0 -4
  70. package/dist/data/quiz/function/answer_b.mcfunction +0 -4
  71. package/dist/data/quiz/function/answer_c.mcfunction +0 -4
  72. package/dist/data/quiz/function/ask_question/else_1.mcfunction +0 -5
  73. package/dist/data/quiz/function/ask_question/else_4.mcfunction +0 -5
  74. package/dist/data/quiz/function/ask_question/else_7.mcfunction +0 -4
  75. package/dist/data/quiz/function/ask_question/merge_2.mcfunction +0 -1
  76. package/dist/data/quiz/function/ask_question/merge_5.mcfunction +0 -2
  77. package/dist/data/quiz/function/ask_question/merge_8.mcfunction +0 -2
  78. package/dist/data/quiz/function/ask_question/then_0.mcfunction +0 -4
  79. package/dist/data/quiz/function/ask_question/then_3.mcfunction +0 -4
  80. package/dist/data/quiz/function/ask_question/then_6.mcfunction +0 -4
  81. package/dist/data/quiz/function/ask_question.mcfunction +0 -7
  82. package/dist/data/quiz/function/finish_quiz.mcfunction +0 -6
  83. package/dist/data/quiz/function/handle_answer/else_1.mcfunction +0 -5
  84. package/dist/data/quiz/function/handle_answer/else_10.mcfunction +0 -3
  85. package/dist/data/quiz/function/handle_answer/else_16.mcfunction +0 -3
  86. package/dist/data/quiz/function/handle_answer/else_4.mcfunction +0 -3
  87. package/dist/data/quiz/function/handle_answer/else_7.mcfunction +0 -5
  88. package/dist/data/quiz/function/handle_answer/merge_11.mcfunction +0 -2
  89. package/dist/data/quiz/function/handle_answer/merge_14.mcfunction +0 -2
  90. package/dist/data/quiz/function/handle_answer/merge_17.mcfunction +0 -2
  91. package/dist/data/quiz/function/handle_answer/merge_2.mcfunction +0 -8
  92. package/dist/data/quiz/function/handle_answer/merge_5.mcfunction +0 -2
  93. package/dist/data/quiz/function/handle_answer/merge_8.mcfunction +0 -2
  94. package/dist/data/quiz/function/handle_answer/then_0.mcfunction +0 -5
  95. package/dist/data/quiz/function/handle_answer/then_12.mcfunction +0 -5
  96. package/dist/data/quiz/function/handle_answer/then_15.mcfunction +0 -6
  97. package/dist/data/quiz/function/handle_answer/then_3.mcfunction +0 -6
  98. package/dist/data/quiz/function/handle_answer/then_6.mcfunction +0 -5
  99. package/dist/data/quiz/function/handle_answer/then_9.mcfunction +0 -6
  100. package/dist/data/quiz/function/handle_answer.mcfunction +0 -11
  101. package/dist/data/quiz/function/start_quiz.mcfunction +0 -5
  102. package/dist/data/shop/function/__load.mcfunction +0 -7
  103. package/dist/data/shop/function/__tick.mcfunction +0 -3
  104. package/dist/data/shop/function/__trigger_shop_buy_dispatch.mcfunction +0 -4
  105. package/dist/data/shop/function/complete_purchase/else_1.mcfunction +0 -5
  106. package/dist/data/shop/function/complete_purchase/else_4.mcfunction +0 -5
  107. package/dist/data/shop/function/complete_purchase/else_7.mcfunction +0 -3
  108. package/dist/data/shop/function/complete_purchase/merge_2.mcfunction +0 -2
  109. package/dist/data/shop/function/complete_purchase/merge_5.mcfunction +0 -2
  110. package/dist/data/shop/function/complete_purchase/merge_8.mcfunction +0 -2
  111. package/dist/data/shop/function/complete_purchase/then_0.mcfunction +0 -4
  112. package/dist/data/shop/function/complete_purchase/then_3.mcfunction +0 -4
  113. package/dist/data/shop/function/complete_purchase/then_6.mcfunction +0 -4
  114. package/dist/data/shop/function/complete_purchase.mcfunction +0 -7
  115. package/dist/data/shop/function/handle_shop_trigger.mcfunction +0 -3
  116. package/dist/data/turret/function/__load.mcfunction +0 -5
  117. package/dist/data/turret/function/__tick.mcfunction +0 -4
  118. package/dist/data/turret/function/__trigger_deploy_turret_dispatch.mcfunction +0 -4
  119. package/dist/data/turret/function/deploy_turret.mcfunction +0 -8
  120. package/dist/data/turret/function/turret_tick/at_1.mcfunction +0 -2
  121. package/dist/data/turret/function/turret_tick/foreach_0.mcfunction +0 -2
  122. package/dist/data/turret/function/turret_tick/foreach_2.mcfunction +0 -2
  123. package/dist/data/turret/function/turret_tick/tick_body.mcfunction +0 -3
  124. package/dist/data/turret/function/turret_tick/tick_skip.mcfunction +0 -1
  125. package/dist/data/turret/function/turret_tick.mcfunction +0 -5
  126. package/dist/pack.mcmeta +0 -6
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Entity Type Hierarchy
3
+ *
4
+ * Closed inheritance tree mapping to Minecraft's entity registry.
5
+ * Used for type narrowing (is checks), selector<T> annotations,
6
+ * and W_IMPOSSIBLE_AS warnings.
7
+ */
8
+
9
+ export interface EntityTypeNode {
10
+ name: string
11
+ mcId: string | null // null for abstract types
12
+ abstract: boolean
13
+ parent: string | null // null for root "Entity"
14
+ }
15
+
16
+ export const ENTITY_TYPES: EntityTypeNode[] = [
17
+ // Root
18
+ { name: 'Entity', mcId: null, abstract: true, parent: null },
19
+
20
+ // Direct children of Entity
21
+ { name: 'Player', mcId: 'minecraft:player', abstract: false, parent: 'Entity' },
22
+ { name: 'ArmorStand', mcId: 'minecraft:armor_stand', abstract: false, parent: 'Entity' },
23
+ { name: 'Item', mcId: 'minecraft:item', abstract: false, parent: 'Entity' },
24
+ { name: 'Arrow', mcId: 'minecraft:arrow', abstract: false, parent: 'Entity' },
25
+
26
+ // Mob hierarchy
27
+ { name: 'Mob', mcId: null, abstract: true, parent: 'Entity' },
28
+
29
+ // Hostile mobs
30
+ { name: 'HostileMob', mcId: null, abstract: true, parent: 'Mob' },
31
+ { name: 'Zombie', mcId: 'minecraft:zombie', abstract: false, parent: 'HostileMob' },
32
+ { name: 'Skeleton', mcId: 'minecraft:skeleton', abstract: false, parent: 'HostileMob' },
33
+ { name: 'Creeper', mcId: 'minecraft:creeper', abstract: false, parent: 'HostileMob' },
34
+ { name: 'Spider', mcId: 'minecraft:spider', abstract: false, parent: 'HostileMob' },
35
+ { name: 'Enderman', mcId: 'minecraft:enderman', abstract: false, parent: 'HostileMob' },
36
+ { name: 'Blaze', mcId: 'minecraft:blaze', abstract: false, parent: 'HostileMob' },
37
+ { name: 'Witch', mcId: 'minecraft:witch', abstract: false, parent: 'HostileMob' },
38
+ { name: 'Slime', mcId: 'minecraft:slime', abstract: false, parent: 'HostileMob' },
39
+ { name: 'ZombieVillager', mcId: 'minecraft:zombie_villager', abstract: false, parent: 'HostileMob' },
40
+ { name: 'Husk', mcId: 'minecraft:husk', abstract: false, parent: 'HostileMob' },
41
+ { name: 'Drowned', mcId: 'minecraft:drowned', abstract: false, parent: 'HostileMob' },
42
+ { name: 'Stray', mcId: 'minecraft:stray', abstract: false, parent: 'HostileMob' },
43
+ { name: 'WitherSkeleton', mcId: 'minecraft:wither_skeleton', abstract: false, parent: 'HostileMob' },
44
+ { name: 'CaveSpider', mcId: 'minecraft:cave_spider', abstract: false, parent: 'HostileMob' },
45
+
46
+ // Passive mobs
47
+ { name: 'PassiveMob', mcId: null, abstract: true, parent: 'Mob' },
48
+ { name: 'Pig', mcId: 'minecraft:pig', abstract: false, parent: 'PassiveMob' },
49
+ { name: 'Cow', mcId: 'minecraft:cow', abstract: false, parent: 'PassiveMob' },
50
+ { name: 'Sheep', mcId: 'minecraft:sheep', abstract: false, parent: 'PassiveMob' },
51
+ { name: 'Chicken', mcId: 'minecraft:chicken', abstract: false, parent: 'PassiveMob' },
52
+ { name: 'Villager', mcId: 'minecraft:villager', abstract: false, parent: 'PassiveMob' },
53
+ { name: 'WanderingTrader', mcId: 'minecraft:wandering_trader', abstract: false, parent: 'PassiveMob' },
54
+ ]
55
+
56
+ /** Map from lowercase name → EntityTypeNode */
57
+ export const ENTITY_TYPE_MAP: Map<string, EntityTypeNode> = new Map(
58
+ ENTITY_TYPES.map(t => [t.name.toLowerCase(), t])
59
+ )
60
+
61
+ /** Map from mcId (without namespace) → EntityTypeNode */
62
+ export const ENTITY_TYPE_BY_MCID: Map<string, EntityTypeNode> = new Map(
63
+ ENTITY_TYPES
64
+ .filter(t => t.mcId !== null)
65
+ .map(t => [t.mcId!.replace('minecraft:', ''), t])
66
+ )
67
+
68
+ /** Check if typeA is a subtype of typeB (recursive ancestry) */
69
+ export function isSubtype(typeA: string, typeB: string): boolean {
70
+ if (typeA === typeB) return true
71
+ const node = ENTITY_TYPE_MAP.get(typeA.toLowerCase())
72
+ if (!node || !node.parent) return false
73
+ return isSubtype(node.parent, typeB)
74
+ }
75
+
76
+ /** True if one type is a subtype of the other (in either direction) */
77
+ export function areCompatibleTypes(outerType: string, innerType: string): boolean {
78
+ return isSubtype(outerType, innerType) || isSubtype(innerType, outerType)
79
+ }
80
+
81
+ /** Get all non-abstract leaf types under a given node */
82
+ export function getConcreteSubtypes(typeName: string): EntityTypeNode[] {
83
+ const results: EntityTypeNode[] = []
84
+ for (const node of ENTITY_TYPES) {
85
+ if (!node.abstract && isSubtype(node.name, typeName)) {
86
+ results.push(node)
87
+ }
88
+ }
89
+ return results
90
+ }
91
+
92
+ /** Parse "type=zombie" from a selector string, return the entity type name or null */
93
+ export function getSelectorEntityType(selector: string): string | null {
94
+ const match = selector.match(/type=(?:minecraft:)?([a-z_]+)/)
95
+ if (!match) return null
96
+ const mcId = match[1]
97
+ const node = ENTITY_TYPE_BY_MCID.get(mcId)
98
+ return node ? node.name : null
99
+ }
100
+
101
+ /** Determine the base entity type from a selector kind:
102
+ * @a/@p/@r → "Player", @e → "Entity" or from type filter, @s → null */
103
+ export function getBaseSelectorType(selector: string): string | null {
104
+ const trimmed = selector.trim()
105
+
106
+ // Check for type filter first (works for any selector)
107
+ const typeFromFilter = getSelectorEntityType(trimmed)
108
+
109
+ if (trimmed.startsWith('@a') || trimmed.startsWith('@p') || trimmed.startsWith('@r')) {
110
+ return typeFromFilter ?? 'Player'
111
+ }
112
+ if (trimmed.startsWith('@e')) {
113
+ return typeFromFilter ?? 'Entity'
114
+ }
115
+ // @s — context-dependent, we don't know unless there's a type filter
116
+ if (trimmed.startsWith('@s')) {
117
+ return typeFromFilter ?? null
118
+ }
119
+ return null
120
+ }
@@ -1,6 +0,0 @@
1
- # RedScript runtime init
2
- scoreboard objectives add rs dummy
3
- scoreboard players set $const_1 rs 1
4
- scoreboard players set $const_200 rs 200
5
- scoreboard players set $const_0 rs 0
6
- scoreboard players set $const_0 rs 0
@@ -1,2 +0,0 @@
1
- # RedScript tick dispatcher
2
- function arena:arena_tick
@@ -1,3 +0,0 @@
1
- # block: else_1
2
- say Arena update: no PvP kills yet.
3
- function arena:announce_leaders/merge_2
@@ -1,3 +0,0 @@
1
- # block: then_0
2
- scoreboard players operation $top_kills rs = $kills rs
3
- function arena:announce_leaders/foreach_0/merge_2
@@ -1,7 +0,0 @@
1
- # block: entry
2
- execute store result score $t0 rs run scoreboard players get @s kills
3
- scoreboard players operation $kills rs = $t0 rs
4
- scoreboard players set $t1 rs 0
5
- execute if score $t0 rs > $top_kills rs run scoreboard players set $t1 rs 1
6
- execute if score $t1 rs matches 1.. run function arena:announce_leaders/foreach_0/then_0
7
- execute if score $t1 rs matches ..0 run function arena:announce_leaders/foreach_0/merge_2
@@ -1,4 +0,0 @@
1
- # block: then_0
2
- tellraw @s {"text":"You are leading the arena right now."}
3
- title @s title {"text":"Arena Leader"}
4
- function arena:announce_leaders/foreach_1/merge_2
@@ -1,6 +0,0 @@
1
- # block: entry
2
- execute store result score $t0 rs run scoreboard players get @s kills
3
- scoreboard players set $t1 rs 0
4
- execute if score $t0 rs = $top_kills rs run scoreboard players set $t1 rs 1
5
- execute if score $t1 rs matches 1.. run function arena:announce_leaders/foreach_1/then_0
6
- execute if score $t1 rs matches ..0 run function arena:announce_leaders/foreach_1/merge_2
@@ -1 +0,0 @@
1
- # block: merge_2
@@ -1,4 +0,0 @@
1
- # block: then_0
2
- say Arena update: current leader check complete.
3
- execute as @a run function arena:announce_leaders/foreach_1
4
- function arena:announce_leaders/merge_2
@@ -1,6 +0,0 @@
1
- # block: entry
2
- execute as @a run function arena:announce_leaders/foreach_0
3
- scoreboard players set $t0 rs 0
4
- execute if score $const_0 rs > $const_0 rs run scoreboard players set $t0 rs 1
5
- execute if score $t0 rs matches 1.. run function arena:announce_leaders/then_0
6
- execute if score $t0 rs matches ..0 run function arena:announce_leaders/else_1
@@ -1 +0,0 @@
1
- # block: merge_2
@@ -1,4 +0,0 @@
1
- # block: then_0
2
- function arena:announce_leaders
3
- scoreboard players operation $t5 rs = $ret rs
4
- function arena:arena_tick/merge_2
@@ -1,11 +0,0 @@
1
- # block: entry
2
- execute store result score $t0 rs run scoreboard players get arena ticks
3
- scoreboard players operation $t1 rs = $t0 rs
4
- scoreboard players operation $t1 rs += $const_1 rs
5
- execute store result score arena ticks run scoreboard players get $t2 rs
6
- scoreboard players operation $t3 rs = $t1 rs
7
- scoreboard players operation $t3 rs %= $const_200 rs
8
- scoreboard players set $t4 rs 0
9
- execute if score $t3 rs = $const_0 rs run scoreboard players set $t4 rs 1
10
- execute if score $t4 rs matches 1.. run function arena:arena_tick/then_0
11
- execute if score $t4 rs matches ..0 run function arena:arena_tick/merge_2
@@ -1,5 +0,0 @@
1
- # RedScript runtime init
2
- scoreboard objectives add rs dummy
3
- scoreboard players set $const_1 rs 1
4
- scoreboard players set $const_100 rs 100
5
- scoreboard players set $const_0 rs 0
@@ -1,2 +0,0 @@
1
- # RedScript tick dispatcher
2
- function counter:counter_tick
@@ -1 +0,0 @@
1
- # block: merge_2
@@ -1,3 +0,0 @@
1
- # block: then_0
2
- say Counter reached another 100 ticks
3
- function counter:counter_tick/merge_2
@@ -1,11 +0,0 @@
1
- # block: entry
2
- execute store result score $t0 rs run scoreboard players get counter ticks
3
- scoreboard players operation $t1 rs = $t0 rs
4
- scoreboard players operation $t1 rs += $const_1 rs
5
- execute store result score counter ticks run scoreboard players get $t2 rs
6
- scoreboard players operation $t3 rs = $t1 rs
7
- scoreboard players operation $t3 rs %= $const_100 rs
8
- scoreboard players set $t4 rs 0
9
- execute if score $t3 rs = $const_0 rs run scoreboard players set $t4 rs 1
10
- execute if score $t4 rs matches 1.. run function counter:counter_tick/then_0
11
- execute if score $t4 rs matches ..0 run function counter:counter_tick/merge_2
@@ -1,5 +0,0 @@
1
- {
2
- "values": [
3
- "turret:__load"
4
- ]
5
- }
@@ -1,5 +0,0 @@
1
- {
2
- "values": [
3
- "turret:__tick"
4
- ]
5
- }
@@ -1,16 +0,0 @@
1
- # RedScript runtime init
2
- scoreboard objectives add rs dummy
3
- scoreboard objectives add quiz_start trigger
4
- scoreboard players enable @a quiz_start
5
- scoreboard objectives add quiz_a trigger
6
- scoreboard players enable @a quiz_a
7
- scoreboard objectives add quiz_b trigger
8
- scoreboard players enable @a quiz_b
9
- scoreboard objectives add quiz_c trigger
10
- scoreboard players enable @a quiz_c
11
- scoreboard players set $const_1 rs 1
12
- scoreboard players set $const_2 rs 2
13
- scoreboard players set $const_3 rs 3
14
- scoreboard players set $const_1 rs 1
15
- scoreboard players set $const_2 rs 2
16
- scoreboard players set $const_3 rs 3
@@ -1,6 +0,0 @@
1
- # RedScript tick dispatcher
2
- # Trigger checks
3
- execute as @a[scores={quiz_start=1..}] run function quiz:__trigger_quiz_start_dispatch
4
- execute as @a[scores={quiz_a=1..}] run function quiz:__trigger_quiz_a_dispatch
5
- execute as @a[scores={quiz_b=1..}] run function quiz:__trigger_quiz_b_dispatch
6
- execute as @a[scores={quiz_c=1..}] run function quiz:__trigger_quiz_c_dispatch
@@ -1,4 +0,0 @@
1
- # Trigger dispatch for quiz_a
2
- function quiz:answer_a
3
- scoreboard players set @s quiz_a 0
4
- scoreboard players enable @s quiz_a
@@ -1,4 +0,0 @@
1
- # Trigger dispatch for quiz_b
2
- function quiz:answer_b
3
- scoreboard players set @s quiz_b 0
4
- scoreboard players enable @s quiz_b
@@ -1,4 +0,0 @@
1
- # Trigger dispatch for quiz_c
2
- function quiz:answer_c
3
- scoreboard players set @s quiz_c 0
4
- scoreboard players enable @s quiz_c
@@ -1,4 +0,0 @@
1
- # Trigger dispatch for quiz_start
2
- function quiz:start_quiz
3
- scoreboard players set @s quiz_start 0
4
- scoreboard players enable @s quiz_start
@@ -1,4 +0,0 @@
1
- # block: entry
2
- scoreboard players set $p0 rs 1
3
- function quiz:handle_answer
4
- scoreboard players operation $t0 rs = $ret rs
@@ -1,4 +0,0 @@
1
- # block: entry
2
- scoreboard players set $p0 rs 2
3
- function quiz:handle_answer
4
- scoreboard players operation $t0 rs = $ret rs
@@ -1,4 +0,0 @@
1
- # block: entry
2
- scoreboard players set $p0 rs 3
3
- function quiz:handle_answer
4
- scoreboard players operation $t0 rs = $ret rs
@@ -1,5 +0,0 @@
1
- # block: else_1
2
- scoreboard players set $t2 rs 0
3
- execute if score $question rs = $const_2 rs run scoreboard players set $t2 rs 1
4
- execute if score $t2 rs matches 1.. run function quiz:ask_question/then_3
5
- execute if score $t2 rs matches ..0 run function quiz:ask_question/else_4
@@ -1,5 +0,0 @@
1
- # block: else_4
2
- scoreboard players set $t3 rs 0
3
- execute if score $question rs = $const_3 rs run scoreboard players set $t3 rs 1
4
- execute if score $t3 rs matches 1.. run function quiz:ask_question/then_6
5
- execute if score $t3 rs matches ..0 run function quiz:ask_question/else_7
@@ -1,4 +0,0 @@
1
- # block: else_7
2
- function quiz:finish_quiz
3
- scoreboard players operation $t4 rs = $ret rs
4
- function quiz:ask_question/merge_8
@@ -1 +0,0 @@
1
- # block: merge_2
@@ -1,2 +0,0 @@
1
- # block: merge_5
2
- function quiz:ask_question/merge_2
@@ -1,2 +0,0 @@
1
- # block: merge_8
2
- function quiz:ask_question/merge_5
@@ -1,4 +0,0 @@
1
- # block: then_0
2
- tellraw @s {"text":"Question 1: Which block drops diamonds?"}
3
- tellraw @s {"text":"A) Diamond ore B) Stone C) Oak log"}
4
- function quiz:ask_question/merge_2
@@ -1,4 +0,0 @@
1
- # block: then_3
2
- tellraw @s {"text":"Question 2: Which food restores more hunger?"}
3
- tellraw @s {"text":"A) Bread B) Steak C) Beetroot"}
4
- function quiz:ask_question/merge_5
@@ -1,4 +0,0 @@
1
- # block: then_6
2
- tellraw @s {"text":"Question 3: Which mob explodes?"}
3
- tellraw @s {"text":"A) Cow B) Creeper C) Villager"}
4
- function quiz:ask_question/merge_8
@@ -1,7 +0,0 @@
1
- # block: entry
2
- execute store result score $t0 rs run scoreboard players get @s quiz_question
3
- scoreboard players operation $question rs = $t0 rs
4
- scoreboard players set $t1 rs 0
5
- execute if score $t0 rs = $const_1 rs run scoreboard players set $t1 rs 1
6
- execute if score $t1 rs matches 1.. run function quiz:ask_question/then_0
7
- execute if score $t1 rs matches ..0 run function quiz:ask_question/else_1
@@ -1,6 +0,0 @@
1
- # block: entry
2
- execute store result score $t0 rs run scoreboard players get @s quiz_score
3
- title @s title {"text":"Quiz Complete"}
4
- tellraw @s {"text":"Your final quiz score is recorded in quiz_score."}
5
- scoreboard players set @s quiz_question 0
6
- execute store result score @s quiz_score run scoreboard players get $t1 rs
@@ -1,5 +0,0 @@
1
- # block: else_1
2
- scoreboard players set $t5 rs 0
3
- execute if score $question rs = $const_2 rs run scoreboard players set $t5 rs 1
4
- execute if score $t5 rs matches 1.. run function quiz:handle_answer/then_6
5
- execute if score $t5 rs matches ..0 run function quiz:handle_answer/else_7
@@ -1,3 +0,0 @@
1
- # block: else_10
2
- tellraw @s {"text":"Wrong. The answer was B."}
3
- function quiz:handle_answer/merge_11
@@ -1,3 +0,0 @@
1
- # block: else_16
2
- tellraw @s {"text":"Wrong. The answer was B."}
3
- function quiz:handle_answer/merge_17
@@ -1,3 +0,0 @@
1
- # block: else_4
2
- tellraw @s {"text":"Wrong. The answer was A."}
3
- function quiz:handle_answer/merge_5
@@ -1,5 +0,0 @@
1
- # block: else_7
2
- scoreboard players set $t8 rs 0
3
- execute if score $question rs = $const_3 rs run scoreboard players set $t8 rs 1
4
- execute if score $t8 rs matches 1.. run function quiz:handle_answer/then_12
5
- execute if score $t8 rs matches ..0 run function quiz:handle_answer/merge_14
@@ -1,2 +0,0 @@
1
- # block: merge_11
2
- function quiz:handle_answer/merge_8
@@ -1,2 +0,0 @@
1
- # block: merge_14
2
- function quiz:handle_answer/merge_8
@@ -1,2 +0,0 @@
1
- # block: merge_17
2
- function quiz:handle_answer/merge_14
@@ -1,8 +0,0 @@
1
- # block: merge_2
2
- execute store result score @s quiz_score run scoreboard players get $t11 rs
3
- scoreboard players operation $t12 rs = $question rs
4
- scoreboard players operation $t12 rs += $const_1 rs
5
- scoreboard players operation $question rs = $t12 rs
6
- execute store result score @s quiz_question run scoreboard players get $t13 rs
7
- function quiz:ask_question
8
- scoreboard players operation $t14 rs = $ret rs
@@ -1,2 +0,0 @@
1
- # block: merge_5
2
- function quiz:handle_answer/merge_2
@@ -1,2 +0,0 @@
1
- # block: merge_8
2
- function quiz:handle_answer/merge_2
@@ -1,5 +0,0 @@
1
- # block: then_0
2
- scoreboard players set $t3 rs 0
3
- execute if score $choice rs = $const_1 rs run scoreboard players set $t3 rs 1
4
- execute if score $t3 rs matches 1.. run function quiz:handle_answer/then_3
5
- execute if score $t3 rs matches ..0 run function quiz:handle_answer/else_4
@@ -1,5 +0,0 @@
1
- # block: then_12
2
- scoreboard players set $t9 rs 0
3
- execute if score $choice rs = $const_2 rs run scoreboard players set $t9 rs 1
4
- execute if score $t9 rs matches 1.. run function quiz:handle_answer/then_15
5
- execute if score $t9 rs matches ..0 run function quiz:handle_answer/else_16
@@ -1,6 +0,0 @@
1
- # block: then_15
2
- scoreboard players operation $t10 rs = $score rs
3
- scoreboard players operation $t10 rs += $const_1 rs
4
- scoreboard players operation $score rs = $t10 rs
5
- tellraw @s {"text":"Correct."}
6
- function quiz:handle_answer/merge_17
@@ -1,6 +0,0 @@
1
- # block: then_3
2
- scoreboard players operation $t4 rs = $score rs
3
- scoreboard players operation $t4 rs += $const_1 rs
4
- scoreboard players operation $score rs = $t4 rs
5
- tellraw @s {"text":"Correct."}
6
- function quiz:handle_answer/merge_5
@@ -1,5 +0,0 @@
1
- # block: then_6
2
- scoreboard players set $t6 rs 0
3
- execute if score $choice rs = $const_2 rs run scoreboard players set $t6 rs 1
4
- execute if score $t6 rs matches 1.. run function quiz:handle_answer/then_9
5
- execute if score $t6 rs matches ..0 run function quiz:handle_answer/else_10
@@ -1,6 +0,0 @@
1
- # block: then_9
2
- scoreboard players operation $t7 rs = $score rs
3
- scoreboard players operation $t7 rs += $const_1 rs
4
- scoreboard players operation $score rs = $t7 rs
5
- tellraw @s {"text":"Correct."}
6
- function quiz:handle_answer/merge_11
@@ -1,11 +0,0 @@
1
- # block: entry
2
- scoreboard players operation $choice rs = $p0 rs
3
- scoreboard players operation $choice rs = $p0 rs
4
- execute store result score $t0 rs run scoreboard players get @s quiz_question
5
- scoreboard players operation $question rs = $t0 rs
6
- execute store result score $t1 rs run scoreboard players get @s quiz_score
7
- scoreboard players operation $score rs = $t1 rs
8
- scoreboard players set $t2 rs 0
9
- execute if score $t0 rs = $const_1 rs run scoreboard players set $t2 rs 1
10
- execute if score $t2 rs matches 1.. run function quiz:handle_answer/then_0
11
- execute if score $t2 rs matches ..0 run function quiz:handle_answer/else_1
@@ -1,5 +0,0 @@
1
- # block: entry
2
- scoreboard players set @s quiz_score 0
3
- scoreboard players set @s quiz_question 1
4
- function quiz:ask_question
5
- scoreboard players operation $t0 rs = $ret rs
@@ -1,7 +0,0 @@
1
- # RedScript runtime init
2
- scoreboard objectives add rs dummy
3
- scoreboard objectives add shop_buy trigger
4
- scoreboard players enable @a shop_buy
5
- scoreboard players set $const_1 rs 1
6
- scoreboard players set $const_2 rs 2
7
- scoreboard players set $const_3 rs 3
@@ -1,3 +0,0 @@
1
- # RedScript tick dispatcher
2
- # Trigger checks
3
- execute as @a[scores={shop_buy=1..}] run function shop:__trigger_shop_buy_dispatch
@@ -1,4 +0,0 @@
1
- # Trigger dispatch for shop_buy
2
- function shop:handle_shop_trigger
3
- scoreboard players set @s shop_buy 0
4
- scoreboard players enable @s shop_buy
@@ -1,5 +0,0 @@
1
- # block: else_1
2
- scoreboard players set $t2 rs 0
3
- execute if score $choice rs = $const_2 rs run scoreboard players set $t2 rs 1
4
- execute if score $t2 rs matches 1.. run function shop:complete_purchase/then_3
5
- execute if score $t2 rs matches ..0 run function shop:complete_purchase/else_4
@@ -1,5 +0,0 @@
1
- # block: else_4
2
- scoreboard players set $t3 rs 0
3
- execute if score $choice rs = $const_3 rs run scoreboard players set $t3 rs 1
4
- execute if score $t3 rs matches 1.. run function shop:complete_purchase/then_6
5
- execute if score $t3 rs matches ..0 run function shop:complete_purchase/else_7
@@ -1,3 +0,0 @@
1
- # block: else_7
2
- tellraw @s {"text":"Invalid shop_choice. Use 1, 2, or 3."}
3
- function shop:complete_purchase/merge_8
@@ -1,2 +0,0 @@
1
- # block: merge_2
2
- scoreboard players set @s shop_choice 0
@@ -1,2 +0,0 @@
1
- # block: merge_5
2
- function shop:complete_purchase/merge_2
@@ -1,2 +0,0 @@
1
- # block: merge_8
2
- function shop:complete_purchase/merge_5
@@ -1,4 +0,0 @@
1
- # block: then_0
2
- give @s minecraft:bread 1
3
- tellraw @s {"text":"You bought bread."}
4
- function shop:complete_purchase/merge_2
@@ -1,4 +0,0 @@
1
- # block: then_3
2
- give @s minecraft:steak 1
3
- tellraw @s {"text":"You bought steak."}
4
- function shop:complete_purchase/merge_5
@@ -1,4 +0,0 @@
1
- # block: then_6
2
- give @s minecraft:diamond 1
3
- tellraw @s {"text":"You bought a diamond."}
4
- function shop:complete_purchase/merge_8
@@ -1,7 +0,0 @@
1
- # block: entry
2
- execute store result score $t0 rs run scoreboard players get @s shop_choice
3
- scoreboard players operation $choice rs = $t0 rs
4
- scoreboard players set $t1 rs 0
5
- execute if score $t0 rs = $const_1 rs run scoreboard players set $t1 rs 1
6
- execute if score $t1 rs matches 1.. run function shop:complete_purchase/then_0
7
- execute if score $t1 rs matches ..0 run function shop:complete_purchase/else_1
@@ -1,3 +0,0 @@
1
- # block: entry
2
- function shop:complete_purchase
3
- scoreboard players operation $t0 rs = $ret rs
@@ -1,5 +0,0 @@
1
- # RedScript runtime init
2
- scoreboard objectives add rs dummy
3
- scoreboard players set $__tick_turret_tick rs 0
4
- scoreboard objectives add deploy_turret trigger
5
- scoreboard players enable @a deploy_turret