acaciamc


Nameacaciamc JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryCompiler of Acacia, a programming language for Minecraft BE.
upload_time2024-08-26 10:46:31
maintainerNone
docs_urlNone
authorCBerJun
requires_python>=3.6.1
licenseMIT License Copyright (c) 2022 CBerJun Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords acacia minecraft mcfunction
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Acacia
English | [中文](README_cn.md)

## Introduction
**Acacia is a programming language that runs in Minecraft Bedrock Edition.**
Minecraft commands can be complicated, long and hard to maintain.
Acacia is an alternative to commands -- it is also used to control Minecraft.
*However*, Acacia code is much more readable than commands, which increases the maintainability of your project and your productivity.
**Imagine writing a Tetris game that runs in Minecraft using less than 14KB code** (see [below](#what-can-acacia-do))!

Acacia code is finally compiled into `.mcfunction` files.
In other word, Acacia code will be converted into Minecraft commands by the program, and can be loaded in a Minecraft world as a behavior pack.

Still confused? Here's a simple Acacia program that calculates sum of elements in an arithmetic sequence in Minecraft:
```
import print
def arithmetic(start: int, to: int, delta=1) -> int:
    #*
     * Return sum of arithmetic sequence that starts with `start`,
     * ends with `to` with common difference `delta`.
     *#
    result (start + to) * ((to - start) / delta + 1) / 2
res := arithmetic(-30, 14, delta=2)
print.tell(print.format("Sum of arithmetic sequence (-30~14, d=2) is %0", res))
```
Acacia will convert the above code into commands:
```mcfunction
# These efficient commands are AUTO-GENERATED! Isn't that cool?
scoreboard players set acacia1 acacia -30
scoreboard players set acacia2 acacia 14
scoreboard players set acacia3 acacia 2
scoreboard players operation acacia4 acacia = acacia1 acacia
scoreboard players operation acacia4 acacia += acacia2 acacia
scoreboard players operation acacia5 acacia = acacia2 acacia
scoreboard players operation acacia5 acacia -= acacia1 acacia
scoreboard players operation acacia5 acacia /= acacia3 acacia
scoreboard players add acacia5 acacia 1
scoreboard players operation acacia4 acacia *= acacia5 acacia
scoreboard players operation acacia4 acacia /= acacia6 acacia
scoreboard players operation acacia7 acacia = acacia4 acacia
tellraw @a {"rawtext": [{"text": "Sum of arithmetic sequence (-30~14, d=2) is "}, {"score": {"objective": "acacia", "name": "acacia7"}}]}
```
```mcfunction
# Initialization: add scoreboard and set constants.
scoreboard objectives add acacia dummy
scoreboard players set acacia6 acacia 2
```
Running these generated commands will send this message in Minecraft's chat:
> Sum of arithmetic sequence (-30~14, d=2) is -184

**In conclusion, by using Acacia you can create Minecraft projects -- not by writing commands, but by writing Acacia code, which is much more easier to maintain and understand.**

Acacia is written in Python, so Python (3.6.1 or newer) is required by compiler (i.e. the program that converts your code into commands).

## What can Acacia do?
Some real-world examples:
- **Without writing 1 command**, we can create a simple Tetris game in Minecraft!
  The source code can be found [here](test/demo/tetris.aca).
  It is only 14KB in size! The generated commands, however, use about 280KB and 50 files.
- Still without 1 command, a random Minecraft maze generator can be made using 3.5KB code
  (with comment that explains the algorithm removed). See [source code](test/demo/maze.aca).
- Noteblock musics can be automatically generated by the builtin module `music`.

Detailed features:
- No more redundant commands and huge amount of files; Acacia code is simple.
- No more worries about `/execute` context.
- No more entity tags; Acacia has an exclusive entity system!
- No more scoreboards! Instead we have the variable system which is popular in computer programming.
- No more repetitive commands; Acacia is good at generating repetitive commands.
- You can define loops and use the "if" statement to run something conditionally.
- Acacia provides various compile-time constants, including numbers, strings, lists, maps and even world positions.
  This makes your map or addon more flexible.

Check out [this file](test/brief.aca) for more information about Acacia's syntax.

## Syntax Overview
This is how to define a variable in Acacia: `a := 1`. That's it.
No need for scoreboards.

Nested expressions within 1 line of code:
```python
a := 10
b := (10 + a) * a - 5
```

Function definitions:
```python
def foo(x: int, y = True) -> int:
    # Here is function body code
    res := x
    if y:
        res += 10
    result res  # return value
z: int
# These are all valid:
foo(1)
z = foo(2, False)
z = foo(x=3)
```

Flow control statements (selections and loops):
```python
def is_prime(x: int) -> bool:
    #* Test if `x` is a prime number *#
    res := True
    mod: int = 2
    while mod <= x / 2:
        if x % mod == 0:
            res = False
        mod += 1
    result res
```

Various builtin modules:
```python
import print
money := 10
# Send "Hello, world!" in chat 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)
```
```python
import music
# Generate a noteblock music and use 1.2x speed.
const m = music.Music("music_score.mid", speed=1.2)
m.play()
```

Use of constants and `for` to avoid repetitive code:
```python
import world

# Place concretes of different colors according to value of an variable
const COLORS = {
    0: "cyan", 1: "orange", 2: "yellow",
    3: "purple", 4: "lime", 5: "red", 6: "blue"
}
i := 0  # Calculate `i`...
for c in COLORS:
    # `for` instructs the compiler to generate the following code
    # repetitively for you!
    if c == i:
        world.setblock(
            Pos(0, -50, 0),
            world.Block("concrete", {"color": COLORS[c]})
        )
```

Position and entity system:
```python
import world

const ORIGIN = AbsPos(0, -50, 0)
world.fill(ORIGIN, Offset(x=5, z=5),
           world.Block("concrete", {"color": "red"}))

entity Test:
    new():
        new(type="armor_stand", pos=ORIGIN)
        world.setblock(Pos(self), "diamond_block")
        world.effect_give(self, "invisibility", duration=1000)

    def foo():
        world.tp(self, ORIGIN)

test_group := Engroup[Test]()
instance := Test()
test_group.add(instance)
test_group.select(Enfilter().distance_from(ORIGIN, max=5))
for test in test_group:
    test.foo()
```

## Discover More about Acacia
- [An introduction video in Chinese](https://www.bilibili.com/video/BV1uR4y167w9)
- [Use Acacia to generate noteblock musics](https://www.bilibili.com/video/BV1f24y1L7DB)
- Go to [this test file](test/brief.aca) for more details about Acacia!
- A simple Guess the Number game written in Acacia can also be found [here](test/demo/numguess.aca)!

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "acaciamc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6.1",
    "maintainer_email": null,
    "keywords": "acacia, minecraft, mcfunction",
    "author": "CBerJun",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/27/b4/873070f1b112a06c67eb1fdf6370f19198dfefe3f05350bc5067fad9bf1e/acaciamc-0.1.0.tar.gz",
    "platform": null,
    "description": "# Acacia\r\nEnglish | [\u4e2d\u6587](README_cn.md)\r\n\r\n## Introduction\r\n**Acacia is a programming language that runs in Minecraft Bedrock Edition.**\r\nMinecraft commands can be complicated, long and hard to maintain.\r\nAcacia is an alternative to commands -- it is also used to control Minecraft.\r\n*However*, Acacia code is much more readable than commands, which increases the maintainability of your project and your productivity.\r\n**Imagine writing a Tetris game that runs in Minecraft using less than 14KB code** (see [below](#what-can-acacia-do))!\r\n\r\nAcacia code is finally compiled into `.mcfunction` files.\r\nIn other word, Acacia code will be converted into Minecraft commands by the program, and can be loaded in a Minecraft world as a behavior pack.\r\n\r\nStill confused? Here's a simple Acacia program that calculates sum of elements in an arithmetic sequence in Minecraft:\r\n```\r\nimport print\r\ndef arithmetic(start: int, to: int, delta=1) -> int:\r\n    #*\r\n     * Return sum of arithmetic sequence that starts with `start`,\r\n     * ends with `to` with common difference `delta`.\r\n     *#\r\n    result (start + to) * ((to - start) / delta + 1) / 2\r\nres := arithmetic(-30, 14, delta=2)\r\nprint.tell(print.format(\"Sum of arithmetic sequence (-30~14, d=2) is %0\", res))\r\n```\r\nAcacia will convert the above code into commands:\r\n```mcfunction\r\n# These efficient commands are AUTO-GENERATED! Isn't that cool?\r\nscoreboard players set acacia1 acacia -30\r\nscoreboard players set acacia2 acacia 14\r\nscoreboard players set acacia3 acacia 2\r\nscoreboard players operation acacia4 acacia = acacia1 acacia\r\nscoreboard players operation acacia4 acacia += acacia2 acacia\r\nscoreboard players operation acacia5 acacia = acacia2 acacia\r\nscoreboard players operation acacia5 acacia -= acacia1 acacia\r\nscoreboard players operation acacia5 acacia /= acacia3 acacia\r\nscoreboard players add acacia5 acacia 1\r\nscoreboard players operation acacia4 acacia *= acacia5 acacia\r\nscoreboard players operation acacia4 acacia /= acacia6 acacia\r\nscoreboard players operation acacia7 acacia = acacia4 acacia\r\ntellraw @a {\"rawtext\": [{\"text\": \"Sum of arithmetic sequence (-30~14, d=2) is \"}, {\"score\": {\"objective\": \"acacia\", \"name\": \"acacia7\"}}]}\r\n```\r\n```mcfunction\r\n# Initialization: add scoreboard and set constants.\r\nscoreboard objectives add acacia dummy\r\nscoreboard players set acacia6 acacia 2\r\n```\r\nRunning these generated commands will send this message in Minecraft's chat:\r\n> Sum of arithmetic sequence (-30~14, d=2) is -184\r\n\r\n**In conclusion, by using Acacia you can create Minecraft projects -- not by writing commands, but by writing Acacia code, which is much more easier to maintain and understand.**\r\n\r\nAcacia is written in Python, so Python (3.6.1 or newer) is required by compiler (i.e. the program that converts your code into commands).\r\n\r\n## What can Acacia do?\r\nSome real-world examples:\r\n- **Without writing 1 command**, we can create a simple Tetris game in Minecraft!\r\n  The source code can be found [here](test/demo/tetris.aca).\r\n  It is only 14KB in size! The generated commands, however, use about 280KB and 50 files.\r\n- Still without 1 command, a random Minecraft maze generator can be made using 3.5KB code\r\n  (with comment that explains the algorithm removed). See [source code](test/demo/maze.aca).\r\n- Noteblock musics can be automatically generated by the builtin module `music`.\r\n\r\nDetailed features:\r\n- No more redundant commands and huge amount of files; Acacia code is simple.\r\n- No more worries about `/execute` context.\r\n- No more entity tags; Acacia has an exclusive entity system!\r\n- No more scoreboards! Instead we have the variable system which is popular in computer programming.\r\n- No more repetitive commands; Acacia is good at generating repetitive commands.\r\n- You can define loops and use the \"if\" statement to run something conditionally.\r\n- Acacia provides various compile-time constants, including numbers, strings, lists, maps and even world positions.\r\n  This makes your map or addon more flexible.\r\n\r\nCheck out [this file](test/brief.aca) for more information about Acacia's syntax.\r\n\r\n## Syntax Overview\r\nThis is how to define a variable in Acacia: `a := 1`. That's it.\r\nNo need for scoreboards.\r\n\r\nNested expressions within 1 line of code:\r\n```python\r\na := 10\r\nb := (10 + a) * a - 5\r\n```\r\n\r\nFunction definitions:\r\n```python\r\ndef foo(x: int, y = True) -> int:\r\n    # Here is function body code\r\n    res := x\r\n    if y:\r\n        res += 10\r\n    result res  # return value\r\nz: int\r\n# These are all valid:\r\nfoo(1)\r\nz = foo(2, False)\r\nz = foo(x=3)\r\n```\r\n\r\nFlow control statements (selections and loops):\r\n```python\r\ndef is_prime(x: int) -> bool:\r\n    #* Test if `x` is a prime number *#\r\n    res := True\r\n    mod: int = 2\r\n    while mod <= x / 2:\r\n        if x % mod == 0:\r\n            res = False\r\n        mod += 1\r\n    result res\r\n```\r\n\r\nVarious builtin modules:\r\n```python\r\nimport print\r\nmoney := 10\r\n# Send \"Hello, world!\" in chat to everyone\r\nprint.tell(\"Hello world!\")\r\n# Show \"Money: (Value of variable `money`)\" on actionbar to everyone\r\nprint.title(print.format(\"Money: %0\", money), mode=print.ACTIONBAR)\r\n```\r\n```python\r\nimport music\r\n# Generate a noteblock music and use 1.2x speed.\r\nconst m = music.Music(\"music_score.mid\", speed=1.2)\r\nm.play()\r\n```\r\n\r\nUse of constants and `for` to avoid repetitive code:\r\n```python\r\nimport world\r\n\r\n# Place concretes of different colors according to value of an variable\r\nconst COLORS = {\r\n    0: \"cyan\", 1: \"orange\", 2: \"yellow\",\r\n    3: \"purple\", 4: \"lime\", 5: \"red\", 6: \"blue\"\r\n}\r\ni := 0  # Calculate `i`...\r\nfor c in COLORS:\r\n    # `for` instructs the compiler to generate the following code\r\n    # repetitively for you!\r\n    if c == i:\r\n        world.setblock(\r\n            Pos(0, -50, 0),\r\n            world.Block(\"concrete\", {\"color\": COLORS[c]})\r\n        )\r\n```\r\n\r\nPosition and entity system:\r\n```python\r\nimport world\r\n\r\nconst ORIGIN = AbsPos(0, -50, 0)\r\nworld.fill(ORIGIN, Offset(x=5, z=5),\r\n           world.Block(\"concrete\", {\"color\": \"red\"}))\r\n\r\nentity Test:\r\n    new():\r\n        new(type=\"armor_stand\", pos=ORIGIN)\r\n        world.setblock(Pos(self), \"diamond_block\")\r\n        world.effect_give(self, \"invisibility\", duration=1000)\r\n\r\n    def foo():\r\n        world.tp(self, ORIGIN)\r\n\r\ntest_group := Engroup[Test]()\r\ninstance := Test()\r\ntest_group.add(instance)\r\ntest_group.select(Enfilter().distance_from(ORIGIN, max=5))\r\nfor test in test_group:\r\n    test.foo()\r\n```\r\n\r\n## Discover More about Acacia\r\n- [An introduction video in Chinese](https://www.bilibili.com/video/BV1uR4y167w9)\r\n- [Use Acacia to generate noteblock musics](https://www.bilibili.com/video/BV1f24y1L7DB)\r\n- Go to [this test file](test/brief.aca) for more details about Acacia!\r\n- A simple Guess the Number game written in Acacia can also be found [here](test/demo/numguess.aca)!\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2022 CBerJun  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Compiler of Acacia, a programming language for Minecraft BE.",
    "version": "0.1.0",
    "project_urls": {
        "Repository": "https://github.com/CBerJun/AcaciaMC"
    },
    "split_keywords": [
        "acacia",
        " minecraft",
        " mcfunction"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ebffc09f01c308af8bdf44b30f2c541b76319716dcde18a7f32ba1c6e36a158",
                "md5": "fa921645048888220f1895cdb2e7dfde",
                "sha256": "d2dfde89d70667d55e62d5f1ce948e58171e0de5d8eeee59c5bddb93d9de0d56"
            },
            "downloads": -1,
            "filename": "acaciamc-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fa921645048888220f1895cdb2e7dfde",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.1",
            "size": 157236,
            "upload_time": "2024-08-26T10:46:30",
            "upload_time_iso_8601": "2024-08-26T10:46:30.337463Z",
            "url": "https://files.pythonhosted.org/packages/8e/bf/fc09f01c308af8bdf44b30f2c541b76319716dcde18a7f32ba1c6e36a158/acaciamc-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27b4873070f1b112a06c67eb1fdf6370f19198dfefe3f05350bc5067fad9bf1e",
                "md5": "83673edaeb5e6298dc690178f474265f",
                "sha256": "8b18b05e122212187d29ebefb7b12993fe7c3628488340cbe722df4ca947c1d0"
            },
            "downloads": -1,
            "filename": "acaciamc-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "83673edaeb5e6298dc690178f474265f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.1",
            "size": 138043,
            "upload_time": "2024-08-26T10:46:31",
            "upload_time_iso_8601": "2024-08-26T10:46:31.911919Z",
            "url": "https://files.pythonhosted.org/packages/27/b4/873070f1b112a06c67eb1fdf6370f19198dfefe3f05350bc5067fad9bf1e/acaciamc-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-26 10:46:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CBerJun",
    "github_project": "AcaciaMC",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "acaciamc"
}
        
Elapsed time: 0.49688s