Skip to content

Commit 035869e

Browse files
committed
mni新内容
1 parent abb13e1 commit 035869e

File tree

11 files changed

+464
-3
lines changed

11 files changed

+464
-3
lines changed

docs/.vitepress/config.mts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
// https://vitepress.dev/reference/default-theme-config
1010
nav: [
1111
{ text: 'Home', link: '/' },
12-
{ text: 'Examples', link: '/markdown-examples' }
12+
{ text: 'QuickStart', link: '/quick-start' }
1313
],
1414

1515
search: {
@@ -25,16 +25,41 @@ export default defineConfig({
2525
]
2626
},
2727

28+
vite: {
29+
build: {
30+
rollupOptions: {
31+
input: {
32+
main: 'index.html',
33+
dokka: '/mcfppdocs/index.html'
34+
}
35+
}
36+
}
37+
},
38+
2839
locales: {
2940
root: {
3041
label: '简体中文',
3142
lang: 'zh',
32-
link: '/zh/'
43+
link: '/zh/',
44+
themeConfig: {
45+
nav: [
46+
{ text: '主页', link: '/zh/' },
47+
{ text: '快速开始', link: '/zh/quickstart/index' },
48+
{ text: '文档', link: '/mcfppdocs/index.html' }
49+
]
50+
}
3351
},
3452
en : {
3553
label: 'English',
3654
lang: 'en',
37-
link: '/en/'
55+
link: '/en/',
56+
themeConfig: {
57+
nav: [
58+
{ text: 'Home', link: '/en/' },
59+
{ text: 'QuickStart', link: '/en/quickstart/index' },
60+
{ text: 'Docs', link: '/mcfppdocs/index.html' }
61+
]
62+
}
3863
}
3964
}
4065
})

docs/.vitepress/sidebar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ export const sidebar: DefaultTheme.Sidebar = {
182182
{
183183
text: "注解",
184184
link: "/zh/quickstart/11mni/04annotation",
185+
},
186+
{
187+
text: "JVM访问符",
188+
link: "/zh/quickstart/11mni/05access",
185189
}
186190
],
187191
},
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# public @interface InsertCommand<Badge type="tip">已废弃</Badge>
2+
3+
```java
4+
package top.mcfpp.annotations;
5+
6+
import java.lang.annotation.ElementType;
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.RetentionPolicy;
9+
import java.lang.annotation.Target;
10+
11+
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
12+
@Retention(RetentionPolicy.RUNTIME)
13+
public @interface InsertCommand {
14+
}
15+
```
16+
17+
InsertCommand类用来标记一个JVM方法是否调用了`Function.addCommand`方法,也就是是否往一个函数里面添加了命令。由于Java和Kotlin之间的注解并不互通,因此此注解实际已经废弃。
18+
19+
## 函数格式
20+
21+
这个注解对函数格式没有要求。

docs/zh/api/annotation/mniaccessor.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# public @interface MNIAccessor
2+
3+
```java
4+
package top.mcfpp.annotations;
5+
6+
public @interface MNIAccessor {
7+
8+
/**
9+
* 访问器的名称
10+
*/
11+
String name();
12+
}
13+
```
14+
15+
这个方法用于标记一个Java方法是否是一个Native访问器。
16+
17+
::: info
18+
19+
在mcfpp中定义Native访问器:
20+
21+
```mcfpp
22+
data BossBar{
23+
#...
24+
25+
int max { get = top.mcfpp.mni.minecraft.BossBarData; };
26+
27+
#...
28+
}
29+
```
30+
31+
在Java中实现Native访问器:
32+
33+
```java
34+
package top.mcfpp.mni.minecraft;
35+
36+
//import ...
37+
38+
public class BossBarData {
39+
@MNIAccessor(name = "max")
40+
public static void getMax(DataTemplateObject bossbar, ValueWrapper<MCInt> returnValue){
41+
//具体的实现
42+
}
43+
}
44+
```
45+
46+
:::
47+
48+
## 函数格式
49+
50+
### 定义要求
51+
52+
|静态|需要为静态|
53+
|返回值|无要求|
54+
|标识符|无要求,但是建议为`getXXX`的形式|
55+
56+
### 参数要求
57+
58+
|参数类型|描述|
59+
|-|-|
60+
|`DataTemplateObject`|这个访问器所在的数据模板对象|
61+
|`ValueWrapper<T extends Var<?>>`|访问器获取到的变量,类型为T|

