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

Style change for C API #3

Closed sancarn closed 5 years ago

sancarn commented 5 years ago

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
}
simon816 commented 5 years ago

Hmm I guess it's more "C-like" to prefix the names like that. I'll make that change. regarding vectors for block functions, it currently needs to be a compile-time constant due to it needing to get baked into a command. The easiest way of doing that (and including things like relative coordinates) was to just make it a string i.e is_block("~ ~ ~", "minecraft:stone") (converts to execute if block ~ ~ ~ minecraft:stone). Ideally there would be a runtime-implemented version.

chorman0773 commented 5 years ago

Instead of Vec3 being returned from a constructor function, I would make it an agragate. const Vec3 v = {0,0,1};. Maybe you could impliment some kind of basic constexpr, where you can either pass a const (or possibly an effectively const Vec3) structure, or an constant agragate initializer. Think C++ constexpr integrals. You could probably also do this for strings and integers. If you pass in a const char[] or a const int instead of a literal, it still works and is parsed as a literal. I know this isn't in the C standard, but then again, printf is allowed to take non-literal strings and non-literal arguments in ISO C. You could replace is_block("0 60 0","minecraft:stone"); with either is_block({0,60,0},"minecraft:stone") or use a const Vec3 object. For relative you could just have an intrinsic (built-in function) called relative which takes a Vec3 constant expression and results in a Vec3 constant expression that represents relative co-ordinates. It may also be prudent to have directed which does the same thing, except it represents directional co-ordinates (carat notation).