https://github.com/lesmiscore/groovymodpe
https://github.com/lesmiscore/groovymodpe
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/lesmiscore/groovymodpe
- Owner: Lesmiscore
- Created: 2017-04-15T14:20:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T05:08:14.000Z (over 2 years ago)
- Last Synced: 2025-01-24T23:16:21.200Z (over 1 year ago)
- Language: Java
- Size: 64.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GroovyModPE
brings you Groovy into BlockLauncher
## Compilation
Please install [Gradle](https://gradle.org) for compilation.
Change the current directory where this repo cloned, and type this on command line: `gradle mergeJavascript`
You'll see `GroovyModPE.js` at `Repo Directory/build/` (Please just ignore other files.)
## Usage
Just import `GroovyModPE.js` into [BlockLauncher](https://play.google.com/store/apps/details?id=net.zhuoweizhang.mcpelauncher).
Place your groovy file at `SD card or internal storage/games/com.mojang/groovyMods/`.
Files starting with `.`(dot) will be ignored.
## Basic coding
For Groovy language grammar, please search yourself.
### Defining hooks
```groovy
hooks.newLevel={->
}
```
In this case, `newLevel` is the name of hook. This is a hook name from BlockLauncher.
`{...->` is argument list.
### Calling methods from BlockLauncher
```groovy
clientMessage('This is a message from Groovy mod.')
```
Just do the same thing as Javascript do.
You can call functions in objects. (e.g. ModPE, Block)
```groovy
Entity.getAll()
```
### Getting `Activity`(Context) object
`com.mojang.minecraftpe.MainActivity.currentMainActivity.get()` is too long to use, so there's alternative way.
Use `context` to get Context object instead.
```groovy
import android.app.AlertDialog
def dialog=new AlertDialog.Builder(context)
dialog.message='I give you a pen from Groovy script'
dialog.show()
```
### Using `ConfigSlurper`
Android uses `Dalvik` to execute Android application, so using `ConfigSlurper` directly would give you an error.
To compile your groovy script dynamically, use `createScript` method.
```groovy
def cs=new ConfigSlurper()
def obj=cs.parse(createScript('value="A script inside script"'))
print(obj)
```
## Attention
All the code is not tested yet: I can't trust that it works well.
Please be careful.
Compiled code will be released when it finishes.