docs/zh/api/annotation/mnifunction.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# public @interface MNIFunction
2+
3+
```java
4+
package top.mcfpp.annotations;
5+
6+
//import ...
7+
8+
@Target({ElementType.METHOD})
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface MNIFunction {
11+
12+
/**
13+
* 只读参数。格式是类型+空格+参数名
14+
*/
15+
String[] readOnlyParams() default {};
16+
17+
/**
18+
* 普通参数。格式是类型+空格+参数名
19+
*/
20+
String[] normalParams() default {};
21+
22+
/**
23+
* 调用者类型。默认为void
24+
*/
25+
String caller() default "void";
26+
27+
/**
28+
* 函数的返回类型。默认为void
29+
*/
30+
String returnType() default "void";
31+
32+
/**
33+
* 是否重写了父类中的函数。默认为false
34+
*/
35+
boolean override() default false;
36+
37+
/**
38+
* 是否是单例对象
39+
*/
40+
boolean isObject() default false;
41+
42+
}
43+
```
44+
45+
这个方法用于标记一个Java方法是否是一个MNINative函数。
46+
47+
::: info
48+
在mcfpp中定义MNINative函数:
49+
50+
```mcfpp
51+
func print(text t) = top.mcfpp.mni.System.print;
52+
```
53+
54+
在java中实现MNINative函数:
55+
56+
```java
57+
package top.mcfpp.mni;
58+
59+
//import ...
60+
61+
public class System {
62+
63+
@InsertCommand
64+
@MNIFunction(normalParams = {"text t"})
65+
public static void print(@NotNull JsonText text){
66+
if(text instanceof JsonTextConcrete textC){
67+
Function.Companion.addCommand(new Command("tellraw @a").build(textC.getValue().toCommandPart(), true));
68+
}else {
69+
Function.Companion.addCommand(new Command("tellraw @a").build(text.toCommandPart(), true));
70+
}
71+
}
72+
73+
}
74+
```
75+
:::
76+
77+
## 函数格式
78+
79+
### 定义要求
80+
81+
|静态|需要为静态|
82+
|返回值|无要求|
83+
|标识符|无要求。使用`getNativeFromClass`方法获取函数时,mcfpp函数的标识符和java标识符相对一致。|
84+
85+
### 参数要求
86+
87+
|参数类型|描述|、
88+
|-|-|
89+
|(可选)`T extends Var<?>...`|这个函数的只读参数列表。需要按照定义顺序。|
90+
|(可选)`T extends Var<?>...`|这个函数的普通参数列表。需要按照定义顺序。|
91+
|(可选)`T extends Var<?>`|这个函数的调用者。|
92+
|(可选)`ValueWrapper<T>`|这个函数的返回值。|

docs/zh/api/annotation/mnimember.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# public @interface MNIMember
2+
3+
```java
4+
package top.mcfpp.annotations;
5+
6+
public @interface MNIMember {}
7+
```
8+
9+
此方法用于在调用`getNativeFromClass`方法的过程中,标记一个Java方法能够用于向当前的复合数据类型变量中添加成员(变量、函数等。)
10+
11+
::: info
12+
13+
在java中使用:
14+
15+
```java
16+
17+
@MNIMember
18+
public static ArrayList<Var<?>> getMembers() {
19+
NormalCompoundDataObject attributes = new NormalCompoundDataObject("attributes", Map.of());
20+
CompoundData attributeData = new CompoundData("attribute", "mcfpp.hidden");
21+
attributeData.getNativeFromClass(AttributeData.class);
22+
attributes.getData().addMember(new NormalCompoundDataObject(attributeData, "armor", Map.of()));
23+
return new ArrayList<>(List.of(attributes));
24+
}
25+
26+
```
27+
28+
:::
29+
30+
## 函数格式
31+
32+
### 定义要求
33+
34+
|静态|需要为静态|
35+
|返回值|`ArrayList<Var<?>>`|
36+
|标识符|`getMembers()`|
37+
38+
### 参数要求
39+
40+
参数列表为空。

