Skip to content

Commit 79e54f9

Browse files
committed
翻译
1 parent 3a78533 commit 79e54f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+444
-301
lines changed

docs/.vitepress/sidebar.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const sidebar: DefaultTheme.Sidebar = {
137137
link: "/zh/quickstart/08nbt/03dict",
138138
},
139139
{
140-
text: "MAP",
140+
text: "Map",
141141
link: "/zh/quickstart/08nbt/04map",
142142
}
143143
],
@@ -155,7 +155,7 @@ export const sidebar: DefaultTheme.Sidebar = {
155155
},
156156
{
157157
text: "特殊类型",
158-
link: "/zh/quickstart/09template/03mort-type",
158+
link: "/zh/quickstart/09template/03sp-type",
159159
},
160160
{
161161
text: "类型委托",
@@ -209,6 +209,15 @@ export const sidebar: DefaultTheme.Sidebar = {
209209
link: "/zh/quickstart/12gradle/01gradle-configuration",
210210
}
211211
],
212+
},
213+
{
214+
text: "文档注释",
215+
"items": [
216+
{
217+
text: "文档注释",
218+
link: "/zh/quickstart/13doc/01doc-comment",
219+
}
220+
],
212221
}
213222
],
214223
"/en/quickstart/": [
@@ -360,9 +369,13 @@ export const sidebar: DefaultTheme.Sidebar = {
360369
link: "/en/quickstart/09template/02template-nest",
361370
},
362371
{
363-
text: "Special Types in Data Templates",
364-
link: "/en/quickstart/09template/03mort-type",
365-
}
372+
text: "Special Types",
373+
link: "/en/quickstart/09template/03sp-type",
374+
},
375+
{
376+
text: "Type Delegate",
377+
link: "/en/quickstart/09template/04type-as",
378+
},
366379
],
367380
},
368381
{
@@ -411,6 +424,15 @@ export const sidebar: DefaultTheme.Sidebar = {
411424
link: "/en/quickstart/12gradle/01gradle-configuration",
412425
}
413426
],
427+
},
428+
{
429+
text: "Documentation",
430+
"items": [
431+
{
432+
text: "Doc Comments",
433+
link: "/en/quickstart/13doc/01doc-comment",
434+
}
435+
],
414436
}
415437
],
416438
};

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

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,91 @@ This command compiles `example.mcfpp` into a data pack and outputs it to the `D:
3838

3939
## Building with Gradle
4040

41-
TODO
41+
:::warning
42+
This content has been translated by AI. We welcome native speakers to help improve the translation.
43+
:::
44+
45+
The Gradle-based MCFPP project has additional feature support.
46+
47+
:::tip
48+
This example uses IntelliJ IDEA and the Gradle DSL in Kotlin.
49+
50+
Example project: <https://github.com/MinecraftFunctionPlusPlus/MCFPP_Example>
51+
:::
52+
53+
To build an MCFPP project with Gradle, first create an empty Java or Kotlin project. MCFPP supports both, but since it’s written in Kotlin, using Kotlin gives a better development experience.
54+
55+
![alt text](image.png)
56+
57+
After the project is created and loaded, open `build.gradle.kts` and add MCFPP support as follows:
58+
59+
```kt
60+
plugins {
61+
// ...existing code
62+
// add the MCFPP plugin
63+
id("mcfpp-gradle") version "1.0.2-SNAPSHOT"
64+
}
65+
66+
repositories {
67+
// ...existing code
68+
// add repositories required by MCFPP and where MCFPP is hosted
69+
maven("https://nexus.mcfpp.top/repository/maven-public/")
70+
maven("https://jitpack.io")
71+
maven("https://maven.aliyun.com/nexus/content/groups/public/")
72+
maven("https://libraries.minecraft.net")
73+
}
74+
75+
group = "top.mcfpp"
76+
version = "1.0-SNAPSHOT"
77+
78+
dependencies {
79+
// ...existing code
80+
// add the MCFPP library. If you don't use MCFPP MNI you can omit this line
81+
implementation("top.mcfpp:mcfpp:1.0.2-SNAPSHOT")
82+
}
83+
```
84+
85+
Then open `settings.gradle.kts` and add:
86+
87+
```kt
88+
// add repositories for plugin dependencies and the plugin itself
89+
pluginManagement {
90+
repositories {
91+
maven("https://nexus.mcfpp.top/repository/maven-public/")
92+
maven("https://jitpack.io")
93+
maven("https://maven.aliyun.com/nexus/content/groups/public/")
94+
maven("https://libraries.minecraft.net")
95+
gradlePluginPortal()
96+
}
97+
}
98+
```
99+
100+
Reload the Gradle project. If everything is OK, you’ve successfully added MCFPP support to Gradle. MCFPP will by default read mcfpp files from src/main/mcfpp, so create that folder and write your MCFPP code there.
101+
102+
When using Gradle you don’t need to create project configuration JSON files. Instead you can configure MCFPP in build.gradle.kts using the mcfpp block:
103+
104+
```kt
105+
mcfpp {
106+
version = "1.21.4"
107+
description = "MCFPP Example Project"
108+
}
109+
```
110+
111+
This block sets the config field of the `Project` class. That field is an instance of[`ProjectConfig`](https://github.com/MinecraftFunctionPlusPlus/MCFPP/blob/kotlin-latest/src/main/kotlin/top/mcfpp/ProjectConfig.kt) and manages MCFPP project settings.
112+
113+
Field | Type | Default | Description
114+
-|-|-|-
115+
version | String | "1.21.8" | Minecraft version for the project. Only official releases supported (no snapshots).
116+
rootNamespace | String | "default" | Default namespace for the project.
117+
targetPath | java.nio.file.Path? | null | Output folder for the datapack. If null: when using a config file it's `$root/build/`, when using Gradle it's the Gradle build output `datapack` folder (usually `build/datapack`).
118+
commentLevel | top.mcfpp.command.CommandLevel | CommentLevel.DEBUG | Comment output level.
119+
root | java.nio.file.Path? | null | Project root. If null, it's the directory of the config JSON or the Gradle project root.
120+
name | String | "new_mcfpp_project" | Project name.
121+
description | String | "A new datapack" | Datapack description.
122+
includes | ArrayList<String> | ArrayList() | All referenced includes.
123+
jars | ArrayList<String> | ArrayList() | Paths to all jar files.
124+
sourcePath | java.nio.file.Path? | null | Root of MCFPP source. If null: when using a config file it's `$root`; with Gradle it's `src/main/mcfpp`.
125+
noDatapack | Boolean | false | Do not generate a datapack.
126+
copyImport | Boolean | true | Copy imported libraries when generating the datapack.
127+
128+
Finally, run the `mcfppCompile` task found under the `build` Gradle tasks to compile the project into a datapack.

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

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,117 @@
22
lastUpdated: true
33
---
44

5-
# Variable
5+
# Variables
66

7-
## Defination of variables
7+
:::warning
8+
This content has been translated by AI. We welcome native speakers to help improve the translation.
9+
:::
10+
11+
## Declaring variables
812

9-
Same as other languages, you can define some variables in MCFPP for store, transfer and process data.
13+
As in other languages, you can declare variables in MCFPP to store, pass and process data.
1014

11-
The defination of data is like this:
15+
Typical declaration:
1216

1317
```mcfpp
14-
#<type> <identifier> [= <expression>]
15-
int i = 5;
16-
int b = i * 6;
18+
#var <identifier> [as <type>] [= expression or value]
19+
var i as int = 5;
20+
var b as int = i * 6;
21+
22+
#type inferred
23+
var j = 5; # j is inferred as int
24+
var k = 5.0; # k is inferred as float
25+
var i; # [!code error] # error: missing initializer, cannot infer
1726
```
1827

19-
The identifier of variable can be the combination of any characters and numbers. In one scope, a name of variable only can defined once.
28+
Identifiers may contain letters and digits. In the same scope a name can be declared only once.
2029

21-
## Type of variable
30+
## Variable types
2231

23-
In MCFPP, variable have basic data type and combined data type. Basic data type is hard-coding and built-in, but combined data types, such as class, template and so on, can be determined by the developer themselves. So on, the basic types MCFPP have is shown here:
32+
MCFPP has primitive and composite types. Primitives are built-in; composite types (classes, templates, etc.) are user-defined. Current primitives:
2433

25-
| Type name | Type description | Example |
34+
|Type|Description|Example|
2635
|-|-|-|
27-
|int| The most basic data type, represent an integer |`1`,`114514`,`-5`|
28-
|float| Represent a single-precision floating-point |`2.5`,`1.0`,`9.5e6`|
29-
|bool| Represent a Boolean data |`true`,`false`|
30-
|nbt| Represents a NBT data |`"a":{"b":"c"}`,`"a":[1,2,3,4]`|
31-
|list| Represent a list |`[1,2,3,4]`,`["a","b","c"]`|
32-
|dict| Represent a dictionary |`{"a":1,"b":2,"c":3}`|
33-
|map|A high-level implement of dictionary, have much more functions than dictionary | Same as dictionary |
34-
|string| Represent a string |`"mcfpp"`,`"qwq"`|
35-
|text| Represents the raw json text |`"mcfpp"`,`{"text":"mcfpp","color":"#114514"}`|
36-
|entity| Represent an entity. Store the UUID of an entity | omit |
37-
|selector| Represent a entity selector |`@a`,`@p`|
38-
39-
There's a simple introduction for type, You can expand and view them one by one:
36+
|int|integer|`1`,`114514`,`-5`|
37+
|float|single-precision float|`2.5`,`1.0`,`9.5e6`|
38+
|bool|boolean|`true`,`false`|
39+
|nbt|NBT data|`"a":{"b":"c"}`,`"a":[1,2,3,4]`|
40+
|list|list|`[1,2,3,4]`,`["a","b","c"]`|
41+
|dict|dictionary|`{"a":1,"b":2,"c":3}`|
42+
|map|richer map with more features|same as above|
43+
|string|string (NBT string tag)|`"mcfpp"`,`"qwq"`|
44+
|text|text components|`"mcfpp"`,`{"text":"mcfpp","color":"#114514"}`|
45+
|entity|single entity (stores UUID)||
46+
|selector|target selector|`@a`,`@p`|
47+
48+
Brief descriptions (expandable):
4049

4150
::: details int
42-
**int** type is the most basic type in MCFPP, represent a integer. It can be positive, negative, zero. Also can be decimal , binary, octal and hexadecimal. An int type data will be stored as a score board variable, So it’s size is same as the score board.
51+
int is the basic integer type. It can be positive, negative, or zero, and supports decimal, binary, octal, hex, etc. int values are stored as scoreboard variables, so they have scoreboard size limits.
4352
:::
4453

4554
::: details float
46-
**float** type is a single-precision floating-point type in MCFPP. It can be positive, negative, zero. And also can be decimal, scientific notation and so on. The float calculation of MCFPP relies on [XiaoDou's MathLib](https:#github.com/xiaodou8593/math2.0). The calculation of float calculation is purely score board calculation, so the memory usage won’t be so big.
55+
A floatingpoint number with single precision. Supports decimal and scientific notation. MCFPP float ops rely on Xiaodou's math library. Float operations are implemented via scoreboard math and have modest overhead.
4756
:::
4857

4958
::: details bool
50-
**bool** type is a type of Boolean data in MCFPP. It only have two values: `true` and `false`. Bool type data would be stored as a score board variable, so it’s size is same as the score board.
59+
Boolean with values `true` or `false`. Stored as a scoreboard variable.
5160
:::
5261

5362
::: details nbt
54-
**nbt** type represent a NBT data. But in fact, most times NBT type data just stores a NBT path, so in fact it can be called as NBT Pointer. It’s worth mentioning, **nbt** type variables is the basic of most basic types. Like `list`, `map` are both archive by the NBT data operations.
63+
NBT data, often acting as an NBT pointer (stores an NBT path). Many composite types (list, map, etc.) are based on NBT operations.
5564
:::
5665

5766
::: details list
58-
**list** type represent a list, `list` type achieved most functions of `ArrayList` in Java, more details can read the API of the standard library. `list`would be stored as a NBT list.
67+
List type. Implements most ArrayList methods from Java; stored as an NBT list.
5968
:::
6069

6170
::: details dict
62-
**dict** type represent to a dictionary, which stored as a combined NBT tag. Because the limit of Minecraft, `dict` type only can insert and delete to basic key values, can’t iterating over an array. You can use `map` to have more operations.
71+
Dictionary stored as an NBT compound. Due to Minecraft limits, dict supports basic key insert/remove but not iteration. Use map for more operations.
6372
:::
6473

6574
::: details map
66-
**map** type high-level implement of `dict`, have much more functions than `dict`. `map` type achieve most functions of `HashMap` in Java, more details are in the API of the standard library. But it’s worth mentioning that the higher implement of `map` means `map` have more cost than `dict`.
75+
A richer wrapper over dict with more features (implements most HashMap methods). Provides more functionality at the cost of additional overhead.
6776
:::
6877

6978
::: details string
70-
Represent a string, which is a string tag in NBT.
79+
String type (NBT string tag).
7180
:::
7281

7382
::: details text
74-
Represent a raw JSON text, compared to `string` type, `text` type can contain more format information, such as color, bold and so on. `text` type data will be stored as a combined NBT tag.
83+
Raw JSON text. Unlike string, text can include formatting (color, bold, etc.). Stored as an NBT compound.
7584
:::
7685

7786
::: details entity
78-
Reference to a single entity. Stored as a UUID integer NBT array.
87+
Represents a single entity. Stored as a UUID integer NBT array.
7988
:::
8089

8190
::: details selector
82-
Represent a entity selector. Stored as a string.
91+
Represents a target selector. Stored as a string.
8392
:::
8493

85-
## `var`
86-
87-
Keyword `var` can be used to declare a variable, without specifying variable types. Compiler would infer the type of the variable by the initialization expression.
88-
89-
However, if we use `var` to declare a variable, then the initialization expression is necessary.
90-
91-
For example:
92-
93-
```mcfpp
94-
var i = 5; # type of i will be inferred as int
95-
var j = 5.0; # type of j will be inferred as float
96-
var i; # [!code error] # Error, there’s no initialization expression
97-
```
98-
9994
## Variable modifiers
10095

101-
Variable modifiers can used to represent the type of variables, including `dynamic`, `const`, `import`
96+
Modifiers express variable properties: dynamic, const.
10297

10398
- dynamic
10499

105-
During Compiling, If any variable has been defined as literal, like `int i = 5;`, compiler will optimize this variable, such as `i += 7` will record `i` as 12 but not compile as scoreboard command. And `dynamic` is used to represent the variable is always dynamic calculating during compilation, though it’s a literal. Such as `dynamic int i = 5;`, `i` will be seen as a dynamic variable during compilation, and won’t be optimized.
100+
If a variable is a literal (e.g. `int i = 5;`), the compiler may optimize it (e.g. `i += 7` becomes 12 at compile time instead of scoreboard commands). `dynamic` forces runtime/dynamic behavior even for literals. Example: `dynamic int i = 5;` will not be optimized away.
106101

107102
- const
108103

109-
`const` means a variable is always constant. That is, its value is given during compilation, and never changes. Such as `const int i = 5;`, `i` will be seem as constant during compiling. Constant is always static during compiling, and its value must be clear when we declare it, can’t assign after declaring.
110-
111-
- import
112-
113-
`import` means a variable is import variable, it’s value is imported from other place. Such as `import int i;`, `i` will be seen as import variable after compile. Often, variable only can be used after assignment, but if we use `import` modifier, Then variable can be used after declaration without assignment.
104+
`const` marks a compile-time constant whose value is fixed at compile time and cannot change. It must be initialized on declaration.
114105

115-
## Optimization of variables
106+
## Compile-time optimizations
116107

117-
During compilation , compiler will optimize to some known values. When a variable’s value be set as a literal, compiler would record it’s name, until lose track to this variable.
108+
The compiler tracks compile-time-known values and optimizes accordingly. When a variable is assigned a literal, the compiler remembers its value until tracking is lost.
118109

119110
```mcfpp
120-
int i = 5; # Compiler record it’s value is 5
121-
i += 7; # Compiler set i’s value as 12 directly, won’t output score board command
122-
int j = i; # Compiler also knows js value now
111+
var i = 5; # compiler records i = 5
112+
i += 7; # compiler treats i as 12; no scoreboard commands emitted
113+
var j = i; # compiler also knows j's value
123114
124-
import int x;
125-
j = x; # Compiler lose track to what j’s value actually is
126-
j += 1; # Compiler will output score board command
115+
dynamic var x as int;
116+
j = x; # compiler loses precise value for j
117+
j += 1; # compiler will emit scoreboard commands
127118
```

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,12 @@ do{
6464
}while (condition);
6565
```
6666

67-
## for statement
68-
69-
`for` statement is a more complex version of loop, it’s grammar is:
70-
71-
```mcfpp
72-
for (forinit; condition; forupdate){
73-
#code
74-
}
75-
```
76-
77-
`forinit` is an initialization expression, used to initialize loop variable. `condition` is a boolean expression, used to determine if the loop keeps going on. `forupdate` is a update expression, used to update the variable of the loop. `#code` represents the loop body, which is the code in the loop. The execute process of `for` is shown below:
78-
79-
1. Execute `forinit`, initialize the loop variable.
80-
2. Determine the value of `condition`, if the value of `condition` is `true`, execute `#code`, then execute `forupdate`, to update the loop variable, and determine the value of `condition` again.
81-
3. If the value of `condition` is `false`, exit the loop.
82-
83-
In `for` loop, the declaration of variable `forinit` only valid in the `for` loop.
84-
8567
## break and continue statement
8668

8769
`break` statement used to jump out the whole loop, `continue` statement used to skip the current loop. For example:
8870

8971
```mcfpp
90-
for (int i = 0; i < 10; i++){
72+
for (var i = 0; i < 10; i++){
9173
if (i == 5){
9274
break;
9375
}

0 commit comments

Comments
 (0)