Skip to main content

Flare datapack compiler framework

Project description

Flare

Flare is a modern, programmatic framework for building Minecraft datapacks natively in Python. 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!

Installation

pip install flaremc

Quick Start

Create a main.py file with your datapack logic:

from flare import namespace, score

namespace("my_pack")

# Scores are automatically compiled to scoreboard operations
health = score(20)
damage = score(5)
health -= damage

if health < 10:
    print("Warning: Low Health!")

Then compile and run your code using the built-in emulator:

flare main.py --run

CLI Usage

The flare command-line tool has several useful flags:

  • flare init - Initializes a basic Flare project in the current directory.
  • flare <file> --watch - Compiles your datapack and watches for any file changes to rebuild automatically.
  • flare <file> --run - Compiles and runs the datapack using the internal mcemu emulator.
  • flare <file> --run=5 - Runs the datapack in the emulator with an automatic timeout of 5 seconds.

Writing Minecraft Commands Natively

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.

from flare import namespace, score

namespace("my_pack")

# Write raw commands natively! Flare translates them automatically.
say Hello World!
/tp @a ~ ~ ~
execute as @a run particle flame ~ ~ ~

# You can still use standard Python logic around them!
health = score(20)
if health < 10:
    title @a title "Low Health!"

Debugging Output (print & dbg)

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!

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!

from flare import score, dbg

x = score(10)

print("The value of x is:", x)  # Emits a nicely formatted tellraw command to the game!
dbg("Raw representation:", x)   # Prints raw representation to BOTH the compiler console and the game!

The score Object

A score represents a Minecraft scoreboard objective. Flare handles the tedious parts of allocating and managing temporary scoreboards behind the scenes.

from flare import score

x = score(100)
y = score(50)
z = x + y  # Behind the scenes, Flare generates 'scoreboard players operation ...'

Fixed Precision (fixed)

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!

from flare import fixed

# fixed[5] means the number has 5 decimal places of precision (multiplier of 1e-5)
# So 1.5 in Python will be stored as 150000 on the scoreboard.
a = fixed[5](1.5)
b = fixed[5](2.0)
c = a * b  # Flare handles all scaling math for you!

NBT Variables

Flare supports full, programmatic NBT data manipulation! You define the NBT type you want using nbt[type].

Basic NBT

from flare import nbt, nbtint

# Shorthand for NBT Integers
level = nbtint(5, addr="storage mypack:data Level")

# Standard generic NBT type
health = nbt[float](20.0, addr="@s Health")

Arrays and Lists

from flare import nbtintarray, nbtlist

my_array = nbtintarray([1, 2, 3], addr="storage mypack:data MyArray")
my_array.append(4)
my_array.prepend(0)

NBT Path Chaining

You can dynamically traverse NBT Compounds using standard Python dot notation or dictionary indexing!

from flare import nbtdict

player_data = nbtdict(addr="storage mypack:data Player")

# Access sub-paths dynamically
inventory = player_data.Inventory
first_slot = inventory[0]

# If your NBT key has a space, use indexing!
weird_key = player_data["Custom Key With Space"]

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!


Avoiding Copies with ref

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.

If you just want to pass a variable around in Python without emitting a command, wrap it in a ref!

from flare import score, ref

x = score(10)

z = x       # COPIES the value. Flare emits a command to map a new variable 'z' and copy 'x'.
y = ref(x)  # NO COPY. 'y' acts as a Python reference pointing to the exact same 'x' address.

x += 5      # Modifies 'x' (now 15). Because 'y' is a ref, 'y' is also 15. 'z' remains 10.
y += 5      # Modifies 'x' again (now 20).

print(x, y, z)  # Output in game will be: 20 20 10

Control Flow (If, For, While)

Flare seamlessly translates standard Python control flow into execute logic and dynamically generated mcfunction blocks!

x = score(5)
y = score(10)

if x > y:
    print("X is bigger!")
elif x == y:
    print("They are equal!")
else:
    print("Y is bigger!")

# Loops
for item in my_array:
    print(item)

Compile-Time Optimization

Flare is highly optimized. It checks conditions at compile-time.

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!

y = 5
x = score(5)

# 'x' is dynamic, so Flare generates an 'execute if score...' command for this branch
if x > 4:
    print("Maybe!")
    
# 'y' is a static Python variable. Flare checks '5 > 4' at compile-time.
# Because it evaluates to True, Flare runs this block unconditionally and ignores the else block!
elif y > 4:
    print("Definitely!")

# This block is physically discarded and will NOT exist in the final datapack!
else:
    print("Never!")

Under the Hood: __icopy__ vs __iset__

Flare uses standard Python assignment (=) heavily, but it treats new and existing variables differently to prevent memory leaks and optimize command generation:

  • __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.
  • __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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flaremc-0.1.0.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flaremc-0.1.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file flaremc-0.1.0.tar.gz.

File metadata

  • Download URL: flaremc-0.1.0.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for flaremc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ea28f1dfaae0bfa4337f70f9a051b676a837ab2065547471d6823629f7361fa
MD5 e9c93901ed6e6d0ae590486c24ba81c8
BLAKE2b-256 dbde7f03ce3c2e3c0b60364d86bc591e9d32e0ead2a831782d78ac2e041b5f79

See more details on using hashes here.

File details

Details for the file flaremc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flaremc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for flaremc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29fe8d8b9d3e112afffa4107a733add0e4b533af5267bf5f4a44c212878513ae
MD5 73617320a7be99adb714cef1d4318675
BLAKE2b-256 ee16cb4ffb94a325a20418c3c38c1cb5699b457744a19ad4012c37e203956c46

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page