Giter VIP home page Giter VIP logo

mcpy's Introduction

mcpy

A library for writing Minecraft datapacks using the Python language. See the mcpy Docs for details.

from mcpy import *

@datapack
def simple_pack():
    with namespace("mypack"):
        @mcfunction()
        def greet():
            yield "say Hello!"

        @mcfunction()
        def tick():
            # count down messages
            for i in range(3):
                yield f"say {i+1}.."
            # call greeting message
            greet()
> python -m mcpy build
# Outputs the data dir:
# my-pack
# ├── data
# │   └── mypack
# │       ├── greet.mcfunction
# │       └── tick.mcfunction

Table of Contents

Motivation

The mcfunction language is very limited and requires repetition and tedium for more complex tasks. There have been numerous attempts at extending it with custom languages and parsers but these have their own issues and create additional layers of complexity.

Advantages:

  • Powerful - can utilize the full Python language and package ecosystem
  • Extensible - With plain Python features (e.g. functions, vars, packages, etc) the language is easy to onto. (See Plugin examples)
  • Minimal boilerplate - Not much overhead to write or think about when using Python syntax compared to other languages

Disadvantages:

  • Syntax highlighting - Ability to use mcfunction syntax highlighting (such as with VSCode extensions) is lost since the commands are in .py files and strs. Though this could likely be worked around with a custom VSCode extension using embedded languages.

Installation

  1. Install the repository as a Python package

    > python -m pip install git+https://github.com/dthigpen/mcpy

Usage

See the Get Started Guide

Examples

Full examples can be found in the examples directory of this repository.

mcpy's People

Contributors

dthigpen avatar

Watchers

 avatar

mcpy's Issues

Cannot recursively call functions

The following error is received when a function is attempted to be called within itself.
NameError: free variable 'function_name' referenced before assignment in enclosing scope
Could be mitigated by a get_self() function that returns the correct resource type.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.