Skip to content

Add localization #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# GroovyScript Docs
This is the official repository for the GroovyScript Documentation using Read the Docs and MkDocs\
Docs are hosted [here](https://groovyscript-docs.readthedocs.io/en/latest/)
# GroovyScript Docs Localization
Being localized ......If you want to see the English wiki tutorial, [please](https://groovyscript-docs.readthedocs.io/en/latest/)

## Test locally
Run the following from a terminal
Expand All @@ -10,4 +9,4 @@ pip install -r requirements.txt
mkdocs serve
```
`pip install` installs the required dependencies and `mkdocs serve` builds and runs the doc on a local server.\
After that simply open [http://127.0.0.1:8000/](http://127.0.0.1:8000/) in a browser. It automatically refreshes when you save files.
After that simply open [http://127.0.0.1:8000/](http://127.0.0.1:8000/) in a browser. It automatically refreshes when you save files.
35 changes: 35 additions & 0 deletions docs/de/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Welcome to GroovyScript

Ein umfassender Skriptsandkasten für Minecraft 1.12.2. <br>
[Trete unserem Discordserver bei (Englisch)](https://discord.com/invite/m53yxTjjKM). <br>

!!! Note
Die deutsche Übersetzung ist nicht vollständig! Bei nicht vorhandenen Seiten werden die Englischen versionen gezeigt.

Du siehst nicht, was andere sehen? Versuche die Seite neu zu laden.

#### Merkmale:

1. Groovy: eine leistungsfähige und getestete Skriptsprache
- Java kompatibler Syntax + zusammenpassender Code
- Statische Kompilation
- Optionale dynamisches typisieren
- Metaprogrammierung
2. Sandboxed: scripts are effectively ran in a sandbox, with sensitive operations blacklisted from being called or referenced
3. Reloading: able to test script changes within the game without restarting
- Most if not all Forge Registry objects can be reloaded on the fly
- Most mod registries are supported natively
4. Events: Easily listen to Forge's EventBuses with Groovy Closures
5. Familiarity: Bracket handlers for those that are familiar with CraftTweaker (currently implemented, may be removed in the near future)
6. Informational: commands to display rich information for the item in your hand and more
7. Optimized: Making sure no compromises are being made while delivering features with efficient code
8. API: Great catalogue of code for other mod authors to make their mods compatible with GroovyScript such as package/class/method/field blacklists

### Where to go?
Check [this](getting_started.md) out to get started. <br>
Check out the Groovy tab for infos about the Groovy language. <br>
Check out the GroovyScript for the GroovyScript documentation. <br>

!!! Note
This wiki is highly WIP. There is still a lot of info missing. We would appreciate any help to improve this place.
Get started by joining our [Discord](https://discord.com/invite/m53yxTjjKM)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions docs/zh-TW/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Welcome to GroovyScript

A comprehensive scripting sandbox for Minecraft 1.12.2. <br>
[加入 Discord 群組(英語)](https://discord.com/invite/m53yxTjjKM). <br>

Are you not seeing what other see on this wiki? Try reloading it.

#### Features:

1. Groovy: a powerful and tested scripting language
- Java-compatible syntax + interoperable code
- Static compilation
- Optional dynamic typing
- Metaprogramming
2. Sandboxed: scripts are effectively ran in a sandbox, with sensitive operations blacklisted from being called or referenced
3. Reloading: able to test script changes within the game without restarting
- Most if not all Forge Registry objects can be reloaded on the fly
- Most mod registries are supported natively
4. Events: Easily listen to Forge's EventBuses with Groovy Closures
5. Familiarity: Bracket handlers for those that are familiar with CraftTweaker (currently implemented, may be removed in the near future)
6. Informational: commands to display rich information for the item in your hand and more
7. Optimized: Making sure no compromises are being made while delivering features with efficient code
8. API: Great catalogue of code for other mod authors to make their mods compatible with GroovyScript such as package/class/method/field blacklists

### Where to go?
Check [this](getting_started.md) out to get started. <br>
Check out the Groovy tab for infos about the Groovy language. <br>
Check out the GroovyScript for the GroovyScript documentation. <br>

!!! Note
This wiki is highly WIP. There is still a lot of info missing. We would appreciate any help to improve this place.
Get started by joining our [Discord](https://discord.com/invite/m53yxTjjKM)
Binary file added docs/zh/assets/images/slice_n_splice_recipe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions docs/zh/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# 让我们开始

哦不不, 读懂这不一定需要太多的编程知识, 但会对你有很大的帮助.
作为文本文件(.groovy), 你可以使用[VSCode](https://code.visualstudio.com/)来打开并且编写Groovy文件, 或者是一个更像样的IDE. (我们将在未来开发一个更好的替代品)

1. 下载 Minecraft和Forge 1.12.2并且安装它. (我想你的启动器应该可以)
2. 下载最新版的GroovyScript([点这里](https://www.curseforge.com/minecraft/mc-mods/groovyscript/files))
并且丢到你的mods文件夹里去. (HMCL等主流启动器支持直接从CurseForge下载模组)
3. 另外, 你还需要安装一个[MixinBooter](https://www.curseforge.com/minecraft/mc-mods/mixin-booter/files), 因为GroovyScript依赖于它.
4. 启动游戏, 并且往groovy文件夹里丢一些脚本.
5. 第一次启动时, GroovyScript将生成以下文件
- groovy.log (即[Groovy Log](#groovy-log))
- groovy/runConfig.json (即[Groovy运行配置](#run-config))
- groovy/postInit/main.groovy (默认提供的脚本实例文件)

## Groovy log

所有与groovy有关的东西都有自己的日志, 而且会生成自己的文件.
如果你的脚本写出了问题, 你应该先看看Log. 文件位于[Minecraft实例路径]/groovy.log

## 运行配置
这个文件定义了每个脚本文件应该如何执行, 在哪个加载阶段执行.
它也可以存储一些关于MOD包的一般信息.
如果该文件无法被查找到或不存在, 将重新生成一份.
如果你不明白这是什么或 "它是如何工作的" , 你可以跳过配置.
你所需要知道的是, 你把你的配方脚本放在groovy/postInit中.
诸如 "自定义物品" 之类的脚本则放在groovy/preInit中.
(类似KubeJS的start_scripts-preInit和server_scripts-postInit)
让我们看看这个文件是什么样子的.

````json
{
"packName": "",
"packId": "",
"version": "1.0.0",
"debug": false,
"classes": [
"classes/"
],
"loaders": {
"preInit": [
"preInit/"
],
"postInit": [
"postInit2/"
]
}
}
````

Let's go through it bit by bit: <br>

- `packName` is the name of the pack (See [pack name and id](#pack-name-and-id)). Important
for [content](groovyscript/content/content.md). <br>
- `packId` (0.4.0+) is the id of the pack (See [pack name and id](#pack-name-and-id)). Important
for [content](groovyscript/content/content.md). <br>
- `version` is the version of the pack. It currently doesn't do anything special. <br>
- `debug`: If this is false all messages that logged to debug will not be logged. Great for debugging. <br>
- `classes`: (0.3.0+) Files that contain a single class should be specified here. It makes sure classes are loaded when
scripts try to access them. <br>
- `loaders`: This defines at what stage what files should be loaded. By default, there are two stages: `preInit`
and `postInit`. <br>
- `preInit` will run at an early stage. Do not register recipes here. Use it to register game objects like items and
blocks. <br>
- `postInit` will run right before JEI loads. Use it to register recipes for example. When GroovyScript gets reloaded
only this loader will run.<br>
Inside the square brackets of the loader we define the files or path that will be run. You can NOT run a file in
multiple loaders.
Elements higher in the list will be run first. Files can be put multiple times, but they will only get executed
once. <br>
For example:

````json
[
"postInit/ore_dict.groovy",
"postInit/"
]
````

Here first `ore_dict.groovy` will be executed and then all files of `postInit/`, but since `ore_dict.groovy` was already
executed, it will not run now. <br>
Another example:

````json
[
"postInit/",
"postInit/late_stuff.groovy"
]
````

First everything in `postInit/` will be executed, but since `late_stuff.groovy` is specifically put later it will not be
executed. After that only `late_stuff.groovy` will be executed.

### Pack name and id

The pack name can be anything. It's the name that will show up in JEI in tooltips on items you created. <br>
The pack id is very important. It must only consist of lower case letters and `_`.

!!! warning
Changing the pack id will result in created items being lost in existing worlds!

## Important infos

1. Groovy scripts must end in `.groovy`
2. Groovy scripts must be defined somehow in the [run config](#run-config) to be executed
3. The scripts and folders can have any name
4. All scripts and the [run config](#run-config) must be located in `[Minecraft instance path]/groovy/`
62 changes: 62 additions & 0 deletions docs/zh/groovy/builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Builder

A builder is a class that contains methods to build an object. Those methods can be chained together and often end in a `.build()` call.
Each method, except the `build()` method, should return the same builder instance.
The Recipe Builders in GroovyScript and with a `.register()` call, because the recipe is registered rather than just build and `.buildAndRegister()` is too long.

## Builder class example
Let's see what a simple Builder class can look like:

```groovy
class RecipeBuilder {
private final List<IIngredient> inputs = new ArrayList()
private final List<ItemStack> outputs = new ArrayList() // (1)

RecipeBuilder input(IIngredient ingredient) {
this.inputs.add(ingredient)
return this // the method returns this builder (2)
}

RecipeBuilder output(ItemStack itemStack) {
this.outputs.add(itemStack)
return this // the method returns this builder (3)
}

Recipe build() { // the build method usually returns the object that will be build
return new Recipe(inputs, outputs)
}
}
```

1. We need to store our inputs and outputs somewhere
2. Usually the return keyword is not needed in groovy, but in this case it helps to understand the concept.
3. Usually the return keyword is not needed in groovy, but in this case it helps to understand the concept.

## Usage example
Now let's create a new recipe using the builder
````groovy
def recipe = new RecipeBuilder() // first create a recipe builder instance
.input('<minecraft:iron_ingot>') // add a input
.input('<minecraft:clay_ball>' * 3) // add another input
.output('<minecraft:nether_star>') // add a output
.build() // build and return a recipe instance
````

Notice how each method call is chained together. This is because `input()` and `output()` return the same builder instance.<br>
Since the `build()` method returns a `Recipe` instance, the `recipe` variable will also be of type `Recipe`.<br>
The same code as above can also be put in a single line:
````groovy
def recipe = new RecipeBuilder().input('<minecraft:iron_ingot>').input('<minecraft:clay_ball>' * 3).output('<minecraft:nether_star>').build()
````
This does exactly the same thing, but as you can see it is uglier and harder to read. The line breaks are purely aesthetically, but are highly recommended.

Now lets see what the recipe could look like without a builder:
````groovy
def recipe = new Recipe(['<minecraft:iron_ingot>', '<minecraft:clay_ball>' * 3], ['<minecraft:nether_star>'])
````
That doesn't look too bad right? Now imagine the recipe requires 5 inputs. Or 10. Or 20. And you need to specify energy requirement, duration and maybe fluids.<br>
This is where Builders shine.

## Conclusion
Builders help to produce clean code while creating complex objects.
Understanding the concept will help you in GroovyScript, since they are used commonly for recipes.
52 changes: 52 additions & 0 deletions docs/zh/groovy/closure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Closures

Closures are like lambdas in java, but slightly different.

# For beginners

You may know what a method is. A method is a set order of instructions you can call. For example:

````groovy
def print_numbers(int n) {
for (def i : 0..n) {
log.info(i)
}
}
````

This method prints numbers from 0 to a given number to the log.

````groovy
print_numbers(5)
````

This will now output

````
0
1
2
3
4
````

You can call that method as often as you want with any number input.

Now closures are methods, but you can carry them around. Example:

````groovy
def print_numbers = { int n -> /*(1)*/
for (def i : 0..n) {
log.info(i)
}
}
````

1. Most of the time the type is optional, so here it would become `{ n -> ...`

This closure does the same thing as the method above, but it's a variable instead of a method. Just like any other
variable you can pass it to other methods. (See [Events](../groovyscript/minecraft/events/aa_events.md)).
You can invoke this closure the same way you do with a method:
````groovy
print_numbers(3)
````
Loading