@@ -27,158 +27,39 @@ public class NBTListConcreteData {
27
27
28
28
@ InsertCommand
29
29
@ MNIFunction (normalParams = {"E e" }, caller = "list" , genericType = "E" )
30
- public static void add (Var <?> e , NBTListConcrete caller ){
30
+ public static void add (Var <?> e , NBTListConcrete caller ) throws IOException {
31
31
if (e instanceof MCFPPValue <?>){
32
- //都是确定的
33
- //直接添加值
34
32
caller .getValue ().add (e );
35
33
}else {
36
- //e不是确定的,但是list可能是确定的可能不是确定的
37
- caller .toDynamic (true );
38
- Command [] command ;
39
- if (e .parentClass () != null ) e = e .getTempVar ();
40
- if (e .isTemp ()) e .storeToStack ();
41
- if (caller .getParent () != null ){
42
- command = Commands .INSTANCE .selectRun (caller .getParent (),
43
- new Command ("data modify " +
44
- "entity @s " +
45
- "data." + caller .getIdentifier () + " " +
46
- "append from " +
47
- "storage mcfpp:system " +
48
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + e .getIdentifier () + " " ), true );
49
- }else {
50
- command = new Command []{ new Command ("data modify " +
51
- "storage mcfpp:system " +
52
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + caller .getIdentifier () + " " +
53
- "append from " +
54
- "storage mcfpp:system " +
55
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + e .getIdentifier () + " " )};
56
- }
57
- Function .Companion .addCommands (command );
34
+ NBTListData .add (e , (NBTList ) caller .toDynamic (true ));
58
35
}
59
36
}
60
37
61
38
@ InsertCommand
62
39
@ MNIFunction (normalParams = {"list<E> list" }, caller = "list" , genericType = "E" )
63
40
public static void addAll (NBTList list , NBTListConcrete caller ){
64
41
if (list instanceof MCFPPValue <?> ec ){
65
- //都是确定的
66
- //直接添加值
67
42
caller .getValue ().addAll ((Collection ) ec .getValue ());
68
43
}else {
69
- caller .toDynamic (true );
70
- Command [] command ;
71
- NBTBasedData l ;
72
- if (list .parentClass () != null ) {
73
- l = list .getTempVar ();
74
- }else {
75
- l = list ;
76
- }
77
- if (caller .getParent () != null ){
78
- command = Commands .INSTANCE .selectRun (caller .getParent (),"data modify " +
79
- "entity @s " +
80
- "data." + caller .getIdentifier () + " " +
81
- "append from " +
82
- "storage mcfpp:system " +
83
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + l .getIdentifier () + "[]" , true );
84
- }else {
85
- command = new Command []{ new Command ("data modify " +
86
- "storage mcfpp:system " +
87
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + caller .getIdentifier () + " " +
88
- "append from " +
89
- "storage mcfpp:system " +
90
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + l .getIdentifier () + "[]" )};
91
- }
92
- Function .Companion .addCommands (command );
44
+ NBTListData .addAll (list , (NBTList ) caller .toDynamic (true ));
93
45
}
94
46
}
95
47
96
48
@ InsertCommand
97
49
@ MNIFunction (normalParams = {"int index" , "E e" }, caller = "list" , genericType = "E" )
98
- public static void insert (MCInt index , Var <?> e , NBTListConcrete caller ){
50
+ public static void insert (MCInt index , Var <?> e , NBTListConcrete caller ) throws IOException {
99
51
if (e instanceof MCFPPValue <?> && index instanceof MCIntConcrete indexC ){
100
- //都是确定的
101
- //直接添加值
102
52
caller .getValue ().add (indexC .getValue (), e );
103
- }else if (index instanceof MCIntConcrete indexC ){
104
- //e不是确定的,index是确定的,所以可以直接调用命令而不需要宏
105
- int i = indexC .getValue ();
106
- caller .toDynamic (true );
107
- Command [] command ;
108
- if (e .parentClass () != null ) e = e .getTempVar ();
109
- if (caller .getParent () != null ){
110
- command = Commands .INSTANCE .selectRun (caller .getParent (), "data modify " +
111
- "entity @s " +
112
- "data." + caller .getIdentifier () + " " +
113
- "insert " + i + " from " +
114
- "storage mcfpp:system " +
115
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + e .getIdentifier (), true );
116
- }else {
117
- command = new Command [] {new Command ("data modify " +
118
- "storage mcfpp:system " +
119
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + caller .getIdentifier () + " " +
120
- "insert " + i + " from " +
121
- "storage mcfpp:system " +
122
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + e .getIdentifier ())};
123
- }
124
- Function .Companion .addCommands (command );
125
- }else if (e instanceof MCFPPValue <?>){
126
- //e是确定的,index不是确定的,需要使用宏
127
- caller .toDynamic (true );
128
- Tag <?> tag = NBTUtil .INSTANCE .varToNBT (e );
129
- try {
130
- if (caller .getParent () != null ){
131
- var command = Commands .INSTANCE .selectRun (caller .getParent (),
132
- new Command ("data modify " +
133
- "entity @s " +
134
- "data." + caller .getIdentifier () + " " +
135
- "insert" ).build ("" , "$" + index .getIdentifier (), true ).build ("value " + SNBTUtil .toSNBT (tag ), true ), true
136
- );
137
- Function .Companion .addCommand (command [0 ]);
138
- var f = command [1 ].buildMacroFunction ();
139
- Function .Companion .addCommands (f );
140
- } else {
141
- var command = new Command ("data modify " +
142
- "storage mcfpp:system " +
143
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + caller .getIdentifier () + " " +
144
- "insert" ).build ("" , "$" + index .getIdentifier (), true ).build ("value " + SNBTUtil .toSNBT (tag ), true );
145
- var f = command .buildMacroFunction ();
146
- Function .Companion .addCommands (f );
147
- }
148
- } catch (IOException ex ) {
149
- throw new RuntimeException (ex );
150
- }
151
- } else {
152
- //e是不确定的,index也不是确定的
153
- caller .toDynamic (true );
154
- if (e .parentClass () != null ) e = e .getTempVar ();
155
- Command [] command ;
156
- if (caller .getParent () != null ){
157
- command = Commands .INSTANCE .selectRun (caller .getParent (), new Command ("data modify " +
158
- "entity @s " +
159
- "data." + caller .getIdentifier () + " " +
160
- "insert" ).build ("" , "$" + index .getIdentifier (), true ).build ("from " +
161
- "storage mcfpp:system " +
162
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + e .getIdentifier (), true ), true );
163
- } else {
164
- command = new Command [] {new Command ("data modify " +
165
- "storage mcfpp:system " +
166
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + caller .getIdentifier () + " " +
167
- "insert" ).build ("" , "$" + index .getIdentifier (), true ).build ("from " +
168
- "storage mcfpp:system " +
169
- Project .INSTANCE .getCurrNamespace () + ".stack_frame[" + caller .getStackIndex () + "]." + e .getIdentifier (), true )};
170
- }
171
- if (command .length == 2 ) Function .Companion .addCommand (command [0 ]);
172
- var f = command [command .length - 1 ].buildMacroFunction ();
173
- Function .Companion .addCommands (f );
53
+ }else if (index instanceof MCIntConcrete indexC ) {
54
+ NBTListData .insert (index , e , (NBTList ) caller .toDynamic (true ));
174
55
}
175
56
}
176
57
177
- @ InsertCommand
178
- @ MNIFunction (normalParams = {"E e" }, caller = "list" , genericType = "E" )
179
- public static void remove (Var <?> e , NBTListConcrete caller ){
180
- //TODO NBT的api本来就没有remove(E e)这个方法,只有remove(int index)
181
- }
58
+ // @InsertCommand
59
+ // @MNIFunction(normalParams = {"E e"}, caller = "list", genericType = "E")
60
+ // public static void remove(Var<?> e, NBTListConcrete caller){
61
+ // //TODO NBT的api本来就没有remove(E e)这个方法,只有remove(int index)
62
+ // }
182
63
183
64
@ InsertCommand
184
65
@ MNIFunction (normalParams = {"int index" }, caller = "list" , genericType = "E" )
@@ -221,6 +102,7 @@ public static void lastIndexOf(Var<?> e, NBTListConcrete caller, ValueWrapper<MC
221
102
}
222
103
}
223
104
105
+ @ SuppressWarnings ("SuspiciousMethodCalls" )
224
106
@ MNIFunction (normalParams = {"E e" }, caller = "list" , genericType = "E" , returnType = "bool" )
225
107
public static void contains (Var <?> e , NBTListConcrete caller , ValueWrapper <ScoreBool > returnVar ){
226
108
if (e instanceof MCFPPValue eC ){
0 commit comments