Skip to content

Commit 9af2514

Browse files
committed
更新文档,修正注释和示例,添加新功能说明
1 parent 9850e05 commit 9af2514

29 files changed

+238
-65
lines changed

docs/en/quickstart/01project/01create-project.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,40 @@
22
lastUpdated: true
33
---
44

5-
# Create a Project
5+
# Getting Started
66

7-
TODO
7+
MCFPP currently offers two usage methods: directly using the command line or building with Gradle. For simple functionalities, the command line is recommended. Gradle provides more extensive support, such as MNI.
8+
9+
## Compiling with Command Line
10+
11+
You can download the latest version of the MCFPP compiler from the release page on [GitHub](https://github.com/MinecraftFunctionPlusPlus/MCFPP/releases), which should be a Jar file. MCFPP requires Java 21 or higher. You can place it anywhere as long as you can locate it in the command line.
12+
13+
First, create a project folder and a project configuration file. You can find the detailed format of the project configuration file in the next section. In this example, we create an `example.json` as the project configuration file.
14+
15+
```json
16+
{
17+
"description": "",
18+
"namespace": "mcfpp",
19+
"targetPath": "D:\\.minecraft\\saves\\MCFPP Example\\datapacks"
20+
}
21+
```
22+
23+
Next, create a simple mcfpp file, such as `example.mcfpp`:
24+
25+
```mcfpp
26+
func hello(){
27+
print("Hello World");
28+
}
29+
```
30+
31+
Then, compile the project using the command line:
32+
33+
```shell
34+
java -jar mcfpp.jar example.json
35+
```
36+
37+
This command compiles `example.mcfpp` into a data pack and outputs it to the `D:\.minecraft\saves\MCFPP Example\datapacks` directory. You can then load the data pack in the game and run `function mcfpp:hello` to see the effect.
38+
39+
## Building with Gradle
40+
41+
TODO

docs/en/quickstart/01project/02config-file.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,27 @@ The project configuration file for MCFPP is a JSON file, typically stored in the
88

99
```json
1010
{
11-
// List of project file paths. Use wildcard symbols to select all files.
12-
"files": [
13-
"src/main/mcfpp/**"
14-
],
11+
// The target Minecraft version to compile for. Only official version numbers are supported.
12+
"version": "1.21.4",
1513
// The source code directory of the project. The namespace of the files is determined by their relative path to the source code directory.
16-
"sourcePath": "src/main/mcfpp",
14+
"sourcePath": "src/main/mcfpp/**",
1715
// Description of the datapack. This is a raw JSON text.
1816
"description": "",
1917
// The default namespace for the datapack, which will determine the namespace for datas, for instance storage in the package.
2018
"namespace": "test",
19+
// The jar-packaged libraries to be called.
20+
"jar": [],
2121
// The output path for the datapack. The datapack and library files will be output to this directory.
22-
"targetPath": "src/main/resources/lib",
22+
"targetPath": "build",
2323
// Whether to *not* generate a datapack. Default is false.
2424
"noDatapack": false,
25-
// Whether to *ignore* the standard library. Default is false. If set to true, the MCFPP standard library will not be referenced.
26-
"ignoreStdLib": false,
27-
// Whether it is a library. Default is false. Libraries do not need to have an entry function.
28-
"isLib": false
25+
// Compilation arguments
26+
"compileArgs": [
27+
// Compile in debug mode (for compiler development)
28+
"-debug",
29+
// Ignore the standard library
30+
"-ignoreStdLib",
31+
// Whether it is a library
32+
"-isLib"
33+
]
2934
}

docs/en/quickstart/02base/02comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ This is a document comment
3838
}#
3939
```
4040

41-
Document comment can include some special tags used to tag the content of the comment. Details in the Document chapter (TODO).
41+
Document comment can include some special tags used to tag the content of the comment. Details in the [Document](../13doc/01doc-comment.md)

docs/en/quickstart/02base/03logic-statements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ for (int i = 0; i < 10; i++){
100100

101101
In this example, when the value of `i` is `5`, `break`will jump out of the loop; when the value of `i` is `3`, `continue` will jump this loop, go to the next loop directly. So, the change of I in each loop are:`0``1``2``4``5`, and finally jump out.
102102

103-
`break` and `continue` statement only can be used in the loop
103+
`break` and `continue` only can be used in the loop

docs/en/quickstart/02base/04top-statements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
lastUpdated: true
33
---
44

5-
# Top statement<Badge type="warning">May Change</Badge>
5+
# Top statement<Badge type="tip">Future Feature</Badge>
66

77
MCFPP allows programming statements at the start of the file and don't need to define any function, that's the top statement. Top statement places in a hidden function, each file have one and only one of this function, and it cannot be called externally. Its returned value’s type is `void`.
88

docs/en/quickstart/02base/05original-command.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ func test(){
2929
```
3030

3131
This will insert the raw text from the `insert` function's parameter into the `test` function. It's important to note that the `insert` function's parameter is a string, so you can insert any content. This also means that the compiler will not perform any checks on the command format.
32+
33+
## Command Interpolation
34+
35+
See [JVM Accessors](../11mni/05access.md) for more information.

docs/en/quickstart/04function/01define-and-call.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ lastUpdate: true
44

55
# Define and call
66

7-
The way of define function in MCFPP has some differences with C/Java, and more similar to the grammar of Python.
8-
97
## Function definition
108

119
In MCFPP, the grammar of define a function is shown below:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
lastUpdate: true
3+
---
4+
5+
# Miscellaneous
6+
7+
## Base Entity
8+
9+
In the example at the beginning of this chapter, you may have noticed the line `@Base<"creeper">`. This line of code is called an **annotation**, which we will discuss in later chapters. Using the `@Base<"creeper">` annotation on the line before the class definition specifies which entity this entity template is based on. This entity is the base entity.
10+
11+
Generally, most entities cannot store custom data well directly, so when the base entity is not `item_display` or `marker`, a `marker` entity will ride on this entity to store the custom fields of the entity template.
12+
13+
The base entity has the tag `<namespace>_class_<classname>_pointer`, while the entity used to store data has the tag `<namespace>_class_<classname>_pointer_data`.
14+
15+
::: info
16+
After 24w10a, all entities can store custom data through the `minecraft:custom_data` entity component. This means that in future versions of mcfpp, classes composed of any type of base entity will store data uniformly in the `minecraft:custom_data` component.
17+
:::
18+
19+
## Lifecycle of Entity Templates
20+
21+
The lifecycle of an entity template is consistent with that of the base entity. When the base entity is removed, the entity template is also removed. This process is automatically handled by the garbage collector (GC).
22+
23+
Of course, you can manually release memory using the `dispose` function <Badge type="tip">Future Feature</Badge>:
24+
25+
```mcfpp
26+
27+
SuperCreeper p = SuperCreeper("Super Creeper");
28+
29+
p.dispose();
30+
31+
```

docs/en/quickstart/08nbt/02list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The MCFPP standard library provides a series of functions for list operations.
4141
| `addAll` | `list<T> elements` | `void` | Adds a group of elements to the list |
4242
| `insert` | `int index, T element` | `void` | Inserts an element at a specified position |
4343
| `removeAt` | `int index` | `void` | Removes the element at the specified position |
44+
| `remove` | `T element` | `void` | Removes the specified element |
4445
| `indexOf` | `T element` | `int` | Returns the index of the specified element |
4546
| `lastIndexOf` | `T element` | `int` | Returns the last index of the specified element |
4647
| `contains` | `T element` | `bool` | Checks if the list contains the specified element |

docs/en/quickstart/08nbt/03dict.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ Dictionaries cannot be iterated over, and you cannot retrieve a list of keys or
4545
| `containsKey` | `string key` | `bool` | Checks if the dictionary contains a specified key |
4646
| `merge` | `dict dict` | `void` | Merges two dictionaries |
4747
| `remove` | `string key` | `void` | Removes the key-value pair for the specified key |
48+
| `clear` | `void` | `void` | Clears the dictionary |

docs/en/quickstart/08nbt/04map.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ The MCFPP standard library provides a series of functions to manipulate `map`.
3232
| `containsKey` | `string key` | `bool` | Checks if the `map` contains the specified key |
3333
| `containsValue` | `T value` | `bool` | Checks if the `map` contains the specified value |
3434
| `isEmpty` | `void` | `bool` | Checks if the `map` is empty |
35-
| `getKeys` | `void` | `list<string>` | Retrieves all keys in the `map` |
36-
| `getValues` | `void` | `list<T>` | Retrieves all values in the `map` |
3735
| `remove` | `string key` | `void` | Removes the key-value pair for the specified key |
3836
| `merge` | `map<T> map` | `void` | Merges two `maps` |
3937
| `size` | `void` | `int` | Returns the size of the `map` |
4038

39+
As well as some properties:
40+
41+
| Property Name | Type | Description|
42+
| --- | --- | --- |
43+
| `keys`| `string`| Gets all the keys in the `map`|
44+
4145
## map Traversal <Badge type="tip" text="Future Feature" />
4246

4347
You can use the `foreach` loop to easily traverse all key-value pairs in a `map`.
@@ -81,9 +85,8 @@ When stored, the structure of the `map` would look like this:
8185
namespace.stack_frame:[
8286
{
8387
m:{
84-
key:["qwq","owo","nya"], // Key list
85-
value:["pwp","uwu","meow"], // Value list
86-
data:{
88+
keys:["qwq","owo","nya"], // Key list
89+
keyValueSet:{
8790
"qwq":"pwp","owo":"uwu","nya":"meow" // Key-value pairs, similar to a dict
8891
}
8992
}

docs/en/quickstart/09template/02template-nest.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,15 @@ func main(){
4141
```
4242

4343
Apparently, using the same type as a member within a Data Template is not allowed.
44+
45+
## Anonymous Definition
46+
47+
In a Data Template, an anonymous Data Template can be defined as a member type:
48+
49+
```mcfpp
50+
data B{
51+
int valueB;
52+
data{
53+
int valueA;
54+
} dataA;
55+
}

docs/en/quickstart/11mni/01mni-framework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ public class System extends MNIMethodContainer {
4949
}
5050
```
5151

52-
In the following sections, we will discuss in detail how to use the MNI framework.
52+
In the following sections, we will discuss in detail how to use the MNI framework.

docs/en/quickstart/11mni/04annotation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
lastUpdate: true
33
---
44

5-
# Annotations <Badge type="tip">WIP</Badge>
5+
# Annotations
66

77
You can add annotations to classes, data templates, and method declarations by using the `@` symbol followed by the annotation name and a read-only parameter list. Annotations are part of the MNI framework and only exist during the compilation phase.
88

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
lastUpdated: true
3+
---
4+
5+
# Documentation Comments <Badge type="tip">Future Feature</Badge>
6+
7+
As the third type of comment in MCFPP, documentation comments can be used to automatically generate documentation for your project. MCFPP's documentation comments are a mix of tag syntax and Markdown. You can use tag comments to provide necessary key information and Markdown to write detailed documentation.
8+
9+
## Syntax
10+
11+
Documentation comments start with `#{` and end with `#}`, with the content in between being the documentation comment. Each line of the documentation comment can start with `#`, which will not be considered part of the comment.
12+
13+
Tag comments must be written before the Markdown content.
14+
15+
Documentation comments can be written above any declaration, but local variable documentation comments will not be extracted into the generated documentation and are only used for IDE hints.
16+
17+
Here is an example of a documentation comment:
18+
19+
```mcfpp
20+
21+
#{
22+
@base Creeper
23+
24+
Implementation class for Super Creeper
25+
}#
26+
@Base<"creeper">
27+
class SuperCreeper{
28+
29+
#{
30+
List of effects the creeper will give
31+
}#
32+
list effectList = ["wither", "poison", "slowness", "hunger", "blindness", "weakness"];
33+
34+
#{
35+
@return A random effect
36+
37+
Get a random effect
38+
}#
39+
func getEffect() -> string {
40+
return effectList.random();
41+
}
42+
43+
override func tick(){
44+
if(@a[distance = 0..5].exist()){
45+
effect(@a[distance = 0..5], getEffect(), 1, 10);
46+
}
47+
}
48+
49+
}
50+
```
51+
52+
## Tags
53+
54+
Some tags can only be used for entity templates, some only for functions, some only for variables or members, and some are general.
55+
56+
### General Tags
57+
58+
- `@see Reference`: Specifies a reference document.
59+
- `@since Version`: Specifies the version from which it was introduced.
60+
- `@deprecated Version`: Specifies the version from which it was deprecated.
61+
- `@version Version`: Specifies the version number.
62+
- `@author Author`: Specifies the author.
63+
64+
### Entity Template Tags
65+
66+
- `@base Description`: Specifies the base entity.
67+
- `@param GenericParameterName Description`: Specifies the description of a generic parameter.
68+
69+
### Function Tags
70+
71+
- `@return Description`: Specifies the return value description.
72+
- `@throws Exception Description`: Specifies the description of thrown exceptions.
73+
- `@param Parameter Description`: Specifies the description of a parameter.
74+
- `@context <entity|pos|rotation|dimension> Description`: Specifies the context description, usually the execution environment of the function.

docs/zh/quickstart/01project/02config-file.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ MCFPP的工程配置文件是一个json文件,一般存放在这个工程的
1414
"sourcePath": "src/main/mcfpp/**",
1515
//数据包的描述。是一个原始JSON文本
1616
"description": "",
17-
//数据包的默认命名空间,将会决定数据包中storage等数据的命名空间
18-
"rootNamespace": "test",
17+
//数据包的默认命名空间
18+
"namespace": "test",
19+
//调用的jar包装的库
20+
"jar": [],
1921
//数据包的输出路径。数据包、库文件将会输出在此目录下
20-
"targetPath": "src/main/resources/lib",
22+
"targetPath": "build",
2123
//是否 *不* 生成数据包。默认为false
2224
"noDatapack": false,
23-
//是否 *忽略* 标准库。默认为false。如果为true,将不会引用mcfpp的标准库。
24-
"ignoreStdLib": false,
25-
//是否是库。默认为false。库不需要拥有一个入口函数
26-
"isLib": false,
27-
//生成注释的级别
28-
"commentLevel": "debug"
25+
//编译参数
26+
"compileArgs": [
27+
//以调试模式编译(用于编译器开发)
28+
"-debug",
29+
//是否忽略标准库
30+
"-ignoreStdLib",
31+
//是否是库
32+
"-isLib"
33+
]
2934
}
3035
```

docs/zh/quickstart/02base/01variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int i = 5; #编译器记住了这个变量的值为5
117117
i += 7; #编译器直接将i的值记为12,不会输出记分板命令
118118
int j = i; #编译器同样也知道了j的值
119119
120-
import int x;
120+
dynamic int x;
121121
j = x; #编译器丢失了对j具体值的跟踪
122122
j += 1; #编译器会输出记分板命令
123123
```

docs/zh/quickstart/02base/02comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ lastUpdated: true
3838
}#
3939
```
4040

41-
文档注释可以包含一些特殊的标签,用来标记注释的内容。详细参考文档章节
41+
文档注释可以包含一些特殊的标签,用来标记注释的内容。详细参考[文档](../13doc/01doc-comment.md)

docs/zh/quickstart/02base/03logic-statements.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,6 @@ do{
6464
}while (condition);
6565
```
6666

67-
## for语句
68-
69-
`for`语句是循环的一种稍复杂的版本,它的语法如下:
70-
71-
```mcfpp
72-
for (forinit; condition; forupdate){
73-
#code
74-
}
75-
```
76-
77-
`forinit`是一个初始化表达式,它用来初始化循环变量。`condition`是一个布尔表达式,它用来判断循环是否继续。`forupdate`是一个更新表达式,它用来更新循环变量。`#code`代表了循环体,即循环体中的代码。在运行的时候,`for`语句的执行过程如下:
78-
79-
1. 执行`forinit`,初始化循环变量。
80-
2. 判断`condition`的值,如果`condition`的值为`true`,则执行`#code`代表的代码块,然后执行`forupdate`,更新循环变量,再次判断`condition`的值。
81-
3. 如果`condition`的值为`false`,则退出循环。
82-
83-
`for`循环中,`forinit`声明的变量只在`for`循环中有效。
84-
8567
## break和continue语句
8668

8769
`break`语句用来跳出整个循环,`continue`语句用来跳过本次循环。例如:

docs/zh/quickstart/02base/04top-statements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
lastUpdated: true
33
---
44

5-
# 顶层语句<Badge type="warning">可能更改</Badge>
5+
# 顶层语句<Badge type="tip">未来特性</Badge>
66

77
在MCFPP中,允许在文件的开始直接编写语句而无需额外定义函数,即顶层语句。顶层语句处于一个隐式的函数中,这个函数每个文件有且只有一个,且不能被外部调用。它的返回值类型为`void`
88

docs/zh/quickstart/02base/05original-command.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ func test(){
2929
```
3030

3131
将会将`insert`参数中的原文插入到test函数中。值得注意的是,`insert`函数的参数是一个字符串,因此你可以在其中插入任何内容,这同时意味着编译器不会对命令格式进行任何检查。
32+
33+
## 命令插值
34+
35+
参见[JVM访问符](../11mni/05access.md)

docs/zh/quickstart/03namespace/01namespace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ func test(){ # test:test函数
1818

1919
一个文件中只能声明一次命名空间。
2020

21-
若没有声明命名空间,文件的命名空间将会由文件路径相对于源代码路径的相对路径决定。例如,假设源代码目录为`src/main/mcfpp`,那么文件`src/main/mcfpp/test/test.mcfpp`的命名空间将会是`test.test`。源代码路径通过工程配置文件中的`sourcePath`决定。
21+
若没有声明命名空间,文件的命名空间将会由文件路径相对于源代码路径的相对路径决定。例如,假设源代码目录为`src/main/mcfpp`项目命名空间为`test`那么文件`src/main/mcfpp/uwu/test.mcfpp`的命名空间将会是`test:uwu`。源代码路径通过工程配置文件中的`sourcePath`决定。

0 commit comments

Comments
 (0)