Skip to content

Commit 2568b32

Browse files
committed
修复while的编译问题
1 parent 3730be5 commit 2568b32

File tree

6 files changed

+32
-14
lines changed

6 files changed

+32
-14
lines changed

.mclib

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"id":"default",
55
"functions":[
66
{
7-
"id":"base",
7+
"id":"generateSequence",
88
"normalParams":[
99

1010
],
@@ -15,7 +15,7 @@
1515
]
1616
},
1717
{
18-
"id":"_if_branch_ed5be6b6-1b8d-44c7-911d-9f257d1b8761",
18+
"id":"_while_1721ca59-7dd8-4e3b-b146-190ad749a4f2",
1919
"normalParams":[
2020

2121
],
@@ -26,7 +26,7 @@
2626
]
2727
},
2828
{
29-
"id":"expression_2b5d5e58-dff2-4c90-b43d-720c0f3baa42",
29+
"id":"expression_67b9dd31-2e5e-4873-a1a3-f4b5f0da11e2",
3030
"normalParams":[
3131

3232
],
@@ -37,7 +37,7 @@
3737
]
3838
},
3939
{
40-
"id":"_if_branch_c2e1e1ba-f3a4-48ce-9e2b-518a32dbacbb",
40+
"id":"_while_block_4b041b7f-b519-423e-82cf-f816f0d548a3",
4141
"normalParams":[
4242

4343
],

src/main/java/top/mcfpp/lang/NBTListData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ public class NBTListData extends MNIMethodContainer {
163163
command = new Command("data modify " +
164164
"entity @s " +
165165
"data." + list.getIdentifier() + " " +
166-
"insert ").build("", index.getIdentifier()).build (" value " + SNBTUtil.toSNBT(tag));
166+
"insert ").build("", index.getIdentifier()).build ("value " + SNBTUtil.toSNBT(tag));
167167
} else {
168168
command = new Command("data modify " +
169169
"storage mcfpp:system " +
170170
Project.INSTANCE.getCurrNamespace() + ".stack_frame[" + list.getStackIndex() + "]." + list.getIdentifier() + " " +
171-
"insert ").build("", index.getIdentifier()).build(" value " + SNBTUtil.toSNBT(tag));
171+
"insert ").build("", index.getIdentifier()).build("value " + SNBTUtil.toSNBT(tag));
172172
}
173173
} catch (IOException ex) {
174174
throw new RuntimeException(ex);
@@ -191,7 +191,7 @@ public class NBTListData extends MNIMethodContainer {
191191
command = new Command("data modify " +
192192
"storage mcfpp:system " +
193193
Project.INSTANCE.getCurrNamespace() + ".stack_frame[" + list.getStackIndex() + "]." + list.getIdentifier() + " " +
194-
"insert ").build("", index.getIdentifier()).build(" from " +
194+
"insert ").build("", index.getIdentifier()).build("from " +
195195
"storage mcfpp:system " +
196196
Project.INSTANCE.getCurrNamespace() + ".stack_frame[" + list.getStackIndex() + "]." + e.getIdentifier());
197197
}

src/main/kotlin/top/mcfpp/command/Command.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ open class Command {
116116
* 在这条命令的末尾继续构建命令
117117
*
118118
* @param command 固定的命令字符串
119-
* @param withBlank 是否会在此字符串和已有的字符串之间添加空格
120119
* @return
121120
*/
122121
fun build(command: String) : Command{
122+
commandStringList.add(" ")
123123
commandStringList.add(command)
124124
return this
125125
}
@@ -140,8 +140,8 @@ open class Command {
140140
* @return
141141
*/
142142
fun build(command: String, pointID: String) : Command{
143-
replacePoint[pointID] = commandStringList.size
144143
commandStringList.add(" ")
144+
replacePoint[pointID] = commandStringList.size
145145
commandStringList.add(command)
146146
return this
147147
}

src/main/kotlin/top/mcfpp/command/Commands.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object Commands {
4444
return Command.build("scoreboard players add")
4545
.build(target.name, target.name)
4646
.build(target.`object`.toString(), target.`object`.toString())
47-
.build(" $value")
47+
.build("$value")
4848
}
4949

5050
/**

src/main/kotlin/top/mcfpp/lang/MCInt.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ open class MCInt : MCNumber<Int> {
105105
if(final.size == 2){
106106
Function.addCommand(final[0])
107107
}
108-
final.last().build(Commands.sbPlayerSet(this,b.value as Int))
108+
final.last().build(Commands.sbPlayerSet(this, b.value))
109109
}else{
110110
Function.replaceCommand(final.last().build(replace), Function.currFunction.commands.size - 1)
111111
}
@@ -134,7 +134,7 @@ open class MCInt : MCNumber<Int> {
134134
Commands.selectRun(parent)
135135
}
136136
is MCFPPClassType -> {
137-
arrayOf(Command.build("execute as ${parent.cls.uuid} run "))
137+
arrayOf(Command.build("execute as ${parent.cls.uuid} run"))
138138
}
139139
else -> TODO()
140140
}
@@ -149,7 +149,7 @@ open class MCInt : MCNumber<Int> {
149149
.build(replace), Function.currFunction.commands.size-1)
150150
}
151151
}
152-
val append = "store result storage mcfpp:system " + Project.config.defaultNamespace + ".stack_frame[" + stackIndex + "]." + identifier + " int 1 run "
152+
val append = "store result storage mcfpp:system " + Project.config.defaultNamespace + ".stack_frame[" + stackIndex + "]." + identifier + " int 1 run"
153153
//是成员
154154
val cmd = when(val parent = a.parent){
155155
is ClassPointer -> {
@@ -170,7 +170,7 @@ open class MCInt : MCNumber<Int> {
170170
Function.replaceCommand(cmd.last().build(replace), Function.currFunction.commands.size-1)
171171
}
172172
}else{
173-
val head = if(isTemp) "" else "execute store result storage mcfpp:system " + Project.config.defaultNamespace + ".stack_frame[" + stackIndex + "]." + identifier + " int 1 run "
173+
val head = if(isTemp) "" else "execute store result storage mcfpp:system " + Project.config.defaultNamespace + ".stack_frame[" + stackIndex + "]." + identifier + " int 1 run"
174174
//变量进栈
175175
if(replace == null){
176176
Function.addCommand(Command.build(head)

src/test/kotlin/top/mcfpp/test/LogicStatementTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,30 @@ class LogicStatementTest {
1313
dynamic int i = 5;
1414
if(i < 7){
1515
print("i < 7");
16+
dynamic int p;
1617
}else{
1718
print("i >= 7");
19+
dynamic int p;
1820
}
21+
print(p);
1922
print("end");
2023
}
2124
""".trimIndent()
2225
MCFPPStringTest.readFromString(test, "D:\\.minecraft\\saves\\MCFPP Studio\\datapacks")
2326
}
27+
28+
@Test
29+
fun whileTest(){
30+
val test =
31+
"""
32+
func generateSequence(){
33+
dynamic int i = 0;
34+
while(i < 10){
35+
print(i);
36+
i = i + 1;
37+
}
38+
}
39+
""".trimIndent()
40+
MCFPPStringTest.readFromString(test, "D:\\.minecraft\\saves\\MCFPP Studio\\datapacks")
41+
}
2442
}

0 commit comments

Comments
 (0)