Giter Club home page Giter Club logo

command-block-assembly's Introduction

Command Block Assembly

Command Block Assembly started off as a tool that compiled assembly instructions into Minecraft commands.

It has now grown into a much larger suite of tools for compiling source code into Minecraft commands, therefore the toolchain as a whole is known as the Minecraft Compiler Collection (MCC).

Minecraft Compiler Collection

The Minecraft Compiler Collection (MCC) is an umbrella tool composed of multiple compilers in a toolchain to compile high level code into Minecraft commands. It shares some similarities with the GNU Compiler Collection.

MCC is composed of the following components:

CBL Compiler

Command Block Language (CBL) is a C++ inspired programming language specifically designed for Minecraft commands.

CBL has been designed to abstract away from commands to the point where you don't need to consider the underlying mechanics.

The syntax is similar to C++ in a lot of ways. It also takes from Java's idea of having no pointers in the language.

Example

include "Text"

type point {
    int x;
    int y;

    constructor(int x, int y) {
        this.x = x;
        this.y = y;
    }

    inline point operator +(point other) {
        return point(this.x + other.x, this.y + other.y);
    }

    inline point operator *(int val) {
        return point(this.x * val, this.y * val);
    }

    inline void print();
}

inline void point::print() {
    Text output;
    output += "(";
    output.append_ref(this.x);
    output += ", ";
    output.append_ref(this.y);
    output += ")";
    output.send_to_all();
}

void main() {
    point p1(2, 4);
    point p2(5, 9);
    p1 += p2;
    p1 *= 2;
    p1.print();
}

This example demonstrates several language features of CBL, some of which should be familiar to C++ programmers.

Because everything in this example can be determined statically (at compile time), the output is just:

tellraw @a [{"text":"("},{"text":"14"},{"text":", "},{"text":"26"},{"text":")"}]

Documentation

See the CBL Wiki for more details on the CBL language.

Assembler

The assembler in MCC is the original assembler when this project was just Command Block Assembly.

Assembly Language

The assembly language is simple and has instructions similar to x86.

The language looks like the following:

#include foo.asm

; Useful comment

.my_const #1 ; A constant value
.my_ref my_const ; A constant reference

main:
    MOV #0x01, 0 ; Do the thing
    _loop: ADD my_const, 0
    JMP _loop

Example

The first example code written for CBA was an assembly program that prints the fibinacci sequence until the next value overflows:

.x 0x00
.y 0x01
.old_x 0x02
.counter 0x03

main:
    MOV #0, x
    MOV #1, y
    MOV #1, counter
    _loop:
    PRINT "fib(", counter, ") = ", x
    SYNC
    ADD #1, counter
    MOV x, old_x
    MOV y, x
    ADD old_x, y
    CMP #0, x
    JGE _loop ; if not >=0 then x has overflowed

Documentation

The instruction set and how write CBA programs is documented on the wiki.

C Compiler

MCC partially implements a C compiler, most language features are implemented and it includes a preprocessor.

The C compiler sits on top of the assembler - all C code is compiled into assembly which is then passed through MCC's assembler.

Example

Here is the same fibinacci sequence program but implemented in C:

#include <stdio.h>

int x;
int y;
int old_x;
int counter;

void main() {
    x = 0;
    y = 1;
    counter = 1;
    do {
        printf("fib(%d) = %d", counter++, x);
        sync;
        old_x = x;
        x = y;
        y += old_x;
    } while(x >= 0);
}

Documentation

The C compiler tries to stay as close as possible to the real C language, so documentation for most language features can be found elsewhere.

There is only one built-in type, int. Fundamentally, all data is stored in a scoreboard objective which is a 32 bit signed integer.

The mclib.h file contains several useful macros and definitions.

Browse the code in the examples directory to see working examples of C code.

Command IR Compiler

Command IR is the intermediate representation used by MCC. All compilers above ultimately generate Command IR code.

