Coder Social home page Coder Social logo

adrodoc / mpl Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 4.0 2.74 MB

A language to generate command blocks for Minecraft 1.9 and higher

License: GNU General Public License v3.0

Java 85.18% ANTLR 0.66% Groovy 12.05% Python 0.15% CSS 0.41% JetBrains MPS 1.54%
minecraft programming-language gplv3 java gradle-wrapper antlr4

mpl's Introduction

This repository has moved to https://codeberg.org/Adrodoc/MPL to avoid GitHubs two factor authentication (2FA) requirement. We believe that Microsofts decision to force all code contributors to use 2FA is very problematic for the following reasons:

  1. 2FA significantly increases the risk of irreversible account loss. This is very different to 2FA for something like online banking where in the worst case you can contact your bank and verify your identity to regain access. With GitHub however, if you loose your phone and backup codes (both of which is possible), you will never gain access to your account again.
  2. The decision to require 2FA for every code contributor seems very needless. Yes software supply chain attacks are a thing, but not every code contributor on GitHub is responsible for widely used libraries. It's quite the opposite: most code contributors are not responsible for widely used libraries and their code is reviewed and merged by those that are. Also, the details of the 2FA requirement seem arbitrary. Why for example is email not accepted as a second factor or why can WebAuth only be a second second factor and not a primary second factor? Just to make it really hard to not use a phone for 2FA? It feels like a "trust us, we know what's good for you" attitude from Microsoft and it is scary to think what arbitrary decision could come next.
  3. Depending on how you use passwords the account security is not necessary improved that much by using 2FA, especially if it is forced onto people that don't want to use it. So why is there no opt out?
  4. Many other developers publicly stated that they are leaving GitHub because of this, so staying on GitHub would prevent any code contributions from these people. This makes finding good contributors even harder than before. By moving to https://codeberg.org everyone can continue to contribute to this project.
  5. Unfortunately Microsoft does not allow mail as a second factor and some companies do not allow you to bring your private phone to work or install proprietary software (such authenticators) for security reasons. This means 2FA can actually completely prevent you from logging into the website in some circumstances. This is really sad, because it can make it harder for professional developers at companies that use free and open source software to return something to the community.
  6. Not everyone owns/can afford a smartphone or dedicated authenticator hardware and Microsoft makes it very inconvenient to use 2FA without that by requiring you to install authenticator software on every development machine. This discourages code contributions from poor people.

2FA is a good technology, but it should be up to repository owners to decide whether it is appropriate for the project at hand. Requiring 2FA for all code contributions, even for code that is reviewed and merged by other people, is completely unnecessary and discourages contributions.

Minecraft Programming Language (MPL)

Author: Adrodoc

What is MPL?

MPL is a language that makes it easier to write applications for Minecraft 1.9 or higher. The final result of compiling an MPL application are command blocks that can be imported into your world in various ways. MPL comes with it's own editor that supports syntax- and error-highlighting and has a built in compiler.

For an advanced example application written in MPL see ApertureCraft Vanilla

While MPL can be used to create very complex command block applications, it is also very easy to use for small projects. To use the command block generator you don't even need to know about any MPL specific syntax.

How To Use

You can find a full tutorial for MPL here.

There are multiple ways to compile .mpl files:

  • Open the file in the IDE and compile it by hand. You can find a detailed explanation in the tutorial.
  • Run the standalone compiler from the command line.
  • Compile MPL ingame using the Bukkit plugin MplManager by BrainStone.

License

MPL is licensed under GNU General Public License. Any application compiled by the MPL compiler is free from this license even if the compiler inserted standard MPL code templates.

It would still be nice if you give credit to MPL, for example by using the following command in the installation of your application:

/tellraw @a [{"text":"This project was created using the\n ","color":"yellow"},{"text":"Minecraft Programming Language ","color":"gold"},{"text":"[MPL]","color":"aqua","hoverEvent":{"action":"show_text","value":{"text":"Click to open GitHub","color":"red"}},"clickEvent":{"action":"open_url","value":"https://github.com/Adrodoc/MPL"}}]

