Skip to content

Samma2009/MobCodeCompiler

Repository files navigation

MobCode Compiler

The MobCode Compiler is a tool designed to compile custom scripting language into Minecraft function files. It supports namespaces, classes, functions, and macros for efficient and modular scripting.

Features

  • Namespaces: Organize your code into logical groups.
  • Classes: Encapsulate related functions and commands.
  • Functions: Define reusable blocks of commands.
  • Macros: Simplify repetitive tasks with parameterized templates.
  • Real-time Watching: Automatically rebuilds files on changes.
  • Conditional Logic: Use if statements for dynamic behavior.
  • Loops: Repeat commands with times.

Dependencies

Installation

  1. Clone the repository or download the source code.
  2. Ensure you have the required dependencies installed.
  3. Build the project using .NET 9.0 or higher.

Usage

Run the compiler with the following commands:

Build

Compile all .mc files in the current directory:

MobCode.exe build

Watch

Automatically rebuild files when changes are detected:

MobCode.exe watch

Install Macros

Download and install macros from a list of URLs:

MobCode.exe install <url1> <url2> ...

Language Features

Namespaces

Group related functions and classes:

namespace myNamespace {
    function myFunction {
        say Hello, World!;
    }
}

Classes

Encapsulate related functions:

namespace myNamespace {
    class myClass {
        function myFunction {
            say This is a class function!;
        }
    }
}

Functions

Define reusable blocks of commands:

namespace myNamespace {
    function greet {
        say Hello, Player!;
    }
}

Macros

Use macros to simplify repetitive tasks:

namespace myNamespace {
    function giveItem {
        Item.Give(@p, diamond_sword, 1, {});
    }
}

Conditional Logic

Execute commands conditionally:

namespace myNamespace {
    function checkCondition {
        if (1 == 1) {
            say Condition is true!;
        }
    }
}

Loops

Repeat commands a specified number of times:

namespace myNamespace {
    function repeatExample {
        times (5) {
            say This will repeat 5 times!;
        }
    }
}

Example

Here is a complete example:

namespace example {
    function main {
        say Starting script...;
        if (2 > 1) {
            say Condition met!;
        }
        times (3) {
            say Repeating this message!;
        }
        Item.Give(@p, diamond, 1, {});
    }
}

Generated Output

The above example will generate a .mcfunction file with the following content:

say Starting script...
say Condition met!
say Repeating this message!
say Repeating this message!
say Repeating this message!
give @p diamond 1

Generated by artificial intelligence

Packages

No packages published

Languages