It is designed to relate closely to Minecraft commands themselves but provide a level of abstraction and context which enables optimizations among other things.

Command IR supports linking, which means it's possible to write code in CBL, C, ASM and IR directly and compile them together into one program.

Example

Here is a hello world program:

function hello {
    preamble {
        $all_players = selector a
        $message = text
        extern
    }

    compiletime {
        entry:
        text_append $message, "Hello, "
        text_append $message, "World!"
    }

    begin:
    text_send $message, $all_players
    ret
}

The output is a file hello.mcfunction:

tellraw @a [{"text":"Hello, "},{"text":"World!"}]

Documentation

Command IR's syntax, instruction reference and internal working is documented on the wiki.

Datapack Packer

Finally, to bring everything together and generate a datapack, MCC reads a "Datapack Definition" file which declares how to package the code into a datapack.

The file is a simple INI file declaring attributes such as the namespace.

To complete the fibinacci example, the datapack definition file fib.dpd is:

[Datapack]
namespace=fib
place location=0 56 0
description = An example datapack that prints the fibonacci sequence

Documentation

Currently there is only one section in a DPD file, the Datapack section.

In order to create a datapack, two values are required: the namespace and the place location

Option Description
namespace The namespace used for functions in the datapack
place location An absolute position in the world to place the utility command block. Specifiy as 3 space-separated numbers
spawn location A position in the world to spawn the global armorstand. Specifiy as 3 space-separated components. Relative positioning (~) is allowed
description Set the description of the datapack
generate cleanup Generate a function which will remove everything created by the datapack

MCC pipeline

There are 3 main stages to the compiler pipeline:

  1. Compiling: Converts source code into Command IR
  2. Linking: Merges one or more Command IR files into one master file
  3. Packing: Converts Command IR into Minecraft commands and creates a datapack from a datapack definition file

The MCC command takes a list of files, each code file goes through some number of transformations to end up as a Command IR object.

The linker merges each Command IR object into a single Command IR object. Any conflicts when merging will abort the compiler.

A datapack definition file is required for the packer. The packer takes the single Command IR object and generates the final mcfunction files.

To get an idea of the hierarchy of components, here is a diagram:

            +---------------+
            |               |
            |  C Compiler   |
            |               |
+-----------+---------------+
|           |               |
|    CBL    |   Assembler   |
|           |               |
+-----------+---------------+
|                           |
|        Command IR         |
|                           |
+---------------------------+----+
|                                |
|      Command Abstraction       |       +--------------+
+--------------------------------+-------|   Datapack   |
|          Minecraft Commands            |  Definition  |
+----------------------------------------+--------------+
|                           Datapack                    |
+-------------------------------------------------------+

Running MCC

You will need to generate the standalone parsers (from Lark) using the ./build-parsers.sh script. If on Windows, run the python commands in that script from the root of this project.

The Lark python package needs to be installed, pip can be used on the requirements.txt file. It is recommended to use virtualenv.

Example: virtualenv env --python=python3 && source env/bin/activate && pip install -r requirements.txt Once the parsers have been built, you don't technically need the virtual environment anymore. It can be deleted with deactivate && rm -rf env/

Alternatively, you don't need to create the standalone parsers if you keep Lark available in the python environment.

MCC is implemented in python. Currently it is not bundled into an executable so it must be invoked using the python interpreter.

MCC is invoked by python mcc.py (If python 3 is not your default python command then run python3 mcc.py).

Command help text:

usage: mcc.py [-h] [-o outfile] [-E] [-c] [-S] [-dump-asm] [-O {0,1}]
              [-dump-ir] [-shared] [--dummy-datapack] [--stats]
              [--dump-commands] [--c-page-size SIZE]
              infile [infile ...]

Command line tool for the Minecraft Compiler Collection

positional arguments:
  infile              Input files

optional arguments:
  -h, --help          show this help message and exit

Output generation control:
  Options that control what stage in the output pipeline the compiler should
  stop at.

  -o outfile          Set the filename to write output to.
  -E                  Stop after running the preprocessor. Input files which
                      do not pass through a preprocessor are ignored.
  -c                  Compile source files, but do not link. An object file is
                      created for each source file
  -S                  Do not compile Command IR code. A Command IR file is
                      created for each non Command IR source file

C Compiler options:
  Options specific to the C compiler.

  -dump-asm           Print The generated ASM code to stdout. Compilation is
                      stopped after this point.

Optimization control:
  -O {0,1}            Control optimization level

Linker arguments:
  Arguments that control how the linker behaves.

  -dump-ir            Print Command IR textual representation to stdout after
                      linking objects, then exit

Packer arguments:
  Arguments that control how the packer behaves.

  -shared             Include a symbol table and other metadata to enable
                      dynamic linking of datapacks
  --dummy-datapack    Don't write an output datapack. This can be used for
                      debugging with --dump-commands
  --stats             Print statistics about the generated datapack
  --dump-commands     Dump the commands to stdout as they are written to the
                      datapack
  --c-page-size SIZE  Size of the memory page to generate if using the C
                      compiler

MCC will dispatch a different tool depending on what the file extension of each input file is:

  • .cbl Will compile the CBL source code file
  • .c Will compile the C source code file
  • .asm Will compile the assembly file
  • .ir Will read the Command IR file
  • .o Will load the pre-compiled Command IR object file
  • .dpd Will read the datapack definition file

Depending on the command line arguments, MCC will perform different tasks on each file. Some files are ignored if they are not relevant for the desired action.

Examples

Compiling examples/fib.asm into a datapack fib.zip:

python mcc.py examples/fib.asm examples/fib.dpd

Compiling examples/hdd_driver.c into Command IR examples/hdd_driver.ir:

python mcc.py examples/hdd_driver.c -S

Compiling mylib.cbl into an object file, statically linking myprogram.cbl with the object and examples/fib.ir, then using mydatapack.dpd to create mysuperdatapack.zip:

python mcc.py mylib.cbl -c
python mcc.py mylib.o myprogram.cbl examples/fib.ir mydatapack.dpd -o mysuperdatapack.zip

command-block-assembly's People

Contributors

chorman0773 avatar omegametor avatar simon816 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

command-block-assembly's Issues

python errors out when launching mcc.py

When I tried the example command for fib.asm, python errors out with an invalid syntax error. Weirdly enough, it's from cbl.compiler :
line 336
assert not decl.async
^
SyntaxError: invalid syntax

Style change for C API

I know that these APIs are barely released but you for example instead of:

set_block
is_block
...

You should probably do this:

block_set
block_is
...

It just keeps code a lot more organised in my opinion and opens up room in the future for easy C++ to C transpilers.

Also might consider using Vec3 structs in block call commands:

Vec3 pos = Vec3_new(0,0,1)
block_set(pos,"minecraft:cobblestone")
if(block_is(pos,"minecraft:cobblestone"){
   //do something
}

Customs entities scoreboard id :

Allow to target entities with scoreboard id equal to a changing scoreboard value at in game tics

Why :
It is a basic contraption useful for more complex ones
For example I use it for modular moving platforms through selecting them by id_objective and running on them relative clone and tp
It can have many other purposes
We could add new instructions rather than the function example

Hi everyone
maybe I should introduce myself a litle bit ?
so I am a minecraft player experienced in commands
I used to write functions files for some complex contraptions for last 2 years
Hand writing is time-consuming, that is why I am interested in your assembly and I have a lot to learn
I have some ideas and I could help to improve it, even if my Github account is not updated

In minecraft commands :
Running a function on selected entities id looks like this :

_scoreboard players operation @s computed_objective = @s id_objectivename
scoreboard players operation @s computed_objective -= @a[tag=memory_entity] id_cible
execute as @s[scores={computed_objective=0..0}] at @s run function functionpath__

maybe it is already possible to do that with assembly instructions ? I do not know them enough
I also do not understand why "It is not possible to dynamically reference scoreboard objectives"

Load.json & Tick.json

Fantastic project. Will be using this for a few things.

Is it possible to have a function be called upon /reload and every tick? Would be very useful.

Fibonacci CBL example not working (Version compatiblity?)

First off, this is a very cool project.

I'm test out the Fibonacci CBL example, and it doesn't seem to be working. I've two methods of generating the datapack:

  1. python3 mcc.py examples/fib.asm examples/fib.dpd and...
  2. https://www.simon816.com/minecraft/assembler/

With both of those datapacks, there's no output.

I'm trying to use it with Minecraft 1.14.4. Maybe that's not a supported version of Minecraft? I looked through the README, but I didn't see anything about version compatibility.

Couple of missing features, 1.16 integration, and wiki pages

Some QOL features:

  • Converting int to string in constexpr
  • Allowing Entitys to be used in boolean conditions to check if they exist
    A work around for the point above:
int exists = 0;
for (e in filter (e2 in Game.entities){
    e2.has_tag("tag");
}) {
    exists = 1;
}

if (exists) {
   // If true
}
  • Basic boolean keywords like true and false don't exist
  • A null or nullptr keyword for comparing Entitys to check if they exist
  • More ways to filter entity by nbt, name, position, scores, and teams
  • Support for 1.16 execute in and maybe a keyword as well
  • as keyword for execute as
  • Overworld, Nether, and End variables defined in Game, builtins, or somewhere else
  • A way to get a world by namespace id. eg. minecraft:end

I looked in the ir wiki page and I could not find any definition for forceload. You have other commands, but not forceload.

Wiki pages:

  • Add intrinsic_extension to the CBL syntax page
  • Add const to the CBL syntax page
  • Add a page for using the builtin types like World, Entity, and NBT

I also noticed that

summon_entity("item", "~ ~ ~", "{Item:{id:\"minecraft: ## color ## _carpet\",Count:1b},PikcupDelay:5s}"); \

PikcupDelay is a typo.

I could be missing something, but using sender gives me an error saying that it doesn't exist.

Possible bug in #include_h assembly directive

I'm trying out assembly for my current project and am running into a strange error. I have a file (regs.asm) with several constants defined in order to emulate registers, and I'm using the #include_h directive to load that file into my main file (main.asm). When I try to assemble my project, I get this error:

Traceback (most recent call last):
  File "[redacted]/Command-Block-Assembly/mcc.py", line 4, in <module>
    start()
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 353, in start
    run_with_args(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 360, in run_with_args
    main(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 275, in main
    top = dispatcher.make_top(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 132, in make_top
    assembler.parse(self.text_file().read(), self.infile.name)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 47, in parse
    self.consume_reader(AsmReader(text, self.filename))
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 54, in consume_reader
    self.handle_token(token, arg)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 69, in handle_token
    self.handle_directive(*arg)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 135, in handle_directive
    if isinstance(val, Variable) and val.owner:
AttributeError: 'GlobalVariable' object has no attribute 'owner'

Here's my source code:

regs.asm:

.r0: 0x00
.r1: 0x01
.r2: 0x02
[.r3 - .rE omitted for brevity]
.rF: 0x0F

main.asm:

#include_h regs.asm

main:
    MOV #0, r0
    MOV #1, r1
    MOV #1, r2
    MOV #0, r3
    _fibloop:
        PRINT "fib(", r2, ") = ", r0
        SYNC
        ADD #1, r2
        MOV r0, r3
        MOV r1, r0
        ADD r3, r1
        CMP #0, r0
        JGE _fibloop

Is this a bug in the assembler, and if not, how do I fix my code?
Thanks in advance!

Possible bug in event handler compilation in CBL

I am trying to learn CBL, and I am having trouble with the event handler example compiling properly. I'm using this example, copied from the CBL syntax reference and modified slightly:

include "Text"
include "Events"

[Event Events.placed_block: {event.item.item: "minecraft:stone"}]
void on_stone_placed() {
    Text t;
    t += "Stone block placed";
    t.send_to_all();
}

When I attempt to compile this with MCC, I get this error message:

Diagnostic:
Compiling function .cbl_init
Current basic block: BasicBlock(_internal/.cbl_init/entry)
    entry:

src/main.cbl:0:0: error: __init__() missing 2 required positional arguments: 'func_members' and 'func_properties'

If I rewrite my code as follows:

include "Text"
include "Events"

[Event Events.placed_block]
void on_stone_placed() {
    Text t;
    t += "Stone block placed";
    t.send_to_all();
}

Then it compiles with no errors.

What (if anything) am I doing wrong, and how do I fix it?

Thanks!

Some features I would love to see (if possible, of course)

Hello,
So I wanna see some things that I think would be helpful to people.

  1. Array support
    What I mean by that, is that we can store, and modify, and delete array values.

  2. Get player data (like Motion, position or rotation) and safe it into a variable

For now this is all I could think of. Thank you for making such a amazing tool!, Keep up the good work.

Great, but needs some things.

If I can request, it would be good if the Compiler was designed with all major features. One thing is that the primitive types in C include all, including a 64 bit long. It could be setup to operate on 2 ints at once. Also The c standard library should be provided, the other integral types could be setup to do something similar to java, where char, and short are promoted to int, with unsigned values being 0-extended, and signed values being sign-extended. (IE. FFFF would be FFFFFFFF if it starts as a (signed) short but 0000FFFF if it starts as an unsigned short.) Also if possible pointers and indirection would be greatly appreciated. (Like MOV 1, [] -> in most assembly languages, when a memory address is given, but is enclosed in [], it refers to using the memory address stored within .
I know that function-pointers are probably not possible, but all other parts of C should be possible to implement. The last thing is indexing (in ASM). It should be possible to index a memory address from a given.
Finally, this should probably be updated to Minecraft 1.13 command-set, because 1.12 commands are incompatible with 1.13, and 1.13 will be more versitile.
All in all, this is an amazing thing, and assuming that I can utilize the standard library and all of the internals, It would because possible to implement the VM of a High-Level Language, and total control MC.

Computing Coordinates

You can convert coordinates to scoreboard values and scoreboard values to coordinates in Minecraft :

To scoreboard :

execute as @e store result score @s Xcoordinates run data get entity @s Pos[0] 1

To coordinates :

execute store result entity @e[tag=memory_entity,limit=1] Pos[0] double 1 run scoreboard players get @s Xcoordinates

In NBT format :
Pos[0] : X
Pos[1] : Y
Pos[2] : Z

Same with rotation in degrés :
Rotation[0] : player course
Rotation[1] : inclination

I think assembly instructions may be useful
Hope it will help

cannot import name 'LEXERS' from 'compiler.parser_gen'

I cannot run compiler_main.py. The import file parser_gen (as far as I can tell) does not contain LEXERS. It is only referenced once in parser_.py which, when removed, causes more problems (I'm not even sure what the for loop it is part of does, but that is beside the point).
I have installed lark-parser and ran ./compiler/rebuild-grammar.sh as per README-C.

I figure I might want to bring this to attention, maybe it's in there by accident?
I suspect that it was part of parser_gen.py before, but an update to lark removed it?

Potential Binutils?

I was wondering if it may be possible to write a full set of binutils for this (Basically have a ld which does some checks and that's it, and as which is a port of this, or a thin-wrapper arround this), which would basically enable people to use full gcc. It would take some more work than just this, but it would be a start.

Are there plans to update to Minecraft Version 1.15.2 ?

I know it just came out, and all, but I was wondering if there were plans to update this to Minecraft 1.15.2. I also wanted to gauge how "alive" the project is, which seems decently so given the last commit was about four months ago. (There's no in-progress branches for me to peek at. 😛 )

Also, truly awesome work. I was just wondering if something like this would be possible.. and stumbled across MCC. Great stuff!

Bug involving #include and #include_h assembler directives while using relative paths

I am working on a project with this file structure:

  • src/
    • setup/
      • init.asm
    • util/
      • regs.asm
    • main.asm

In init.asm, I have this code:

#include_h ../util/regs.asm

init:
    [routine body omitted for brevity]

In main.asm, I have this code:

#include_h setup/init.asm

main:
    CALL init

When I try to assemble main.asm, I get this error:

Traceback (most recent call last):
  File "[redacted]/Command-Block-Assembly/mcc.py", line 4, in <module>
    start()
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 353, in start
    run_with_args(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 360, in run_with_args
    main(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 275, in main
    top = dispatcher.make_top(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 132, in make_top
    assembler.parse(self.text_file().read(), self.infile.name)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 47, in parse
    self.consume_reader(AsmReader(text, self.filename))
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 54, in consume_reader
    self.handle_token(token, arg)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 69, in handle_token
    self.handle_directive(*arg)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 133, in handle_directive
    self.top.include_from(assembler.top)
  File "[redacted]/Command-Block-Assembly/cmd_ir/core.py", line 355, in include_from
    self.scope[name] = ExternFunction(var.global_name.name, self)
  File "[redacted]/Command-Block-Assembly/cmd_ir/core.py", line 641, in __init__
    super().__init__(NSName(name), params, returns)
  File "[redacted]/Command-Block-Assembly/cmd_ir/core.py", line 598, in __init__
    self.params = list(params or [])
TypeError: 'TopLevel' object is not iterable

It seems that relative paths don't work properly when used in #include_h or #include directives. Can this be fixed?
Thanks in advance!

Possible bug in the C text API

I am having trouble with the C Text API, specifically the function text_set_click_run. I have this code:

#include <stdio.h>
#include <text.h>

void say_hello() {
    printf("Hello!");
}

void main() {
    text_begin()
    text_set_text("Test");
    text_set_color("yellow");
    text_set_click_run(say_hello);
    text_end(TEXT_TELLRAW);
}

When I compile this file to object code, then to a datapack, then run the main function (by entering /function test:sub_main, the clickable text "Test" shows up in yellow as expected. However, when I click it, Minecraft displays an error stating "Expected whitespace to end one argument, but found trailing data". Minecraft then shows that instead of MCC compiling the click event function as /function test:sub_say_hello, it compiled it as /function $func:say_hello$. This made the datapack not work.

Is this a bug, and if not, how do I fix it?

Thanks!

Edit: I am using the latest version of the compiler, git cloned from the repository.

High level method suggestions

I know some of these might end up being very expensive. Sadly, Mojang is doing a $#!t job at improving their command system to perform better in complex mcfunction files.

Here's my list of suggestions:

Working with inventories

In C++ version, the container could be a class holding context about container position, possibly extra position for double chests so that you don't have to check for adjacency every call. In C it's a struct.

  • get_item_count(container, item, slot_range=all)
    • test every slot in container for each number 1-64, sum them, use result - yes, very slow
  • has_item(container, item, count=1)
    • same as above but terminates earlier so a bit faster
  • modify_item_count(container, item, count=1)
    • positive count values add items, negative remove items
  • Support for item frames.
    • Methods mentioned so far would allow spiffy and compact sorting systems to be written for example.

Working with data

I suggest you allow loading files (just one format is more than enough) and using their content. JSON files would probably be the best choice as MC uses JSON for its data pack content.
Using fopen/fstream would be confusing, I suggest a custom name like json("rel_path.json").
This would for obvious reasons be read-only. Treat object as a struct. During compile-time, read content from the path and bake in all possible permutations (YES, slowness) based on possible states.

Make IDs a primitive type

Store a local list of all blocks and items - generated from decompiled minecraft code, not sure if there's a better source - so that they can be treated as primitive types. This would ease the pain of generating large numbers of permutations for commands which interact with inventories.

Block states

Allow interacting with block states. These can be optimized a bit as they are block dependant. Information can be generated from each version data. Access from C++ with operator[], from C through struct values.

I haven't looked at Minecraft for a very long time so some of these might be possible to do in a better/more optimized way. I'm aware these are a lot, but they would make writing huge mcfunctions files simple as it's easier to generate 10000 lines of commands from python than actually writing them. Having said that, I'll create yet another suggestion on r/minecraftsuggestions and spam the discord that they add commands for populating scoreboards with item counts and reducing/increasing stack sizes in inventories.

I'm currently very busy, but your project is something that I've been thinking about for two years now and I'm very interested in how it pans out. I'd love to contribute, I might sometime soon, but I'm currently working on a decompiler.

Edit 1

Raytracing

Another commonly used function that should work 99% of the time and is extremely useful is raycasting. There are some problems with it (like detecting non-full blocks), but these could be supported via tags (as in block/item lists in data json). Here's a nice tutorial I found for it which explains in great detail several techniques and their drawbacks. A few things have changed since it was made but generally, it still applies. Some things could be optimized a bit for instance.

Possibly even snowballs could be used by teleporting them and changing their velocity (it should be possible I think), this would provide a better performance and a much better collision detection than using armour stands. Would involve complicated calculation for velocity but that's only a problem to do without a script or a compiler.

Linker bug involving subroutines included from external files

I am working on the same project as the previous issue (#21), with this file structure:

  • src/
    • setup/
      • init.asm
    • util/
      • regs.asm
    • main.asm

In init.asm, I have this code:

#include_h ../util/regs.asm

init:
    [routine body omitted for brevity]

In main.asm, I have this code:

#include_h setup/init.asm

main:
    CALL init

Since you fixed #21, I am able to assemble this code into object files successfully, however when linking, I get this error:

Traceback (most recent call last):
  File "[redacted]/Command-Block-Assembly/mcc.py", line 4, in <module>
    start()
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 353, in start
    run_with_args(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 360, in run_with_args
    main(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 290, in main
    top = link(tops, args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 193, in link
    final_top = TopLevel.linker(*tops)
  File "[redacted]/Command-Block-Assembly/cmd_ir/core.py", line 470, in linker
    out.store(name, var)
  File "[redacted]/Command-Block-Assembly/cmd_ir/core.py", line 263, in store
    '%s: %s' % (name, self.scope[name])
AssertionError: sub_init: DynLink(sub_init)

Can you fix this?
Thanks in advance!

Python Assembly

I finally end up writting my own assembly in python

Currently availables instructions :

  • selecting a mcfunction and writing in
  • while and for loops
  • My scoreboard selector

This one is intended to rely mostly on commands knowledge and simple instructions rather than programming skills
Intended to be easy to use and to be easily improved
For all audiences

ask me if you are interested
or ask me if I am just flooding issues and if you prefer that I stop

how do you run the tetris example

This is a newbie question. I've created a superflat 1.14.4 world and loaded the tetris datapack in it.

I used this .dpd file:

[Datapack]
namespace=tetris
place location=300 4 300
description = Tetris
generate cleanup=true

then built with python mcc.py examples/tetris.cbl examples/tetris.dpd.

When I tp to 300 4 300 and run /reload I see 3 command blocks placed, which makes me think the datapack was loaded. When I run /function tetris:main it says: 6127 commands executed, but nothing in the world appears to have changed.

May I ask how to make this example do whatever it is supposed to be doing?

Potential feature: Dynamic dispatch without a tick delay

A series of chain command blocks that loops back on itself (most compactly, just two facing each other) will continue to run to the chain limit if both have the tag UpdateLastExecution set to 0. This allows dynamic dispatch to be done without a tick delay by updating one of the command blocks in such a chain while a previous one is executing, which seems like a potentially desirable feature.

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.