Download

For manual use you can download the standalone compiler and IDE from GitHub.

MPL is also available both as library and standalone application at Sonatype OSS Maven Repository and Maven Central. To get MPL using Maven add the following to your pom:

<dependency>
    <groupId>de.adrodoc55.mpl</groupId>
    <artifactId>mpl-compiler</artifactId>
    <version>1.3.2</version>
    <scope>compile</scope>
</dependency>

In Gradle you can use the following example build.gradle:

apply plugin: 'java'

repositories {
  mavenCentral()
}

dependencies {
  compile 'de.adrodoc55.mpl:mpl-compiler:1.3.2'
}

Contributing

If you are missing a feature or just want to help out you can contribute to MPL by opening a pull request.

Here are some guidelines to make contributing easier:

  • The MPL Project is split into two parts, the compiler and the ide. Both of these directories are subprojects, that should be imported into your IDE.
  • You should configure your IDE to use the google java formatter.
  • All files should be encoded in UTF-8.
  • This project uses lombok. This does not make a difference on the command line, but depending on what IDE you use, you may have to install lombok into the IDE: https://projectlombok.org/setup/overview.
  • When using Eclipse configure the project by using the Gradle Wrapper and executing gradlew eclipse on a command line in the root directory.
  • Most tests are written in groovy. If you are using Eclipse you might want to use the greclipse plugin.

Building

MPL is built using Gradle. You don't have to install Gradle, because the project contains a Gradle Wrapper along with the source files. To build custom jar files execute gradlew build on Windows or ./gradlew build on Unix systems. The jar files will be created in the directories MPL/ide/build/libs and MPL/compiler/build/libs.

mpl's People

Contributors

adrodoc avatar brainstone avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

mpl's Issues

Add "Compile to Schematic"

It would be nice to add a feature to compile the command blocks to a schematic file so you can import the structures with something like worldedit

loop implementieren

loop implementieren

Source:

/scoreboard players set result POW 1
while not: /scoreboard players test exponent POW 0 0
repeat (
/scoreboard players operation result POW *= base POW
/scoreboard players remove exponent POW 1
)

Generated:

/scoreboard players set result POW 1
if: /scoreboard players test exponent POW 0 0
then (
/setblock ${this + 8} redstone_block
) else (
/setblock ${this + 1} redstone_block
)
skip
repeat: /scoreboard players operation result POW *= base POW
/scoreboard players remove exponent POW 1
/scoreboard players test exponent POW 0 0
conditional: /setblock ${this - 4} stone
conditional: /setblock ${this + 1} redstone_block
skip
impulse: /setblock ${this - 1} stone
...

Add compile time functions and loops

It would be wonderful to have a feature that allows functions to be compiled during runtime.

Example:

function hello (
  /say Hello!
  /say How are you?
)

process main (
  hello
  /tp @a ~ ~10 ~
  hello
)

This should generate the following code before it gets compiled into command blocks

process main (
  /say Hello!
  /say How are you?
  /tp @a ~ ~10 ~
  /say Hello!
  /say How are you?
)

Also having the possibility to add parameters would be amazing!
Suggested syntax

function tp_player($x, $y, $z) (
  /tp @p $x, $y, $z
)

process main (
  tp_player(1, 2, ~10)
)

Generates:

process main (
  /tp @p 1 2 ~10
)

Also for loops during compile time:

process main (
  for $x from -10 to 10 step 5: (
    /tp @p $x 2 ~10
  )
)
process main (
  /tp @p -10 2 ~10
  /tp @p -5 2 ~10
  /tp @p 0 2 ~10
  /tp @p 5 2 ~10
  /tp @p 10 2 ~10
)

Process Parameter

Using Variables as described in #31, it should be possible to call a process and give it parameters.
A runtime/normal Process can be called with values and selectors.
There should be a new type of process, a compiletime process.
A compiletime process can be called with all types of variables and will be inlined into the calling process.
A compiletime process should be able to call both compiletime and runtime processes.

Add incremental compilation