docs/zh/api/annotation/mnimutator.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# public @interface MNIMutator
2+
3+
```java
4+
package top.mcfpp.annotations;
5+
6+
public @interface MNIMutator {
7+
8+
/**
9+
* 操作器的名称
10+
*/
11+
String name();
12+
}
13+
```
14+
15+
这个方法用于标记一个Java方法是否是一个Native操作器。
16+
17+
::: info
18+
19+
在mcfpp中定义Native操作器:
20+
21+
```mcfpp
22+
data BossBar{
23+
#...
24+
25+
int max { set = top.mcfpp.mni.minecraft.BossBarData; };
26+
27+
#...
28+
}
29+
```
30+
31+
在Java中实现Native操作器:
32+
33+
```java
34+
package top.mcfpp.mni.minecraft;
35+
36+
//import ...
37+
38+
public class BossBarData {
39+
@MNIMutator(name = "max")
40+
public static void setMax(DataTemplateObject bossbar, MCInt value){
41+
//具体的实现
42+
}
43+
}
44+
```
45+
46+
:::
47+
48+
## 函数格式
49+
50+
### 定义要求
51+
52+
|静态|需要为静态|
53+
|返回值|无要求|
54+
|标识符|无要求,但是建议为`setXXX`的形式|
55+
56+
### 参数要求
57+
58+
|参数类型|描述|
59+
|-|-|
60+
|`DataTemplateObject`|这个操作器所在的数据模板对象|
61+
|`T extends Var<?>`|传入操作器的变量|

docs/zh/api/class/command.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# class Command
2+
3+
top.mcfpp.command
4+
5+
## 概述
6+
7+
一条命令。在MCFPP编译过程中,一条命令可能会被分为多个命令片段,由接口`ICommandPart`实现。一个`Command`对象可以包含多个`CommandPart`对象。命令中的片段可以被字符串标签标记,从而能够对命令的某些片段进行替换操作。
8+
9+
要开始构建一个命令,可以使用`Command`的伴随对象中的`Command.build`方法,或者使用`Command(String)`构造函数。此后,可以继续通过链式调用成员方法`build(String)`或者`build(Command)`来添加命令片段,或者使用`build(command:String, pointID: String)`来在添加命令片段的同时,标记该片段的替换标签为`pointID`
10+
11+
对于宏命令而言,可以使用成员方法`buildMacro(id: Var<*>)`来构建一个宏命令,其中`id`代表的变量就是要传递给宏的变量。随后,构建出的宏命令需要再使用`buildMacroFunction`方法将宏命令转换为宏函数来调用,从而提高宏命令的效率。此方法将会返回一个新的`Command`对象,即调用此宏函数的命令。
12+
13+
要替换命令中的一些片段,可以使用成员方法`replace(pointID: String, target: String)`或者`replace(pointID: String, target: Command)`。它将会把标记为`pointID`的片段替换为`target`
14+
15+
## 例子
16+
17+
```kotlin
18+
fun sbPlayerOperation(a: MCInt, operation: String, b: MCInt): Command {
19+
return Command.build("scoreboard players operation")
20+
.build(a.name,a.name)
21+
.build(a.sbObject.toString(),a.sbObject.toString())
22+
.build(operation,"operation")
23+
.build(b.name,b.name)
24+
.build(b.sbObject.toString(),b.sbObject.toString())
25+
}
26+
```
27+
28+
```kotlin
29+
class XPredicate(val x: MCInt): EntitySelectorPredicate {
30+
override fun toCommandPart(): Command {
31+
return if(x is MCIntConcrete){
32+
Command.build("x=${x.value}")
33+
}else{
34+
Command.build("x=").buildMacro(x, false)
35+
}
36+
}
37+
38+
override fun isConcrete(): Boolean = x is MCIntConcrete
39+
}
40+
```
41+
42+
```java
43+
public static void print(@NotNull JsonText text){
44+
if(text instanceof JsonTextConcrete textC){
45+
Function.Companion.addCommand(new Command("tellraw @a").build(textC.getValue().toCommandPart(), true));
46+
}else {
47+
Function.Companion.addCommand(new Command("tellraw @a").build(text.toCommandPart(), true));
48+
}
49+
}
50+
```

docs/zh/api/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# API 文档
2+
3+
本文档提供了MCFPP编译器开发的基本信息。如果你需要进行MNI框架开发或者对编译器进行拓展开发,你可以参考MCFPP的Kotlin文档或者此文档。注意,此文档并非教程,可能包含大量技术性内容。如果你想要了解MNI框架,请参阅快速开始中的MNI章节。
4+

0 commit comments

Comments
 (0)