flaremc 0.1.0__tar.gz
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.
- flaremc-0.1.0/LICENSE +21 -0
- flaremc-0.1.0/PKG-INFO +235 -0
- flaremc-0.1.0/README.md +224 -0
- flaremc-0.1.0/flare/__init__.py +11 -0
- flaremc-0.1.0/flare/__main__.py +4 -0
- flaremc-0.1.0/flare/cli.py +311 -0
- flaremc-0.1.0/flare/compiler.py +102 -0
- flaremc-0.1.0/flare/context.py +191 -0
- flaremc-0.1.0/flare/control_flow.py +139 -0
- flaremc-0.1.0/flare/preprocessor.py +179 -0
- flaremc-0.1.0/flare/types.py +37 -0
- flaremc-0.1.0/flare/variables.py +1193 -0
- flaremc-0.1.0/flaremc.egg-info/PKG-INFO +235 -0
- flaremc-0.1.0/flaremc.egg-info/SOURCES.txt +20 -0
- flaremc-0.1.0/flaremc.egg-info/dependency_links.txt +1 -0
- flaremc-0.1.0/flaremc.egg-info/entry_points.txt +2 -0
- flaremc-0.1.0/flaremc.egg-info/requires.txt +2 -0
- flaremc-0.1.0/flaremc.egg-info/top_level.txt +2 -0
- flaremc-0.1.0/flarevsc/node_modules/flatted/python/flatted.py +144 -0
- flaremc-0.1.0/pyproject.toml +21 -0
- flaremc-0.1.0/setup.cfg +4 -0
- flaremc-0.1.0/tests/test_flare.py +96 -0
flaremc-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Oğuzhan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
flaremc-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flaremc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Flare datapack compiler framework
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: mcemu
|
|
9
|
+
Requires-Dist: watchdog
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Flare
|
|
13
|
+
|
|
14
|
+
Flare is a modern, programmatic framework for building Minecraft datapacks natively in Python.
|
|
15
|
+
With Flare, you can write Minecraft commands and logic using standard Python syntax, variables, conditionals, and loops, and compile them effortlessly into highly-optimized `.mcfunction` datapacks. Because Flare is just Python, you have the full power of the Python language and any external libraries at your disposal!
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
```bash
|
|
19
|
+
pip install flaremc
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
Create a `main.py` file with your datapack logic:
|
|
24
|
+
```python
|
|
25
|
+
from flare import namespace, score
|
|
26
|
+
|
|
27
|
+
namespace("my_pack")
|
|
28
|
+
|
|
29
|
+
# Scores are automatically compiled to scoreboard operations
|
|
30
|
+
health = score(20)
|
|
31
|
+
damage = score(5)
|
|
32
|
+
health -= damage
|
|
33
|
+
|
|
34
|
+
if health < 10:
|
|
35
|
+
print("Warning: Low Health!")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then compile and run your code using the built-in emulator:
|
|
39
|
+
```bash
|
|
40
|
+
flare main.py --run
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## CLI Usage
|
|
44
|
+
|
|
45
|
+
The `flare` command-line tool has several useful flags:
|
|
46
|
+
- `flare init` - Initializes a basic Flare project in the current directory.
|
|
47
|
+
- `flare <file> --watch` - Compiles your datapack and watches for any file changes to rebuild automatically.
|
|
48
|
+
- `flare <file> --run` - Compiles and runs the datapack using the internal `mcemu` emulator.
|
|
49
|
+
- `flare <file> --run=5` - Runs the datapack in the emulator with an automatic timeout of 5 seconds.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Writing Minecraft Commands Natively
|
|
54
|
+
|
|
55
|
+
Flare includes a smart preprocessor that allows you to write literal Minecraft commands directly within your Python script! You don't need to wrap them in functions or strings—just write them as you would in an `.mcfunction` file.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from flare import namespace, score
|
|
59
|
+
|
|
60
|
+
namespace("my_pack")
|
|
61
|
+
|
|
62
|
+
# Write raw commands natively! Flare translates them automatically.
|
|
63
|
+
say Hello World!
|
|
64
|
+
/tp @a ~ ~ ~
|
|
65
|
+
execute as @a run particle flame ~ ~ ~
|
|
66
|
+
|
|
67
|
+
# You can still use standard Python logic around them!
|
|
68
|
+
health = score(20)
|
|
69
|
+
if health < 10:
|
|
70
|
+
title @a title "Low Health!"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Debugging Output (`print` & `dbg`)
|
|
76
|
+
|
|
77
|
+
In Flare, calling the standard `print()` function is automatically intercepted and translated into a highly-formatted Minecraft `tellraw` command so the output appears directly in the game chat!
|
|
78
|
+
|
|
79
|
+
If you want to debug the raw underlying Python objects, use Flare's `dbg()` function. It prints the raw `<score object ...>` string directly to your local compiler console, and simultaneously emits a raw `tellraw` command to the game!
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from flare import score, dbg
|
|
83
|
+
|
|
84
|
+
x = score(10)
|
|
85
|
+
|
|
86
|
+
print("The value of x is:", x) # Emits a nicely formatted tellraw command to the game!
|
|
87
|
+
dbg("Raw representation:", x) # Prints raw representation to BOTH the compiler console and the game!
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## The `score` Object
|
|
93
|
+
|
|
94
|
+
A `score` represents a Minecraft scoreboard objective. Flare handles the tedious parts of allocating and managing temporary scoreboards behind the scenes.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from flare import score
|
|
98
|
+
|
|
99
|
+
x = score(100)
|
|
100
|
+
y = score(50)
|
|
101
|
+
z = x + y # Behind the scenes, Flare generates 'scoreboard players operation ...'
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Fixed Precision (`fixed`)
|
|
105
|
+
|
|
106
|
+
In Minecraft, scoreboards can only store integers. To work with decimal numbers, Flare scales values. You can use the `fixed` class to specify decimal precision natively!
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from flare import fixed
|
|
110
|
+
|
|
111
|
+
# fixed[5] means the number has 5 decimal places of precision (multiplier of 1e-5)
|
|
112
|
+
# So 1.5 in Python will be stored as 150000 on the scoreboard.
|
|
113
|
+
a = fixed[5](1.5)
|
|
114
|
+
b = fixed[5](2.0)
|
|
115
|
+
c = a * b # Flare handles all scaling math for you!
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## NBT Variables
|
|
121
|
+
|
|
122
|
+
Flare supports full, programmatic NBT data manipulation! You define the NBT type you want using `nbt[type]`.
|
|
123
|
+
|
|
124
|
+
### Basic NBT
|
|
125
|
+
```python
|
|
126
|
+
from flare import nbt, nbtint
|
|
127
|
+
|
|
128
|
+
# Shorthand for NBT Integers
|
|
129
|
+
level = nbtint(5, addr="storage mypack:data Level")
|
|
130
|
+
|
|
131
|
+
# Standard generic NBT type
|
|
132
|
+
health = nbt[float](20.0, addr="@s Health")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Arrays and Lists
|
|
136
|
+
```python
|
|
137
|
+
from flare import nbtintarray, nbtlist
|
|
138
|
+
|
|
139
|
+
my_array = nbtintarray([1, 2, 3], addr="storage mypack:data MyArray")
|
|
140
|
+
my_array.append(4)
|
|
141
|
+
my_array.prepend(0)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### NBT Path Chaining
|
|
145
|
+
You can dynamically traverse NBT Compounds using standard Python dot notation or dictionary indexing!
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from flare import nbtdict
|
|
149
|
+
|
|
150
|
+
player_data = nbtdict(addr="storage mypack:data Player")
|
|
151
|
+
|
|
152
|
+
# Access sub-paths dynamically
|
|
153
|
+
inventory = player_data.Inventory
|
|
154
|
+
first_slot = inventory[0]
|
|
155
|
+
|
|
156
|
+
# If your NBT key has a space, use indexing!
|
|
157
|
+
weird_key = player_data["Custom Key With Space"]
|
|
158
|
+
```
|
|
159
|
+
*Note: Flare dynamically generates the string path behind the scenes (`Player.Inventory[0]`). Commands are only emitted when you read or write to these endpoints!*
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Avoiding Copies with `ref`
|
|
164
|
+
|
|
165
|
+
By default, in Flare, if you assign a variable to another variable (`y = x`), it generates a Minecraft command to physically copy the data from `x`'s address to `y`'s address.
|
|
166
|
+
|
|
167
|
+
If you just want to pass a variable around in Python *without* emitting a command, wrap it in a `ref`!
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from flare import score, ref
|
|
171
|
+
|
|
172
|
+
x = score(10)
|
|
173
|
+
|
|
174
|
+
z = x # COPIES the value. Flare emits a command to map a new variable 'z' and copy 'x'.
|
|
175
|
+
y = ref(x) # NO COPY. 'y' acts as a Python reference pointing to the exact same 'x' address.
|
|
176
|
+
|
|
177
|
+
x += 5 # Modifies 'x' (now 15). Because 'y' is a ref, 'y' is also 15. 'z' remains 10.
|
|
178
|
+
y += 5 # Modifies 'x' again (now 20).
|
|
179
|
+
|
|
180
|
+
print(x, y, z) # Output in game will be: 20 20 10
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Control Flow (If, For, While)
|
|
186
|
+
|
|
187
|
+
Flare seamlessly translates standard Python control flow into `execute` logic and dynamically generated `mcfunction` blocks!
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
x = score(5)
|
|
191
|
+
y = score(10)
|
|
192
|
+
|
|
193
|
+
if x > y:
|
|
194
|
+
print("X is bigger!")
|
|
195
|
+
elif x == y:
|
|
196
|
+
print("They are equal!")
|
|
197
|
+
else:
|
|
198
|
+
print("Y is bigger!")
|
|
199
|
+
|
|
200
|
+
# Loops
|
|
201
|
+
for item in my_array:
|
|
202
|
+
print(item)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Compile-Time Optimization
|
|
206
|
+
Flare is highly optimized. It checks conditions at **compile-time**.
|
|
207
|
+
|
|
208
|
+
If a condition relies purely on standard Python variables (and not Minecraft `score` or `nbt` objects), Flare resolves the logic natively and *never* generates Minecraft commands for branches that it knows will never run!
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
y = 5
|
|
212
|
+
x = score(5)
|
|
213
|
+
|
|
214
|
+
# 'x' is dynamic, so Flare generates an 'execute if score...' command for this branch
|
|
215
|
+
if x > 4:
|
|
216
|
+
print("Maybe!")
|
|
217
|
+
|
|
218
|
+
# 'y' is a static Python variable. Flare checks '5 > 4' at compile-time.
|
|
219
|
+
# Because it evaluates to True, Flare runs this block unconditionally and ignores the else block!
|
|
220
|
+
elif y > 4:
|
|
221
|
+
print("Definitely!")
|
|
222
|
+
|
|
223
|
+
# This block is physically discarded and will NOT exist in the final datapack!
|
|
224
|
+
else:
|
|
225
|
+
print("Never!")
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Under the Hood: `__icopy__` vs `__iset__`
|
|
231
|
+
|
|
232
|
+
Flare uses standard Python assignment (`=`) heavily, but it treats new and existing variables differently to prevent memory leaks and optimize command generation:
|
|
233
|
+
|
|
234
|
+
- **`__icopy__` (New Variables)**: If you type `y = x` and `y` hasn't been used yet, Flare dynamically creates a completely new Minecraft variable for `y` and emits commands to physically copy the data from `x`'s address to `y`. This safely isolates the two variables.
|
|
235
|
+
- **`__iset__` (Existing Variables)**: If `y` is an *already existing* Flare variable and you want to update its value, you shouldn't use `y = x` (as this would try to create a new `y` and potentially overwrite the Python reference, losing track of your NBT structure or scoreboard address). Instead, use `y[:] = x` (or call `y.__iset__(x)` directly). This tells Flare to emit commands to update the *existing* address of `y` with the value from `x`!
|
flaremc-0.1.0/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Flare
|
|
2
|
+
|
|
3
|
+
Flare is a modern, programmatic framework for building Minecraft datapacks natively in Python.
|
|
4
|
+
With Flare, you can write Minecraft commands and logic using standard Python syntax, variables, conditionals, and loops, and compile them effortlessly into highly-optimized `.mcfunction` datapacks. Because Flare is just Python, you have the full power of the Python language and any external libraries at your disposal!
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
```bash
|
|
8
|
+
pip install flaremc
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
Create a `main.py` file with your datapack logic:
|
|
13
|
+
```python
|
|
14
|
+
from flare import namespace, score
|
|
15
|
+
|
|
16
|
+
namespace("my_pack")
|
|
17
|
+
|
|
18
|
+
# Scores are automatically compiled to scoreboard operations
|
|
19
|
+
health = score(20)
|
|
20
|
+
damage = score(5)
|
|
21
|
+
health -= damage
|
|
22
|
+
|
|
23
|
+
if health < 10:
|
|
24
|
+
print("Warning: Low Health!")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then compile and run your code using the built-in emulator:
|
|
28
|
+
```bash
|
|
29
|
+
flare main.py --run
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## CLI Usage
|
|
33
|
+
|
|
34
|
+
The `flare` command-line tool has several useful flags:
|
|
35
|
+
- `flare init` - Initializes a basic Flare project in the current directory.
|
|
36
|
+
- `flare <file> --watch` - Compiles your datapack and watches for any file changes to rebuild automatically.
|
|
37
|
+
- `flare <file> --run` - Compiles and runs the datapack using the internal `mcemu` emulator.
|
|
38
|
+
- `flare <file> --run=5` - Runs the datapack in the emulator with an automatic timeout of 5 seconds.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Writing Minecraft Commands Natively
|
|
43
|
+
|
|
44
|
+
Flare includes a smart preprocessor that allows you to write literal Minecraft commands directly within your Python script! You don't need to wrap them in functions or strings—just write them as you would in an `.mcfunction` file.
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from flare import namespace, score
|
|
48
|
+
|
|
49
|
+
namespace("my_pack")
|
|
50
|
+
|
|
51
|
+
# Write raw commands natively! Flare translates them automatically.
|
|
52
|
+
say Hello World!
|
|
53
|
+
/tp @a ~ ~ ~
|
|
54
|
+
execute as @a run particle flame ~ ~ ~
|
|
55
|
+
|
|
56
|
+
# You can still use standard Python logic around them!
|
|
57
|
+
health = score(20)
|
|
58
|
+
if health < 10:
|
|
59
|
+
title @a title "Low Health!"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Debugging Output (`print` & `dbg`)
|
|
65
|
+
|
|
66
|
+
In Flare, calling the standard `print()` function is automatically intercepted and translated into a highly-formatted Minecraft `tellraw` command so the output appears directly in the game chat!
|
|
67
|
+
|
|
68
|
+
If you want to debug the raw underlying Python objects, use Flare's `dbg()` function. It prints the raw `<score object ...>` string directly to your local compiler console, and simultaneously emits a raw `tellraw` command to the game!
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from flare import score, dbg
|
|
72
|
+
|
|
73
|
+
x = score(10)
|
|
74
|
+
|
|
75
|
+
print("The value of x is:", x) # Emits a nicely formatted tellraw command to the game!
|
|
76
|
+
dbg("Raw representation:", x) # Prints raw representation to BOTH the compiler console and the game!
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## The `score` Object
|
|
82
|
+
|
|
83
|
+
A `score` represents a Minecraft scoreboard objective. Flare handles the tedious parts of allocating and managing temporary scoreboards behind the scenes.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from flare import score
|
|
87
|
+
|
|
88
|
+
x = score(100)
|
|
89
|
+
y = score(50)
|
|
90
|
+
z = x + y # Behind the scenes, Flare generates 'scoreboard players operation ...'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Fixed Precision (`fixed`)
|
|
94
|
+
|
|
95
|
+
In Minecraft, scoreboards can only store integers. To work with decimal numbers, Flare scales values. You can use the `fixed` class to specify decimal precision natively!
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from flare import fixed
|
|
99
|
+
|
|
100
|
+
# fixed[5] means the number has 5 decimal places of precision (multiplier of 1e-5)
|
|
101
|
+
# So 1.5 in Python will be stored as 150000 on the scoreboard.
|
|
102
|
+
a = fixed[5](1.5)
|
|
103
|
+
b = fixed[5](2.0)
|
|
104
|
+
c = a * b # Flare handles all scaling math for you!
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## NBT Variables
|
|
110
|
+
|
|
111
|
+
Flare supports full, programmatic NBT data manipulation! You define the NBT type you want using `nbt[type]`.
|
|
112
|
+
|
|
113
|
+
### Basic NBT
|
|
114
|
+
```python
|
|
115
|
+
from flare import nbt, nbtint
|
|
116
|
+
|
|
117
|
+
# Shorthand for NBT Integers
|
|
118
|
+
level = nbtint(5, addr="storage mypack:data Level")
|
|
119
|
+
|
|
120
|
+
# Standard generic NBT type
|
|
121
|
+
health = nbt[float](20.0, addr="@s Health")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Arrays and Lists
|
|
125
|
+
```python
|
|
126
|
+
from flare import nbtintarray, nbtlist
|
|
127
|
+
|
|
128
|
+
my_array = nbtintarray([1, 2, 3], addr="storage mypack:data MyArray")
|
|
129
|
+
my_array.append(4)
|
|
130
|
+
my_array.prepend(0)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### NBT Path Chaining
|
|
134
|
+
You can dynamically traverse NBT Compounds using standard Python dot notation or dictionary indexing!
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from flare import nbtdict
|
|
138
|
+
|
|
139
|
+
player_data = nbtdict(addr="storage mypack:data Player")
|
|
140
|
+
|
|
141
|
+
# Access sub-paths dynamically
|
|
142
|
+
inventory = player_data.Inventory
|
|
143
|
+
first_slot = inventory[0]
|
|
144
|
+
|
|
145
|
+
# If your NBT key has a space, use indexing!
|
|
146
|
+
weird_key = player_data["Custom Key With Space"]
|
|
147
|
+
```
|
|
148
|
+
*Note: Flare dynamically generates the string path behind the scenes (`Player.Inventory[0]`). Commands are only emitted when you read or write to these endpoints!*
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Avoiding Copies with `ref`
|
|
153
|
+
|
|
154
|
+
By default, in Flare, if you assign a variable to another variable (`y = x`), it generates a Minecraft command to physically copy the data from `x`'s address to `y`'s address.
|
|
155
|
+
|
|
156
|
+
If you just want to pass a variable around in Python *without* emitting a command, wrap it in a `ref`!
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from flare import score, ref
|
|
160
|
+
|
|
161
|
+
x = score(10)
|
|
162
|
+
|
|
163
|
+
z = x # COPIES the value. Flare emits a command to map a new variable 'z' and copy 'x'.
|
|
164
|
+
y = ref(x) # NO COPY. 'y' acts as a Python reference pointing to the exact same 'x' address.
|
|
165
|
+
|
|
166
|
+
x += 5 # Modifies 'x' (now 15). Because 'y' is a ref, 'y' is also 15. 'z' remains 10.
|
|
167
|
+
y += 5 # Modifies 'x' again (now 20).
|
|
168
|
+
|
|
169
|
+
print(x, y, z) # Output in game will be: 20 20 10
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Control Flow (If, For, While)
|
|
175
|
+
|
|
176
|
+
Flare seamlessly translates standard Python control flow into `execute` logic and dynamically generated `mcfunction` blocks!
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
x = score(5)
|
|
180
|
+
y = score(10)
|
|
181
|
+
|
|
182
|
+
if x > y:
|
|
183
|
+
print("X is bigger!")
|
|
184
|
+
elif x == y:
|
|
185
|
+
print("They are equal!")
|
|
186
|
+
else:
|
|
187
|
+
print("Y is bigger!")
|
|
188
|
+
|
|
189
|
+
# Loops
|
|
190
|
+
for item in my_array:
|
|
191
|
+
print(item)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Compile-Time Optimization
|
|
195
|
+
Flare is highly optimized. It checks conditions at **compile-time**.
|
|
196
|
+
|
|
197
|
+
If a condition relies purely on standard Python variables (and not Minecraft `score` or `nbt` objects), Flare resolves the logic natively and *never* generates Minecraft commands for branches that it knows will never run!
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
y = 5
|
|
201
|
+
x = score(5)
|
|
202
|
+
|
|
203
|
+
# 'x' is dynamic, so Flare generates an 'execute if score...' command for this branch
|
|
204
|
+
if x > 4:
|
|
205
|
+
print("Maybe!")
|
|
206
|
+
|
|
207
|
+
# 'y' is a static Python variable. Flare checks '5 > 4' at compile-time.
|
|
208
|
+
# Because it evaluates to True, Flare runs this block unconditionally and ignores the else block!
|
|
209
|
+
elif y > 4:
|
|
210
|
+
print("Definitely!")
|
|
211
|
+
|
|
212
|
+
# This block is physically discarded and will NOT exist in the final datapack!
|
|
213
|
+
else:
|
|
214
|
+
print("Never!")
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Under the Hood: `__icopy__` vs `__iset__`
|
|
220
|
+
|
|
221
|
+
Flare uses standard Python assignment (`=`) heavily, but it treats new and existing variables differently to prevent memory leaks and optimize command generation:
|
|
222
|
+
|
|
223
|
+
- **`__icopy__` (New Variables)**: If you type `y = x` and `y` hasn't been used yet, Flare dynamically creates a completely new Minecraft variable for `y` and emits commands to physically copy the data from `x`'s address to `y`. This safely isolates the two variables.
|
|
224
|
+
- **`__iset__` (Existing Variables)**: If `y` is an *already existing* Flare variable and you want to update its value, you shouldn't use `y = x` (as this would try to create a new `y` and potentially overwrite the Python reference, losing track of your NBT structure or scoreboard address). Instead, use `y[:] = x` (or call `y.__iset__(x)` directly). This tells Flare to emit commands to update the *existing* address of `y` with the value from `x`!
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .compiler import _flatten_and, _eval_to_bool_score, _compile_relational
|
|
2
|
+
from .context import namespace, export, tick, push_context, runcommand, files, temp_obj, constant_obj, vars_obj, \
|
|
3
|
+
constants, _flare_assign, _flare_print, dbg
|
|
4
|
+
from .control_flow import _flare_if, _flare_while, _flare_for
|
|
5
|
+
from .types import NBTType, byte, boolean, short, long, double
|
|
6
|
+
from .variables import score, nbt, fixed, ref, getscore, nbtbyte, nbtbool, nbtshort, nbtint, nbtlong, nbtfloat, \
|
|
7
|
+
nbtdouble, nbtstr, nbtlist, nbtdict, nbtbytearray, nbtintarray, nbtlongarray
|
|
8
|
+
|
|
9
|
+
__all__ = ["namespace", "export", "tick", "score", "nbt", "fixed", "ref", "getscore", "_flare_print", "dbg", "nbtbyte", "nbtbool",
|
|
10
|
+
"nbtshort", "nbtint", "nbtlong", "nbtfloat", "nbtdouble", "nbtstr", "nbtlist", "nbtdict", "nbtbytearray",
|
|
11
|
+
"nbtintarray", "nbtlongarray"]
|