This feature would improve the development of large MPL program, where it is not possible to import the entire program with one command.

When using incremental compilation, the compiler should create a patch script that modifies the existing command blocks, instead of recreating them. The structure would need to track a version hash to tell the patch script wich patches are necessary.

if: then: else: end hinzufügen

if: then: else: end hinzufügen

Tabgröße sollte entsprechend auf 2/4 angepasst werden.

Beispiel:

if:
    /scoreboard players test @p sneak 1 1
then:
    /say hi
    if:
        /scoreboard players test @p sneak2 2 2
    then:
        /say 2!!!
        /say inner then
    end
    /say then
else:
    /say else
    /say hi2
end

wait keyword and process

Add a keyword wait that will wait for one tick.
To wait 2 or more ticks there should be a process with the name wait with a parameter time of type value as defined in #31.
This process should have the modifier remote (#34) to make sure that calling and returning takes one tick each.

An implementation could look roughly like this:

remote repeat process wait(value ticks) {
  ticks -= 1
  if: ticks < 2
  then {
    return
  }
}

Rework waitfor and notify logic

The keyword notify should not be used on it's own in remote processes anymore. Instead remote processes that are called or waited for should automatically notify at their end.

The syntax waitfor notify myProcess is removed and the normal waitfor returns to it's old semantic.
Additionally notify myMutex can now be used to trigger a waitfor myMutex.
Both notify and waitfor will create a compiler error if their counterpart does not exist.
If a remote process with the name myProcess exists, then waitfor myProcess is valid. It is not yet decided, whether notify myProcess will also be valid in that case.
To avoid the compiler exceptions notify, waitfor, start, stop and intercept can be called with the remote keyword. For example start remote myProcess. This allows to call other applications at runtime.

Add packages

Imports and included are currently based on relative file paths. This is not very useful for libraries. It would be better to have a packaging System similar to java, because imports/includes can then use an "absolute" file path:

package "mpl/lang"
import "mpl/util"

This also opens up the possibility of using multiple source folders wich would allow to use ZIP archives for libraries.

A simple nested if is missing a parent normalizer

A simple nested if is missing a parent normalizer.
The following example will work correctly if there are zero or exactly one pigs in the world. If there are two or more, nothing will be printed, even though it should print "innerElse".

if: /testfor @e[type=Pig]
then (
  if: /this is false
  then (
    /say innerThen
  ) else (
    /say innerElse
  )
)

Process tags

Similar to annotations in java. They would allow reflection and MplUnit:

#Test
process test_haha {
  ...
}

Lables in Debug mode barely visible

Lables of armor stands are barely visible in Debug mode.

2016-05-26_04 05 47

Suggested fixes:

  • Move armor stands up one block in Debug mode and set relative coordinates when starting and stopping to ~ ~-1 ~
  • Move amor stands 0.49 blocks up in Debug mode. They still will be in the block (no changing of the starting and stopping required) but the tag is visible
  • Don't use the marker flag

Parse and validate Minecraft commands

This would enable warning the user about missspelled commands at compiletime.
It would also make autocompletion possible for commands.
With this feature if then else could be improved for commands that are always successful like /say.

Process modifer

remote: process must always be called remotely and can't be inlined.
global/runtime/public: process will be inlined, but will also be available at runtime. Warning: waiting for or intercepting this process will only work when called remotely by a different project.
inline/compiletime/private: process will not be available at runtime and can't be intercepted or waited for. This enables string parameters. This should be the default.

Dynamic process calling

Dynamically call processes like this: start @e[tag=Test].
Maybe there is a way to pass parameters, though that might be very difficult, because the parameters are not available at runtime.

Syntax für if ändern

Neue Syntax:

if: /scoreboard players test exponent POW 0 0
then (
/setblock ${this + 8} redstone_block
) else (
/setblock ${this + 1} redstone_block
)

ANTLRErrorListener implementieren

ANTLRErrorListener implementieren.
Dies ist notwendig, um Syntaxfehler richtig anzuzeigen.
Vermutlich kann dann die Methode visitErrorNode(ErrorNode) aus dem Interpreter entfernt werden.

ability to call a process in a synchronized way

As suggested in #32 (comment) it should be possible to call a process. The syntax should be myFunnyProcess() and the semantic should be identical to:

start myFunnyProcess
waitfor

This has been extracted into this issue, because it required for #34 and works without parameters (#32).

Multiline comments

Multiline comments like the following would be quite nice to have.

/*
This
is
a
comment
*/

Simple comparison of scores for if and loops

Having simple comaprisons in conditions would be amazing!

Something like this:

if: selector1 score1 <= selector2 score2

would become

/scoreboard players operation selector1 score1 -= selector2 score2
/scoreboard players test selector1 score1 * 0
/scoreboard players operation selector1 score1 += selector2 score2

Then just apply the if logic to the second command.

Scoreboard-Test-Commands for all comparison operators:

<= -> * 0
< -> * -1
>= -> 0 *
> -> 1 *
== -> 0 0
!= use the == logic and invert the condition. (if: a b != c d becomes not if: a b == c d and vice versa)

Add keyword "clickable"

Add a keyword clickable to the process modifiers. (Also unclickable if clickable is implicit)
This add a sign to the process that will start the process by setting the auto-NBT-Tag in the command block.

I suggest that install and uninstall implicitly use this tag. Also a debug compiler option that implicitly adds the keyword to all processes might make sense.

Add compiler option to specify file encoding

Currently all source files have to be encoded in UTF-8. While this is a good default it would be even better if there was a compiler option "-e" or "--encoding" to specify a different file encoding.

Continuing after a breakpoint overrides repeat processes when not using transmitter

If you are not using the compiler option transmitter and continue the program after encountering a breakpoint, the first command block of all repeat processes is overwritten. This happens here.
The reason behind this is, that all impulse processes that have been triggered during the pause will start running because the nbt of the temporary command block was updated. For repeat command blocks this approach does not work.

Command line compilation

It would be lovely to have the option to compile files from the command line.

Something like this:
java -jar MPL.jar <type> <input.mpl> <output>

Add compiler warnings

Compiler warnings are similar to errors, but they don't stop compilation.
It should be possible to suppress warnings. That could be done with a keyword:

suppress "some warning"
/line that produces some warning

It could also be done "Java style" with a Tag:

#suppressSomeWarning
/line that produces some warning

Add "Compile to Structure"

It would be nice to add a feature to compile the command blocks to a structure file so you can import them with the 1.10 structure blocks

Compiletime scripts

Expanding on the idea of #25 it would be cool to enable embedded scripts that generate parts of the MPL program. This would require MPL to package a full language Interpreter.
Because MPL is written in Java, embedded groovy scripts are a good option.
An embedded script could look like this:

/say normal MPL code
compiletime {
  for (i in 1..10) {
    println "/generated line ${i}"
  }
}

Instead of the keyword compiletime we could use embedded or groovy.
For security reasons it is important to restrict embedded scripts from accessing the file system or internet.

Search and Replace implementieren

Durch STRG + F in einem Editor sollte sich ein nicht modaler, immer im Vordergrund befindlicher Suchen und Ersetzen Dialog erscheinen.
Wiederholter Druck von STRG + F sollte nur den Fokus auf den dialog wechseln, statt einen neuen aufzumachen.

Variables

There should be at least 3 types of variables:

  • String template
  • Selecor
  • Value

A value can be assigned from a constant or selector and scoreboard.
Selectors and templates can be used for interpolation.
Values can be used for scoreboard operations like:
mySelector Scoreboard += myValue

Support for infinitely nested if

Support for infinitely nested if is required for mpl to be a fully functional programming language.
Currently if is only supported for up to one nesting layer (see MplInterpreterSpec).

To fully support this it might make sence to rethink the IfChainBuffer. Maybe it can be implemented with a ReferencingCommand class, that has a reference to the actual condition command and the whole chain to determin it's offset lazy.

Another idea is that the MplInterpreter could always just have one chainbuffer that manages the nesting explicitely and keeps track of the current nesting layer.

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.