Skip to content
MinecraftFunctionPlusPlusPublic

About

MCFPP is a brand new objected-oriented language that can be compiled into Minecraft Datapack.

Topics

Resources

Stars

283 stars

Watchers

8 watching

Forks

Repository files navigation

Introduction

MCFPP is a new object-oriented language that compiles into Minecraft data packs. It aims to simplify data pack creation with syntax similar to C-based languages, incorporating common programming concepts for convenience.

Note: This project is in early development. Features may change, and library functions are incomplete.

Quick Start

See the project and CLI guide. Use mcfpp init hello and mcfpp build, or mcfpp init hello --mni for Java MNI and tests. Projects use mcfpp.toml and mcfpp-packages.json.

MCFPP API

Build with JDK 21 using ./gradlew build (./gradlew.bat build on Windows).

Type system specification · Migration status and guide

ScoreRef / NBTRef usage and migration: save and pass explicit Minecraft addresses, read with synchronous tryRead, and write with set.

  • Code optimization
  • Basic library

Related Projects

MCSharp is a CSharp library for data pack development, now discontinued due to technical issues. MCFPP inherits some of its ideas.

JustMCF simplifies mcfunction projects, allowing both original and streamlined commands for efficiency.

Features

Basic Logic Statements

func example(){
  external i: int = 1
  if(i > 0){
    execute(as = @s) {
      /say Hello Minecraft!
    }
  }
}

Object-Oriented Programming

data Example{
  var i: int {
    get {
      return field * 2
    }
    set {
      field = value
    }
  }

  constructor(i: int){
    this.i = i
  }

  func print(){
    print(this.i)
  }
}

Library Calls

import mcfpp.lang:*

func example(){
    var i: float = 1.5
    var out: int
    out = toInt(i)
    print(out)
}

Generics

<T> declares a readonly type parameter; explicit <T: type> is also supported. Readonly value parameters use <N: int>. Ordinary values cannot have type type; var t: type = int is invalid.

data Example<T>{
  var i: T

  constructor(i: T){
    this.i = i
  }

  public func print(){
    print(this.i)
  }
}

func test<T>(i: T){
    print(i)
}

Direct Use of Minecraft Commands

var qwq = "Minecraft"

func test(){
  /execute as @a run say Hello ${qwq}!
}

Functions, comments, and fields

Variables, named parameters, and fields use : for type annotations, such as var x: int. Declare const x = 1 and external x: int = 1 directly, without var; variable imports retain import var. Function return types use :. Ordinary comments start with //; documentation comments start with /// and contain Markdown. Consecutive documentation lines form one block. A single space after /// is a separator; further indentation and Markdown markers are preserved. Fields in data, object data, and anonymous data bodies use var or const.

/// # Counter
/// Stores the current count, with **bold** and `code` documentation.
data Counter {
  // Fields use var or const
  var value: int = 0
  func read(): int { return this.value }
}

Declare shared contracts with abstract data Name and bodyless methods with abstract func read(): int;. Concrete children must implement inherited abstract methods. The interface and data abstract declarations have been removed. Replace the dynamic variable keyword with external, which still requires runtime storage.

The old -> return marker and #, ##, #{…}#, and ### comments are no longer accepted. Version directives #if/#elif/#else/#endif retain their syntax.

Line breaks and arithmetic expressions

Newlines or semicolons separate statements; the final statement before } needs no semicolon. Keep semicolons between same-line statements and in SNBT arrays. Parentheses are optional around if, else if, while, and do ... while conditions, which must have type bool. An expression can continue on the next line when its operator ends the current line. A line starting with a single / after optional whitespace is a vanilla Minecraft command; put a division operator on the previous line when splitting division across lines.

func calculate(){
  var x = 12 /
    3
  x += 2
  x *= 3
  var opposite = -x
  /say Calculation complete
}

Compound assignments +=, -=, *=, /=, and %= read the target, apply the corresponding operation, and write the result back. ++ and -- are not supported.

Compile for a Minecraft version

Set the target version in mcfpp.toml, for example version = "26.3". Each build produces one data pack for that target; change version and build again for another version. Targets 26.1, 26.2, 26.3, and the previously supported older versions are available.

Targeting 26.3 automatically uses native number providers and NBT floats for float arithmetic, comparisons, compound assignments, and integer conversions. Earlier targets keep XiaoDouMathLib. See the 26.3 float backend notes for the implementation and storage migration details.

#if MC >= 26.1
func greet(){
  /say 26.1 or newer
}
#elif MC >= 1.21.6
func greet(){
  /say 1.21.6 to 1.21.8
}
#else
func greet(){
  /say older version
}
#endif

Directives may be nested and can surround imports, declarations, or function statements. A condition compares MC with a version using ==, !=, <, <=, >, or >=; logical combinations are not supported. Versions are compared component by component. Spell older versions in full, such as 1.21.6, rather than 21.6. Ordinary comments use //.

For more syntax information, refer to the MCFPP API.

About

MCFPP is a brand new objected-oriented language that can be compiled into Minecraft Datapack.

Topics

Resources

Stars

283 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages