simon816 / Command-Block-Assembly

Compile high-level code into Minecraft commands
https://www.simon816.com/minecraft/assembler
MIT License
272 stars 29 forks source link

Python Assembly #6

Closed Loumardes closed 5 years ago

Loumardes commented 5 years ago

I finally end up writting my own assembly in python

Currently availables instructions :

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

simon816 commented 5 years ago

Sounds interesting. Do you have any examples or implementation code publicly available?

Loumardes commented 5 years ago

Hi Takes to me a while to find your reply

The assembly code is close to the final form I wanted I will give you a link when ready

The Base Concept :

So the user can generate his datapacks by writting a script files with, for example for_loop(criterias), without knowing how it's done with command He can easily fix an argument error instead of browsing the datapack And he can define his own functions in his own library to use and can share them

At least thats the concept I will give you the link soon and you will be welcomed to give changes suggestions

chorman0773 commented 5 years ago

Interesting. And can you also generate custom commands with it? This may be good for https://github.com/chorman0773/Gac14-Datapack.

Loumardes commented 5 years ago

Yes it can support any MCcommands It generate custom datapacks Minecraft commands

It now have many more "library functions" the most important are : "_write(MCcommandslist)" to write any MCcommands in an mcfunction (most important) and "_writed_folder(new_folder = folder, function_name = functname)" to choose to which mcfunction you add the command

So all others "library functions" are defined with theses 2 simple functions and a bit of python syntax I added : _new_objective(objectivename) to init the objective _get_function(folder = folder, functionname = "") to return the /function wich target the designed mcfunction _set_entity(entityargs) a /summon with extra arguments like tags, scoreboard and commands to run as the new entity _take_score(target_entity = "@s", target_objective = "", aim_entity = "@s", aimobjective = "")

there is some more, and I also planned raycasting, custom mob targetting ...

I will release it soon, before beeing fully tested and finished I spend too much time without feedback

Loumardes commented 5 years ago

I strived to make the assembly code as simple as possible, in order to allow you and others to easily contribute

chorman0773 commented 5 years ago

What I meant is does it support replacing some of the less efficient vanilla commands, with more efficient modded ones easily. The datapack I posted targets a modded server environment with enough functions to write that something like this would be incredibly useful.

Loumardes commented 5 years ago

Yes you can write custom commands instead of vanilla ones in mcfunctions files and you can change the extension if you want

The main assembly goal was to allow programming with the inefficient vanilla commands But you will be able to write a library for my assembly to write new commands more easily

In fact the assembly can be used for anything involving writing text files

I want to show the code soon, maybe this week

simon816 commented 5 years ago

From what I can understand, it sounds like you're creating a DSL (Domain Specific Language). So you write python code that generates commands? That's basically what commands.py does in this project, for example this function generates a bitwise operation).

FYI I'm working on a new core system for Command Block Assembly - an IR (intermediate representation) which represents a level of abstraction over commands (branch command-ir). The fib.asm looks like this in the IR: https://gist.github.com/simon816/bb83500dc9a98fc25cd9459f591caefb

Loumardes commented 5 years ago

Yes that is exactly a DSL which write Minecraft commands in datapacks user write scripts using theses DSL functions to specify the datapack commands (they are still python scripts but user may not know it) It dont manadge commands blocks because you can do everything inside the datapack

I followed different guidlines for my assembly :

I would like to make the assembly avalaible for all odiences So I avoided object oriented programming, I use python functions only abstraction will be achived through defining new libraries based on the functions of the simplier libraries

The issue I have with your assembly is that I found it too complex to master I dont understand how the commands block are outputed maybe improving your documentation will help me

Fun fact, all the code defining this DSL language is shorter than your commands.py script :)

simon816 commented 5 years ago

The issue I have with your assembly is that I found it too complex to master

The assembly language is similar to other assembly languages like x86 so you'd need to have a basic understanding of how assembly/machine code works.

I wrote the C compiler to make it much easier to write code, and using a familiar language.

main.py (or compiler_main.py for C) is the entry point. When given the --world-dir option it outputs a datapack directly into the world's datapack folder.

For example: python main.py examples/fib.asm --world-dir ~/.minecraft/saves/MyWorld This will write the datapack for the fib.asm example into the world "MyWorld".

Loumardes commented 5 years ago

Well it's impressive

I have read again the readme documentation, I understand better your work Seem that C# syntax is run in game as mc commands and not at compile time

I have a question :

Did it exploit full Minecraft commands potential ? Minecraft commands is kina Object Oriented Programming thanks to entities, selectors and execute criterias, you can reproduce Classes with :

You can dynamically reference entity and tags for memory purposes

simon816 commented 5 years ago

The way variables work is by storing them on an armor stand where each variable is a single dummy objective. Normal variables use just a single entity - there is only one entity that can be assigned scores on these objectives. I also added the ability to specify "entity local" variables which are basically the same as normal scoreboard objectives where the value is attached to entities that you can specify.

I wouldn't go as far as saying scoreboards can emulate classes. It's really a table of: (entity, objective) -> value Although you can probably do pseudo-OOP (there are techniques for this in C).

On the readme I say that you can't dynamically reference memory locations. What I mean by this is that you have to specify objective names before the program is run. e.g. for an objective "A" I can't store the name "A" somewhere in-game, then say "give me the value of objective get_stored_objective". I have to specify the objective beforehand.

Loumardes commented 5 years ago

On the readme I say that you can't dynamically reference memory locations. What I mean by this is that you have to specify objective names before the program is run. e.g. for an objective "A" I can't store the name "A" somewhere in-game, then say "give me the value of objective get_stored_objective". I have to specify the objective beforehand.

What I mean is that you could specify an entity with a tag to return the value of a default objective instead of specifying the objective of a default entity tags can be changed in game trough commands

Loumardes commented 5 years ago

Here is my assembly : https://github.com/Loumardes/BlocCode

It may seem a bit amateurish in comparison but for someone who started programming 6 month ago I think it's fine :)

I am a lot more experienced in datapack editing and what's inspire me for this code is beeing able to perform the repetitive task in datapack editing with dedicated functions, while aiming maximal code scalability and clarity

I named it "Bloccode" as a way to fill a gap between MCcommands and programming you can suggest other ideas

Feel free to leave your feedback in the issues sections Have a nice day

simon816 commented 5 years ago

Looks good, thanks for sharing. Closing this issue now.

Loumardes commented 5 years ago

It was a pleasure to discuss with you

Good luck for yours projects