Cobble 🧱
A modern, Python-like language for creating Minecraft Data Packs
Cobble is a transpiler that converts Python-like code into Minecraft Data Packs, making it easier and more intuitive to create complex Minecraft command systems.
✨ Version 0.6.1 - Expanded validation diagnostics, standard library v1.1 helpers, namespaced data pack resources, project templates, and Minecraft Java Edition 26.1.2 support | Pack Format 101.1
⚠️ Pre-release Notice
Cobble is currently in active development (v0.6.1 Pre-Alpha). While we've implemented many features and extensive tests, the project may contain bugs and unexpected behavior. Features and APIs may change between releases.
We appreciate your feedback! If you encounter any issues, unexpected behavior, or have suggestions, please report them at:
- GitHub Issues: https://github.com/deveworld/cobble/issues
Your bug reports and feature requests help make Cobble better for everyone. Thank you for being an early adopter! 🙏
✨ Features
- ✅ Static Type System - Immutable types with compile-time inference and validation
- ✅ Python-like Syntax - Familiar, clean syntax with proper indentation
- ✅ Function Parameters - Full support using Minecraft function macro system
- ✅ Event System - Built-in event handling for load and tick events
- ✅ Control Flow - If statements, for loops (with step support), while loops with smart optimization
- ✅ Match/Switch Statements - Efficient multi-way branching with overlap validation
- ✅ Boolean Operators -
and,or,notoperators for complex conditions (e.g.,if x > 0 and y < 5 or z == 10:) - ✅ Complex Expressions - Multi-operator expressions with proper precedence (e.g.,
a + b * c) - ✅ Arithmetic Operations - Full support for +, -, *, /, %, ^ with variable and constant operands
- ✅ Advanced Operators - Modulo (%) and power (^) operators with compile-time optimization
- ✅ Expressions in Conditions - Use arithmetic directly in if/while (e.g.,
if x % 3 == 1:) - ✅ Compile-time Constants - Define constants with
constkeyword for compile-time evaluation - ✅ Entity Selector Definitions - Create custom selector aliases (e.g.,
@Player = @a[type=player]) - ✅ File Import System - Import functions and definitions from other
.cblfiles - ✅ Module-level Variables - Top-level assignments automatically initialized at pack load
- ✅ Numeric Range Warnings - Compile-time warnings for float precision and overflow
- ✅ Modern CLI - Full-featured command-line interface with watch mode and ZIP creation
- ✅ Project Management - Configuration via
cobble.toml - ✅ Correct Command Format - Follows Minecraft data pack specifications (no slash prefix)
- ✅ JSON Safety - Preserves JSON commands without breaking syntax
- ✅ Command Tree Validation - Validate generated
.mcfunctionfiles against Minecraft Java Edition 26.1.2 commands - ✅ Nested If Optimization - Automatically splits complex control flow
- ✅ Comprehensive Tests - Extensive unit, integration, fixture, validation, and source-map coverage
- ✅ Modern Parser - Built with chumsky combinator library for reliability
- ✅ Beautiful Errors - Clear error messages powered by ariadne
📦 Installation
From crates.io
The crates.io package is named cobble-lang; the installed command remains
cobble.
From Source
# Clone the repository
# Build with Cargo
# Binary will be in target/release/cobble
Add to PATH (Optional)
# Linux/macOS
# Or copy to system bin
🚀 Quick Start
1. Create a New Project
This creates:
my-datapack/
├── cobble.toml # Project configuration
├── src/
│ └── main.cbl # Main source file
└── .gitignore
2. Write Your Code
Edit src/main.cbl:
"""Initialize the data pack"""
/
/ @
"""Called every game tick"""
@ @:
/ : ~ ~2 ~ 0.5 0.5 0.5 0 1
"""Give reward to player using macro parameters"""
/ :
/
# Register event handlers
3. Build the Data Pack
# Build to output directory
# Build with ZIP
4. Use in Minecraft
Copy the output folder to your Minecraft world's datapacks directory:
.minecraft/saves/YourWorld/datapacks/
📖 Language Guide
Functions
Define functions with Python-style syntax:
"""Documentation string"""
/ :
/ @
Parameter Substitution:
- Use
{param}syntax directly for macro parameters - Cobble convert it to the
$()syntax for function parameters
Variables and Type System
Cobble has a static type system where variable types are inferred from their first assignment and cannot change:
# Module-level variables (initialized automatically at pack load)
= 0 # Type: Integer
= True # Type: Boolean
= 5 # Type: Integer
# Local variables (initialized when function is called)
= 100 # Type: Integer
= * 2 # Type: Integer (arithmetic result)
# Type error: cannot change type
# score = True # ERROR: cannot reassign integer to boolean
Type System Features:
- Automatic type inference - Types are inferred from first assignment
- Immutable types - Variables cannot change their type
- Compile-time checking - Type errors are caught before generating the data pack
- Expression types - Arithmetic operations return Integer, comparisons return Boolean
Module-level variables are automatically initialized in the _cobble_init function when the data pack loads.
Compile-time Constants
Define constants that are evaluated at compile time:
= 100
= 2
= 300
= # Replaced with 100 at compile time
/ :
Constants are replaced with their values during compilation, resulting in optimized code.
Entity Selector Definitions
Create custom selector aliases for cleaner, more maintainable code:
# Define custom selectors
= @
= @
= @
@:
/ @ 5
@:
/ @
@:
/ @ 999999 2
Selector aliases are replaced at compile time with zero runtime overhead.
File Import System
Import functions and definitions from other .cbl files:
# utils.cbl
/
= @
# main.cbl
# Imports utils.cbl
# Use imported function
@: # Use imported selector
/
Features:
- Relative import resolution
- Circular import errors with the import chain
- Missing import errors with the importing file and expected path
- Functions and selectors are merged into current namespace
Minecraft Commands
Direct Minecraft commands start with /:
/ : ~ ~ ~
/ @ : 30
Control Flow
If Statements
/ !
/ @ :
# Complex expressions in conditions
= 10
/ 3 1
# Multiple conditions with AND/OR
/ !
For Loops
# Basic loop
/ : ~ ~ ~
# Loop with step
/ 2:
# Countdown with negative step
/ -1:
While Loops
= 10
/ @
= - 1
Match/Switch Statements
Efficient multi-way branching based on integer values:
= 75
:
0 59:
/ :
60 69:
/ :
70 79:
/ :
80 89:
/ :
90 100:
/ :
:
/
:
1:
/
2:
/
3:
/
:
/
Features:
- Literal matching:
case 5:- matches exactly 5 - Range matching:
case 1 to 10:- matches values from 1 to 10 (inclusive) - Wildcard pattern:
case _:- matches anything not matched by previous cases - Overlap validation: Compiler ensures case ranges don't overlap (prevents bugs)
- Uses efficient 4-way split algorithm for optimal branching
Arithmetic Operations
Cobble supports full arithmetic operations with proper operator precedence:
= 10
= 5
= 3
# Simple operations
= + # 15
= - # 5
= * # 50
= / # 2
= % # 1 (modulo)
= ^ 2 # 25 (exponentiation)
# Multi-operator expressions
= + + # (a + b) + c = 18
= * * # (a * b) * c = 150
# Operator precedence
= + * # a + (b * c) = 25, NOT (a + b) * c
= * + # (a * b) + c = 53
= % + # (a % c) + b = 6
= ^ 2 * # (b ^ 2) * c = 75
# Loop variable arithmetic
= * 10 # Uses correct loop_counter objective
= + 5 # Loop variables work in all operations
# Complex expressions in conditions
# Use arithmetic directly in conditions
/
Operator Precedence (highest to lowest):
^- Power/exponentiation*,/,%- Multiplication, division, and modulo+,-- Addition and subtraction==,!=,<,<=,>,>=- Comparisons
Implementation Details:
- Simple operations compile to optimized scoreboard commands
- Complex expressions use temporary variables automatically
- Power operator uses compile-time expansion (e.g.,
x^3becomesx*x*x) - Modulo and division use temporary helper variables (
modulus,divisor) - Loop variables correctly track their objective (e.g.,
loop_counter) - Arithmetic expressions in conditions are automatically evaluated to temporary variables
Imports and Modules
Import from the standard library or other .cbl files:
# Standard library imports
# File imports (imports from other .cbl files)
# Imports utils.cbl
# Imports helpers.cbl
# Use imported functions and selectors
# From utils.cbl
See File Import System for more details on importing from .cbl files.
Standard Library Helpers
Cobble 0.6.1 includes compiler-backed helpers for common data pack tasks:
=
Supported helper modules:
text-tellraw,title,subtitle,actionbarscore-set,add,remove,reset,copy,operationrandom-int,booltimer-set,tick,done,resetstorage-set,merge,remove,copy,append,prepend,insert,get,read_score,copy_fromscore.objective-add,remove,displayschedule-once,clearbossbar-add,remove,set_value,set_max,set_name,set_color,set_style,set_visible,set_playersteam-add,remove,join,leave,modifyentity-tag_add,tag_remove,effect_give,effect_clear,attribute_get,attribute_base_setmath-sqrt,abs,min,max
Data Pack JSON Resources
Top-level datapack.* declarations generate common JSON resources:
Supported resources include function/block/item/entity type tags, predicates,
advancements, loot tables, recipes, item modifiers, and dialogs. Resource names
can use nested paths and optional explicit namespaces such as
other_namespace:checks/is_ready.
Event System
Register functions to run on specific events:
/ !
# Runs 20 times per second
pass
🛠️ CLI Commands
cobble init [OPTIONS]
Initialize a new Cobble project.
Options:
--name <NAME>- Project name (creates a new directory if specified)--description <DESCRIPTION>- Project description--pack-format <FORMAT>- Pack format version (default: 101.1)--template <NAME>- Project template:minimal,stdlib, orvalidation
cobble build [input] [options]
Build the data pack from source files.
Options:
-o, --output <dir>- Output directory--zip- Create ZIP archive--validate- Validate generated.mcfunctionfiles against Minecraft Java Edition 26.1.2 commands--commands-json <path>- Path to the exported command tree (default:data/commands.json; auto-generated when missing)
The default data/commands.json is generated automatically on first validation.
This requires curl and Java because Cobble downloads the Minecraft server jar
and runs the server reports generator. For custom paths, generate the file
manually and copy it to the requested path:
If Mojang's manifest endpoint is blocked on your network, Cobble also tries the legacy launcher manifest host and a pinned 26.1.2 server jar URL. You can override the source explicitly:
COBBLE_COMMANDS_JSON_URL=https://example.com/commands.json
COBBLE_MINECRAFT_SERVER_URL=https://example.com/server.jar
COBBLE_MINECRAFT_SERVER_JAR=/path/to/server.jar
COBBLE_MINECRAFT_SERVER_SHA1=<sha1> COBBLE_MINECRAFT_SERVER_URL=https://example.com/server.jar
cobble watch [input] [options]
Watch files and rebuild on changes.
cobble check [input]
Check syntax without building.
⚙️ Configuration
cobble.toml configures your project:
[]
= "my-datapack"
= "My awesome data pack"
= "my_namespace"
= "1.0.0"
= "101.1" # Minecraft Java Edition 26.1.2
[]
= "src" # Source directory
= "output" # Output directory
= [] # Main files to compile; imported files are pulled in by those entries
Supported Minecraft Version
| Minecraft Version | Pack Format |
|---|---|
| 26.1.2 | 101.1 (required) |
Note: Cobble v0.6.1 exclusively supports Minecraft Java Edition 26.1.2 (pack format 101.1). No backward compatibility with older versions is provided. This allows us to leverage the latest Minecraft features without worrying about legacy constraints.
📁 Project Structure
my-datapack/
├── cobble.toml # Configuration
├── src/
│ ├── main.cbl # Main entry point
│ ├── events.cbl # Event handlers
│ ├── functions.cbl # Utility functions
│ └── entities/
│ └── mobs.cbl # Mob-related functions
├── output/ # Generated data pack
│ ├── pack.mcmeta
│ └── data/
│ └── namespace/
│ ├── function/
│ └── tags/
└── my-datapack.zip # Distributable pack
🎮 Complete Example
Boss Fight System
src/boss.cbl:
# Global variables
= 100
= 1
"""Spawn the boss entity"""
/ : ~ ~1 ~
/ :
/ : @
/ : 200
/ : 200
/ :
"""Boss fight logic - runs every tick"""
global
# Update boss bar
/ : @
# Phase transitions
= 2
"""Boss enters rage mode"""
/ @
/ @ : 999999 1
/ @ : 999999 0
# Spawn minions
@:
/ : ~ ~ ~
"""Called when boss is defeated"""
/ :
/ @
/ @ :
@:
/ : ~ ~1 ~
# Register events
Parkour System
src/parkour.cbl:
"""Create a checkpoint at coordinates"""
/ :
/ : 0.5 1 0.5 0.01 20
"""Player reaches checkpoint"""
/ @ ~ ~ ~
/ : @
/ @
/ @
"""Teleport player to last checkpoint"""
/ @ @
/ @ : 3 255
🧪 Testing
Run the test suite:
Check syntax of example files:
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Development Setup
# Clone and setup
# Install development dependencies
# Run in watch mode
📚 Documentation
🐛 Known Limitations
- Variable Scope: All variables are effectively global due to Minecraft's scoreboard architecture. The
globalkeyword is accepted for code clarity but has no functional effect. Variables defined in one function can affect variables in another function if they share the same name. - For loops only support
range()iterators - Minecraft Java Edition 26.1.2 Required: Cobble exclusively supports Minecraft Java Edition 26.1.2 (pack format 101.1). Older versions are not supported.
- No array/list data structures yet
- While loops: Execute all iterations in a single game tick, which can cause server lag with large iteration counts (>100)
🗺️ Roadmap
Recently Completed
v0.6.1 (2026-06-02)
- Validation diagnostics - Macro commands are counted explicitly and invalid commands now include caret-position diagnostics when available
- Standard library v1.1 - Added objective, storage list/read, schedule, bossbar, team, and entity helper commands
- Namespaced resources -
datapack.*declarations can emit explicitnamespace:pathresources and reject non-object JSON resources where Minecraft expects objects - Project templates -
cobble init --template minimal|stdlib|validationcreates more targeted starter projects - Server QA workflow - Added
scripts/test_minecraft_server.shfor the ignored real-server integration test
v0.6.0 (2026-06-01)
- Build validation workflow -
cobble build --validateandcobble watch --validatevalidate generated.mcfunctionfiles against Minecraft Java Edition 26.1.2 commands - Standard library v1 - Added compiler-backed
text,score,random,timer,storage, and non-placeholdermath.sqrthelpers - Data pack JSON resources - Added
datapack.*helpers for tags, predicates, advancements, loot tables, recipes, item modifiers, and dialogs - Generated command source maps - Generated packs include
.cobble/source_map.jsonwith command text, generated location, source location when available, and command kind - Project stability - Circular imports now fail with import chains, missing imports include the importing file, and example projects are covered by build-and-validate fixtures
v0.5.18 (2025-10-21)
- Performance optimization - Removed unnecessary scoreboard objectives (multiplier, divisor, modulus, power_base, expr_temp) - now uses only temp objective with fake players
- Enhanced /say command - Scoreboard variables in /say commands are automatically converted to tellraw with proper score display components
- Cleaner datapacks - Generated packs now have fewer objectives in the objectives list, reducing clutter
v0.5.17 (2025-01-19)
- Return statement error handling - Return statements now produce clear compile-time errors instead of being silently ignored
- Function call assignment validation - Assignments like
x = helper()now error with helpful messages explaining Minecraft limitations - Enhanced expression errors - Attribute, subscript, and None assignments now have explicit error handling
- Comprehensive regression tests - Added 7 new tests to prevent these bugs from reoccurring (102 total tests)
v0.5.16 (2025-01-09)
- Critical bug fixes - Fixed three major issues that prevented proper Minecraft functionality
- Range syntax parsing - Fixed tokenizer to correctly parse Minecraft range syntax (
1..,..5,1..5) - Circular import detection - Restored proper circular dependency detection that was broken in v0.5.15
- Python expression translation - Execute blocks now properly translate Python expressions to Minecraft conditions
v0.5.6 (2025-10-04)
- Execute modifiers fix - All execute modifiers (positioned, in, rotated, etc.) now work as first modifier
- Unary operators - Negation (-x) and positive (+x) operators now work correctly
- Macro parameters in /say - Function parameters can be used in /say commands (e.g.,
/say Count: {counter}) - For loop macro support - Loop variables work in /say commands (e.g.,
/say Number {i}) - If condition fixes - Boolean literals (True/False) now generate correct execute conditions
- For loop error handling - Clear error messages for unsupported variable ranges instead of silent failure
v0.5.5 (2025-10-03)
- Inline comments - Support for # comments on same line as code
- Execute modifier improvements - Initial support for various execute modifiers
- Parser enhancements - Better error recovery and reporting
v0.5.0 (2025-10-03)
- Type System - Static, immutable type system with compile-time inference
- Type checking - Prevents accidental type changes (e.g., overwriting score with boolean)
- Match validation - Compile-time detection of overlapping case ranges
- Boolean initialization fix - Module-level boolean variables now properly initialized
- Numeric warnings - Float precision and overflow warnings at compile time
- Documentation updates - New Type System section in language reference
v0.4.3 (2025-10-03)
- Critical bug fix - Fixed execute block keyword capitalization (if/unless were incorrectly capitalized)
- Token Display trait fix - Added explicit lowercase mappings for all keywords
- Enhanced test coverage - 58 integration tests with regression tests for execute chains
- Documentation improvements - Added division by zero warnings and safe usage patterns
v0.4.2 (2025-10-03)
- Critical bug fixes - Fixed nested OR operators, NOT+OR combination, and match wildcard cases
- OR operator improvements - Recursive flattening for complex OR expressions
- Match wildcard fixes - Proper conditional execution for single and multi-statement wildcards
- Comprehensive testing - 58 integration tests, all passing
v0.4.1 (2025-10-03)
- Loop variable macro support - Use loop variables directly in commands (e.g.,
/say Count: {i}) - Loop body as macro functions - Loop bodies compile to macro functions for variable access
- Function call fix - Fixed parameterless function calls (no longer incorrectly use
with storage) - Parser improvements - Fixed
bykeyword recognition in for loops
v0.4.0 (2025-10-03)
- Entity Selector Definitions - Custom selector aliases (e.g.,
@Player = @a[type=player]) - File Import System - Import functions and definitions from other
.cblfiles - Circular dependency prevention - Automatic detection and prevention
- Relative import resolution - Import files relative to current file location
v0.3.0 (2025-10-03)
- Compile-time constants -
constkeyword for compile-time evaluation - Match/switch statements - Efficient multi-way branching
- Literal matching - Match exact values (e.g.,
case 5:) - Range matching - Match value ranges (e.g.,
case 1 to 10:) - Wildcard pattern - Default case with
case _: - 4-way split algorithm - Optimized branching implementation
v0.2.2 (2025-10-02)
- Critical bug fixes - If/elif/else inlining bug, while loop condition bug
- Automatic gamerule configuration -
maxCommandChainLengthset automatically - Module variable initialization order - Proper command ordering
v0.2.1 (2025-10-02)
- Complex expressions in conditions - Use arithmetic directly in if/while (e.g.,
if x % 3 == 1:) - Automatic temporary variables - Unique variables for each expression in conditions
- Nested expression support - Works with AND/OR operators
v0.2.0 (2025-10-02)
- Modulo operator (%) - Compute remainders (e.g.,
x % y) - Power operator (^) - Exponentiation with compile-time expansion (e.g.,
x ^ 2) - OR operator - Boolean OR in conditions (e.g.,
if x == 5 or y == 10:) - For loop step support - Control increment/decrement (e.g.,
for i in range(10) by 2:) - Java Edition compatibility - Fixed negative loop steps
v0.1.1 (2025-10-02)
- Parenthesized expressions - Support for
(a + b) * cstyle expressions - Self-assignment optimization - Removed unnecessary operations
v0.1.0 (Pre-release)
- elif and else branch support
- Scoreboard objectives auto-generation
- User function calls
- Multi-operator expressions - Chained operations like
a + b + c - Operator precedence - Proper math order (
*//before+/-) - Complex nested expressions - Full arithmetic expression support
- Module-level variable initialization - Top-level vars auto-initialized
- Loop variable arithmetic fix - Correct objective tracking in loops
- Variable division - Full division operation support
- CLI watch enhancements - All build options available in watch mode
- Boolean operators -
and,notoperators in conditions - chumsky parser integration
- Improved error messages with ariadne
- as/at/asat/if execute support
- global keyword
- Comprehensive test suite (58 integration tests)
Near Term
- Template functions - Parameterized code generation (e.g.,
def summon[entity]: /summon {entity} ~ ~ ~) - Array and list data structures
- More built-in functions (math, strings)
- Enhanced loop optimizations
Medium Term
- Class and object support for entities
- NBT data manipulation
- Custom advancement generation
- Recipe generation
- Loot table generation
- Predicate support
Long Term
- Resource pack integration
- VS Code extension with syntax highlighting
- Language server protocol (LSP) support
- Online playground/REPL
- Standard library expansion
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Minecraft command system documentation
- Rust community for excellent libraries:
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with ❤️ for the Minecraft community