Skip to content

Commit e800817

Browse files
committed
list,dict和map的标准库函数
1 parent 254b441 commit e800817

Some content is hidden

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

42 files changed

+610
-111
lines changed
File renamed without changes.

mcfpp/lang/src/main/mcfpp/list/index_of.mcfpp

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#@param list 要检查的列表
2+
#@param element 要检查的元素
3+
4+
#list.index mcfpp_temp当前的索引
5+
#list.size mcfpp_temp列表的长度
6+
7+
#检查索引是否越界
8+
execute if score list.index mcfpp_temp >= list.size mcfpp_temp run return 0
9+
#检查第一个元素
10+
execute store success score #if_success mcfpp_temp run data modify storage mcfpp:system list.list[0] set from storage mcfpp:system list.element
11+
#如果元素符合
12+
execute unless score #if_success mcfpp_temp matches 1 run return 1
13+
#否则,检查第二个元素
14+
data remove storage mcfpp:system list.list[0]
15+
scoreboard players add list.index mcfpp_temp 1
16+
function mcfpp.lang:list/index_of
17+
return 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# @param list 要检查的列表
2+
# @param element 要检查的元素
3+
4+
# list.index mcfpp_temp当前的索引
5+
# list.size mcfpp_temp列表的长度
6+
7+
# 检查索引是否越界
8+
execute if score list.index mcfpp_temp >= list.size mcfpp_temp run return -1
9+
# 检查第一个元素
10+
execute store success score #if_success mcfpp_temp run data modify storage mcfpp:system list.list[0] set from storage mcfpp:system list.element
11+
# 如果元素符合
12+
execute unless score #if_success mcfpp_temp matches 1 run return run scoreboard players get list.index mcfpp_temp
13+
# 否则,检查第二个元素
14+
data remove storage mcfpp:system list.list[0]
15+
scoreboard players add list.index mcfpp_temp 1
16+
function mcfpp.lang:list/index_of
17+
return -1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#@param list 要检查的列表
2+
#@param element 要检查的元素
3+
4+
#list.last_index_of.index mcfpp_temp当前的索引
5+
#list.last_index_of.size mcfpp_temp列表的长度
6+
7+
#检查索引是否越界
8+
execute if score list.index mcfpp_temp >= list.size mcfpp_temp run return -1
9+
#检查第一个元素
10+
execute store success score #if_success mcfpp_temp run data modify storage mcfpp:system list.list[-1] set from storage mcfpp:system list.element
11+
#如果元素符合
12+
execute unless score #if_success mcfpp_temp matches 1 run return run scoreboard players get list.index mcfpp_temp
13+
#否则,检查第二个元素
14+
data remove storage mcfpp:system list.list[-1]
15+
scoreboard players add list.index mcfpp_temp 1
16+
function mcfpp.lang:list/last_index_of
17+
return -1
18+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"pack": {
3+
"pack_format": 50,
4+
"description": ""
5+
}
6+
}

src/main/antlr/mcfppLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ BOOL: 'bool';
118118
FLOAT: 'float';
119119
SELECTOR: 'selector';
120120
STRING: 'string';
121-
JTEXT: 'jtext';
121+
JTEXT: 'text';
122122
NBT: 'nbt';
123123
ANY: 'any';
124124
TYPE: 'type';

src/main/java/top/mcfpp/mni/MCAnyData.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import kotlin.jvm.functions.Function4;
44
import org.jetbrains.annotations.NotNull;
55
import top.mcfpp.annotations.MNIRegister;
6-
import top.mcfpp.lang.CanSelectMember;
7-
import top.mcfpp.lang.JavaVar;
8-
import top.mcfpp.lang.Var;
6+
import top.mcfpp.lang.*;
7+
import top.mcfpp.lib.ChatComponent;
8+
import top.mcfpp.lib.ListChatComponent;
9+
import top.mcfpp.lib.PlainChatComponent;
910
import top.mcfpp.model.function.Function;
1011
import top.mcfpp.model.function.MNIMethodContainer;
1112
import top.mcfpp.util.ValueWrapper;
@@ -19,4 +20,11 @@ public static void getJavaVar(@NotNull Var<?> value, ValueWrapper<Var<?>> return
1920
var re = new JavaVar(value, UUID.randomUUID().toString());
2021
returnValue.setValue(re);
2122
}
23+
24+
@MNIRegister(caller = "any", returnType = "text")
25+
public static void toText(@NotNull Var<?> caller, ValueWrapper<JsonTextConcrete> returnValue){
26+
var l = new ListChatComponent();
27+
l.getComponents().add(new PlainChatComponent(caller.toString()));
28+
returnValue.setValue(new JsonTextConcrete(l, "re"));
29+
}
2230
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package top.mcfpp.mni;
2+
3+
import top.mcfpp.annotations.MNIRegister;
4+
import top.mcfpp.lang.JsonTextConcrete;
5+
import top.mcfpp.lang.MCInt;
6+
import top.mcfpp.lang.MCIntConcrete;
7+
import top.mcfpp.lib.ListChatComponent;
8+
import top.mcfpp.lib.PlainChatComponent;
9+
import top.mcfpp.lib.ScoreChatComponent;
10+
import top.mcfpp.util.ValueWrapper;
11+
12+
public class MCIntConcreteData {
13+
14+
@MNIRegister(caller = "int", returnType = "text")
15+
public static void toText(MCIntConcrete caller, ValueWrapper<JsonTextConcrete> returnValue) {
16+
var l = new ListChatComponent();
17+
l.getComponents().add(new PlainChatComponent(caller.getValue().toString()));
18+
returnValue.setValue(new JsonTextConcrete(l, "re"));
19+
}
20+
}

src/main/java/top/mcfpp/mni/MCIntData.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
import top.mcfpp.annotations.MNIRegister;
44
import top.mcfpp.lang.JavaVar;
5+
import top.mcfpp.lang.JsonTextConcrete;
56
import top.mcfpp.lang.MCInt;
7+
import top.mcfpp.lib.ListChatComponent;
8+
import top.mcfpp.lib.ScoreChatComponent;
69
import top.mcfpp.model.function.Function;
710
import top.mcfpp.util.ValueWrapper;
811

912
public class MCIntData {
1013

11-
@MNIRegister(caller = "int")
12-
public static void test(MCInt caller) {
13-
Function.Companion.addCommand("say " + caller);
14-
}
15-
16-
@MNIRegister(normalParams = {"int i"}, caller = "int", returnType = "JavaVar")
17-
public static void qwq(MCInt i, MCInt caller, ValueWrapper<JavaVar> re){
18-
re.setValue(new JavaVar(caller, "qwq"));
19-
Function.Companion.addCommand("say i=" + i);
20-
Function.Companion.addCommand("say this=" + caller);
14+
@MNIRegister(caller = "int", returnType = "text")
15+
public static void toText(MCInt caller, ValueWrapper<JsonTextConcrete> returnValue) {
16+
var l = new ListChatComponent();
17+
l.getComponents().add(new ScoreChatComponent(caller));
18+
returnValue.setValue(new JsonTextConcrete(l, "re"));
2119
}
2220
}

0 commit comments

Comments
 (0)