Git Product home page Git Product logo

acaciamc's Introduction

Acacia

English | δΈ­ζ–‡

Introduction

Acacia is a programming language for Minecraft Bedrock Edition command development. Our principle is to be as simple as possible. Minecraft commands can be complicated, long and hard to maintain. Acacia simplify commands into Python-like code. Acacia code is finally compiled into .mcfunction files, and can be loaded in a Minecraft world as a datapack.

Acacia is written in Python (require 3.3 or newer), so it's easy to create a binary module using Python for Acacia code to use.

Go to this test file for an overview of Acacia.

Simple Syntax

Defining variables in Acacia: a = 1. That's it. No need for scoreboards.

Nested expression within 1 line of code:

a = 10
# `10 + 20` is folded into `30`
b = (10 + 20) * a - 5

Function definition:

def foo(x: int, y = True) -> int:
    pass # code here...
# These are all OK:
foo(1)
z = foo(2, False)
z = foo(x=3)

Flow Control Statement:

def is_prime(x: int) -> bool:
    # Test if `x` is a prime number
    mod = 2
    result True
    while mod <= x / 2:
        if x % mod == 0:
            result False
        mod += 1

Builtin modules:

import print
money = 10
# Send "Hello, world!" in char to everyone
print.tell("Hello world!")
# Show "Money: (Value of variable `money`)" on actionbar to everyone
print.title(print.format("Money: %0", money), mode=print.ACTIONBAR)

Compatible with Commands

Acacia supports commands inserted in code:

a = 1
/tp @p 11 45 14
/*
    tellraw @a {
    ...
    }
*/ # Multi-line command!

It can even simplify commands:

player -> "@p[tag=player]" # defining macro
/tp ${player} 11 45 14
/execute at ${player} run setblock ~ ~ ~ grass

Accessing scores on scoreboard: |"player": "scoreboard"| = 10

Optimized Output

Acacia can even do better than you in some aspects like doing math!

def sum_between(start: int, to: int, delta=1) -> int:
    #* Return sum of Equidistant sequence from `start` to `to` with `delta` *#
    result (start + to) * ((to - start) / delta + 1) / 2
sum_between(-5, 5, delta=2)

These commands are generated for function sum_between:

# On initial run
scoreboard players set "acacia5" "acacia" 2
# "acacia1", "acacia2" and "acacia3" are the arguments
scoreboard players operation "acacia6" "acacia" = "acacia2" "acacia"
scoreboard players operation "acacia6" "acacia" -= "acacia1" "acacia"
scoreboard players operation "acacia6" "acacia" /= "acacia3" "acacia"
scoreboard players add "acacia6" "acacia" 1
scoreboard players operation "acacia4" "acacia" = "acacia1" "acacia"
scoreboard players operation "acacia4" "acacia" += "acacia2" "acacia"
scoreboard players operation "acacia4" "acacia" *= "acacia6" "acacia"
scoreboard players operation "acacia4" "acacia" /= "acacia5" "acacia"

The order of the operations are well-organized by Acacia compiler.

Discover More about Acacia

acaciamc's People

Contributors

cberjun avatar

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.