dfpyre 0.4.5__py3-none-any.whl → 0.8.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dfpyre might be problematic. Click here for more details.
- dfpyre/actiondump.py +77 -0
- dfpyre/data/actiondump_min.json +1 -0
- dfpyre/items.py +396 -361
- dfpyre/pyre.py +595 -433
- dfpyre/scriptgen.py +193 -0
- dfpyre/style.py +22 -22
- dfpyre/util.py +39 -0
- {dfpyre-0.4.5.dist-info → dfpyre-0.8.1.dist-info}/LICENSE +21 -21
- dfpyre-0.8.1.dist-info/METADATA +514 -0
- dfpyre-0.8.1.dist-info/RECORD +12 -0
- dfpyre/data/data.json +0 -1
- dfpyre-0.4.5.dist-info/METADATA +0 -448
- dfpyre-0.4.5.dist-info/RECORD +0 -9
- {dfpyre-0.4.5.dist-info → dfpyre-0.8.1.dist-info}/WHEEL +0 -0
dfpyre/items.py
CHANGED
|
@@ -1,361 +1,396 @@
|
|
|
1
|
-
"""
|
|
2
|
-
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from enum import Enum
|
|
6
|
-
|
|
7
|
-
from
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
self.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
self.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
self.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
def
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
"""
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
self.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
def
|
|
262
|
-
self.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
self.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
1
|
+
"""
|
|
2
|
+
Class definitions for code items.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from enum import Enum
|
|
6
|
+
import re
|
|
7
|
+
from typing import Literal, Any
|
|
8
|
+
from dfpyre.style import is_ampersand_coded, ampersand_to_minimessage
|
|
9
|
+
from dfpyre.util import PyreException, warn
|
|
10
|
+
from mcitemlib.itemlib import Item as NbtItem
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
NUMBER_REGEX = r'^-?\d*\.?\d+$'
|
|
14
|
+
VAR_SHORTHAND_REGEX = r'^\$([gsli]) (.+)$'
|
|
15
|
+
VAR_SCOPES = {'g': 'unsaved', 's': 'saved', 'l': 'local', 'i': 'line'}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def convert_argument(arg: Any):
|
|
19
|
+
if type(arg) in {int, float}:
|
|
20
|
+
return Number(arg)
|
|
21
|
+
elif isinstance(arg, str):
|
|
22
|
+
shorthand_match: re.Match = re.match(VAR_SHORTHAND_REGEX, arg)
|
|
23
|
+
if shorthand_match:
|
|
24
|
+
scope = VAR_SCOPES[shorthand_match.group(1)]
|
|
25
|
+
return Variable(shorthand_match.group(2), scope)
|
|
26
|
+
return Text(arg)
|
|
27
|
+
return arg
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _add_slot(d: dict, slot: int|None):
|
|
31
|
+
if slot is not None:
|
|
32
|
+
d['slot'] = slot
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Item(NbtItem):
|
|
36
|
+
"""
|
|
37
|
+
Represents a Minecraft item.
|
|
38
|
+
"""
|
|
39
|
+
type = 'item'
|
|
40
|
+
|
|
41
|
+
def format(self, slot: int|None):
|
|
42
|
+
formatted_dict = {"item": {"id": self.type, "data": {"item": self.get_nbt()}}}
|
|
43
|
+
_add_slot(formatted_dict, slot)
|
|
44
|
+
return formatted_dict
|
|
45
|
+
|
|
46
|
+
def __repr__(self) -> str:
|
|
47
|
+
return f'{self.__class__.__name__}({self.get_id()}, {self.get_count()})'
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class String:
|
|
51
|
+
"""
|
|
52
|
+
Represents a DiamondFire string object. (`txt`)
|
|
53
|
+
"""
|
|
54
|
+
type = 'txt'
|
|
55
|
+
|
|
56
|
+
def __init__(self, value: str):
|
|
57
|
+
self.value = value
|
|
58
|
+
|
|
59
|
+
def format(self, slot: int|None):
|
|
60
|
+
formatted_dict = {"item": {"id": self.type, "data": {"name": self.value}}}
|
|
61
|
+
_add_slot(formatted_dict, slot)
|
|
62
|
+
return formatted_dict
|
|
63
|
+
|
|
64
|
+
def __repr__(self) -> str:
|
|
65
|
+
return f'{self.__class__.__name__}("{self.value}")'
|
|
66
|
+
|
|
67
|
+
Str = String # String alias
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Text:
|
|
71
|
+
"""
|
|
72
|
+
Represents a DiamondFire styled text object (`comp`)
|
|
73
|
+
"""
|
|
74
|
+
type = 'comp'
|
|
75
|
+
|
|
76
|
+
def __init__(self, value: str):
|
|
77
|
+
if is_ampersand_coded(value):
|
|
78
|
+
value = ampersand_to_minimessage(value)
|
|
79
|
+
self.value = value
|
|
80
|
+
|
|
81
|
+
def format(self, slot: int|None):
|
|
82
|
+
formatted_dict = {"item": {"id": self.type, "data": {"name": self.value}}}
|
|
83
|
+
_add_slot(formatted_dict, slot)
|
|
84
|
+
return formatted_dict
|
|
85
|
+
|
|
86
|
+
def __repr__(self) -> str:
|
|
87
|
+
return f'{self.__class__.__name__}("{self.value}")'
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Number:
|
|
91
|
+
"""
|
|
92
|
+
Represents a DiamondFire number object.
|
|
93
|
+
"""
|
|
94
|
+
type = 'num'
|
|
95
|
+
|
|
96
|
+
def __init__(self, num: int|float|str):
|
|
97
|
+
self.value = num
|
|
98
|
+
|
|
99
|
+
def format(self, slot: int|None):
|
|
100
|
+
formatted_dict = {"item": {"id": self.type, "data": {"name": str(self.value)}}}
|
|
101
|
+
_add_slot(formatted_dict, slot)
|
|
102
|
+
return formatted_dict
|
|
103
|
+
|
|
104
|
+
def __repr__(self) -> str:
|
|
105
|
+
return f'{self.__class__.__name__}({self.value})'
|
|
106
|
+
|
|
107
|
+
Num = Number # Number alias
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class Location:
|
|
111
|
+
"""
|
|
112
|
+
Represents a DiamondFire location object.
|
|
113
|
+
"""
|
|
114
|
+
type = 'loc'
|
|
115
|
+
|
|
116
|
+
def __init__(self, x: float=0, y: float=0, z: float=0, pitch: float=0, yaw: float=0):
|
|
117
|
+
self.x = float(x)
|
|
118
|
+
self.y = float(y)
|
|
119
|
+
self.z = float(z)
|
|
120
|
+
self.pitch = float(pitch)
|
|
121
|
+
self.yaw = float(yaw)
|
|
122
|
+
|
|
123
|
+
def format(self, slot: int|None):
|
|
124
|
+
formatted_dict = {"item": {
|
|
125
|
+
"id": self.type,
|
|
126
|
+
"data": {
|
|
127
|
+
"isBlock": False,
|
|
128
|
+
"loc": {
|
|
129
|
+
"x": self.x,
|
|
130
|
+
"y": self.y,
|
|
131
|
+
"z": self.z,
|
|
132
|
+
"pitch": self.pitch,
|
|
133
|
+
"yaw": self.yaw
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}}
|
|
137
|
+
_add_slot(formatted_dict, slot)
|
|
138
|
+
return formatted_dict
|
|
139
|
+
|
|
140
|
+
def __repr__(self) -> str:
|
|
141
|
+
return f'{self.__class__.__name__}({self.x}, {self.y}, {self.z}, {self.pitch}, {self.yaw})'
|
|
142
|
+
|
|
143
|
+
Loc = Location # Location alias
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class Variable:
|
|
147
|
+
"""
|
|
148
|
+
Represents a DiamondFire variable object.
|
|
149
|
+
"""
|
|
150
|
+
type = 'var'
|
|
151
|
+
|
|
152
|
+
def __init__(self, name: str, scope: Literal['unsaved', 'game', 'saved', 'local', 'line']='unsaved'):
|
|
153
|
+
self.name = name
|
|
154
|
+
|
|
155
|
+
if scope == 'game':
|
|
156
|
+
scope = 'unsaved'
|
|
157
|
+
self.scope = scope
|
|
158
|
+
|
|
159
|
+
def format(self, slot: int|None):
|
|
160
|
+
formatted_dict = {"item": {"id": self.type,"data": {"name": self.name, "scope": self.scope}}}
|
|
161
|
+
_add_slot(formatted_dict, slot)
|
|
162
|
+
return formatted_dict
|
|
163
|
+
|
|
164
|
+
def __repr__(self) -> str:
|
|
165
|
+
return f'{self.__class__.__name__}({self.scope}, "{self.name}")'
|
|
166
|
+
|
|
167
|
+
Var = Variable # Variable alias
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class Sound:
|
|
171
|
+
"""
|
|
172
|
+
Represents a DiamondFire sound object.
|
|
173
|
+
"""
|
|
174
|
+
type = 'snd'
|
|
175
|
+
|
|
176
|
+
def __init__(self, name: str, pitch: float=1.0, vol: float=2.0):
|
|
177
|
+
self.name = name
|
|
178
|
+
self.pitch = pitch
|
|
179
|
+
self.vol = vol
|
|
180
|
+
|
|
181
|
+
def format(self, slot: int|None):
|
|
182
|
+
formatted_dict = {"item": {"id": self.type,"data": {"sound": self.name, "pitch": self.pitch, "vol": self.vol}}}
|
|
183
|
+
_add_slot(formatted_dict, slot)
|
|
184
|
+
return formatted_dict
|
|
185
|
+
|
|
186
|
+
def __repr__(self) -> str:
|
|
187
|
+
return f'{self.__class__.__name__}(pitch: {self.pitch}, volume: {self.vol})'
|
|
188
|
+
|
|
189
|
+
Snd = Sound # Sound alias
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class Particle:
|
|
193
|
+
"""
|
|
194
|
+
Represents a DiamondFire particle object.
|
|
195
|
+
"""
|
|
196
|
+
type = 'part'
|
|
197
|
+
def __init__(self, particle_data: dict):
|
|
198
|
+
self.particle_data = particle_data
|
|
199
|
+
|
|
200
|
+
def format(self, slot: int|None):
|
|
201
|
+
formatted_dict = {"item": {"id": self.type, "data": self.particle_data}}
|
|
202
|
+
_add_slot(formatted_dict, slot)
|
|
203
|
+
return formatted_dict
|
|
204
|
+
|
|
205
|
+
def __repr__(self) -> str:
|
|
206
|
+
return f'{self.__class__.__name__}({self.particle_data})'
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class Potion:
|
|
210
|
+
"""
|
|
211
|
+
Represents a DiamondFire potion object.
|
|
212
|
+
"""
|
|
213
|
+
type = 'pot'
|
|
214
|
+
|
|
215
|
+
def __init__(self, name: str, dur: int=1000000, amp: int=0):
|
|
216
|
+
self.name = name
|
|
217
|
+
self.dur = dur
|
|
218
|
+
self.amp = amp
|
|
219
|
+
|
|
220
|
+
def format(self, slot: int|None):
|
|
221
|
+
formatted_dict = {"item": {"id": self.type,"data": {"pot": self.name, "dur": self.dur, "amp": self.amp}}}
|
|
222
|
+
_add_slot(formatted_dict, slot)
|
|
223
|
+
return formatted_dict
|
|
224
|
+
|
|
225
|
+
def __repr__(self) -> str:
|
|
226
|
+
return f'{self.__class__.__name__}(effect: {self.name}, duration: {self.dur}, amplifier: {self.amp})'
|
|
227
|
+
|
|
228
|
+
Pot = Potion # Potion alias
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class GameValue:
|
|
232
|
+
"""
|
|
233
|
+
Represents a DiamondFire game value object.
|
|
234
|
+
"""
|
|
235
|
+
type = 'g_val'
|
|
236
|
+
|
|
237
|
+
def __init__(self, name: str, target: str='Default'):
|
|
238
|
+
self.name = name
|
|
239
|
+
self.target = target
|
|
240
|
+
|
|
241
|
+
def format(self, slot: int|None):
|
|
242
|
+
formatted_dict = {"item": {"id": self.type, "data": {"type": self.name, "target": self.target}}}
|
|
243
|
+
_add_slot(formatted_dict, slot)
|
|
244
|
+
return formatted_dict
|
|
245
|
+
|
|
246
|
+
def __repr__(self) -> str:
|
|
247
|
+
return f'{self.__class__.__name__}({self.name}, target: {self.target})'
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
class Vector:
|
|
251
|
+
"""
|
|
252
|
+
Represents a DiamondFire vector object.
|
|
253
|
+
"""
|
|
254
|
+
type = 'vec'
|
|
255
|
+
|
|
256
|
+
def __init__(self, x: float=0.0, y: float=0.0, z: float=0.0):
|
|
257
|
+
self.x = float(x)
|
|
258
|
+
self.y = float(y)
|
|
259
|
+
self.z = float(z)
|
|
260
|
+
|
|
261
|
+
def format(self, slot: int|None):
|
|
262
|
+
formatted_dict = {"item": {"id": self.type, "data": {"x": self.x, "y": self.y, "z": self.z}}}
|
|
263
|
+
_add_slot(formatted_dict, slot)
|
|
264
|
+
return formatted_dict
|
|
265
|
+
|
|
266
|
+
def __repr__(self) -> str:
|
|
267
|
+
return f'{self.__class__.__name__}({self.x}, {self.y}, {self.z})'
|
|
268
|
+
|
|
269
|
+
Vec = Vector # Vector alias
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
PARAMETER_TYPE_LOOKUP = ['txt', 'comp', 'num', 'loc', 'vec', 'snd', 'part', 'pot', 'item', 'any', 'var', 'list', 'dict']
|
|
273
|
+
|
|
274
|
+
class ParameterType(Enum):
|
|
275
|
+
STRING = 0
|
|
276
|
+
TEXT = 1
|
|
277
|
+
NUMBER = 2
|
|
278
|
+
LOCATION = 3
|
|
279
|
+
VECTOR = 4
|
|
280
|
+
SOUND = 5
|
|
281
|
+
PARTICLE = 6
|
|
282
|
+
POTION_EFFECT = 7
|
|
283
|
+
ITEM = 8
|
|
284
|
+
ANY = 9
|
|
285
|
+
VAR = 10
|
|
286
|
+
LIST = 11
|
|
287
|
+
DICT = 12
|
|
288
|
+
|
|
289
|
+
def get_string_value(self) -> str:
|
|
290
|
+
return PARAMETER_TYPE_LOOKUP[self.value]
|
|
291
|
+
|
|
292
|
+
class Parameter:
|
|
293
|
+
"""
|
|
294
|
+
Represents a DiamondFire parameter object.
|
|
295
|
+
"""
|
|
296
|
+
type = 'pn_el'
|
|
297
|
+
|
|
298
|
+
def __init__(self, name: str, param_type: ParameterType, plural: bool=False, optional: bool=False, description: str="", note: str="", default_value=None):
|
|
299
|
+
self.name = name
|
|
300
|
+
self.param_type = param_type
|
|
301
|
+
self.plural = plural
|
|
302
|
+
self.optional = optional
|
|
303
|
+
self.description = description
|
|
304
|
+
self.note = note
|
|
305
|
+
self.default_value = convert_argument(default_value)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def format(self, slot: int):
|
|
309
|
+
formatted_dict = {"item": {
|
|
310
|
+
"id": self.type,
|
|
311
|
+
"data": {
|
|
312
|
+
"name": self.name,
|
|
313
|
+
"type": self.param_type.get_string_value(),
|
|
314
|
+
"plural": self.plural,
|
|
315
|
+
"optional": self.optional,
|
|
316
|
+
}},
|
|
317
|
+
"slot": slot
|
|
318
|
+
}
|
|
319
|
+
if self.description:
|
|
320
|
+
formatted_dict['item']['data']['description'] = self.description
|
|
321
|
+
if self.note:
|
|
322
|
+
formatted_dict['item']['data']['note'] = self.note
|
|
323
|
+
if self.default_value is not None:
|
|
324
|
+
if not self.optional:
|
|
325
|
+
warn(f'For parameter "{self.name}": Default value cannot be set if optional is False.')
|
|
326
|
+
elif self.plural:
|
|
327
|
+
warn(f'For parameter "{self.name}": Default value cannot be set while plural is True.')
|
|
328
|
+
else:
|
|
329
|
+
formatted_dict['item']['data']['default_value'] = self.default_value.format(None)['item']
|
|
330
|
+
|
|
331
|
+
return formatted_dict
|
|
332
|
+
|
|
333
|
+
def __repr__(self) -> str:
|
|
334
|
+
raw_type = str(self.param_type).partition('.')[2]
|
|
335
|
+
return f'{self.__class__.__name__}({self.name}, type: {raw_type})'
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def item_from_dict(item_dict: dict) -> object:
|
|
339
|
+
item_id = item_dict['id']
|
|
340
|
+
item_data = item_dict['data']
|
|
341
|
+
|
|
342
|
+
if item_id == 'item':
|
|
343
|
+
return Item.from_nbt(item_data['item'])
|
|
344
|
+
|
|
345
|
+
elif item_id == 'txt':
|
|
346
|
+
return String(item_data['name'])
|
|
347
|
+
|
|
348
|
+
elif item_id == 'comp':
|
|
349
|
+
return Text(item_data['name'])
|
|
350
|
+
|
|
351
|
+
elif item_id == 'num':
|
|
352
|
+
num_value = item_data['name']
|
|
353
|
+
if re.match(NUMBER_REGEX, num_value):
|
|
354
|
+
num_value = float(item_data['name'])
|
|
355
|
+
if num_value % 1 == 0:
|
|
356
|
+
num_value = int(num_value)
|
|
357
|
+
return Number(num_value)
|
|
358
|
+
return Number(num_value)
|
|
359
|
+
|
|
360
|
+
elif item_id == 'loc':
|
|
361
|
+
item_loc = item_data['loc']
|
|
362
|
+
return Location(item_loc['x'], item_loc['y'], item_loc['z'], item_loc['pitch'], item_loc['yaw'])
|
|
363
|
+
|
|
364
|
+
elif item_id == 'var':
|
|
365
|
+
return Variable(item_data['name'], item_data['scope'])
|
|
366
|
+
|
|
367
|
+
elif item_id == 'snd':
|
|
368
|
+
return Sound(item_data['sound'], item_data['pitch'], item_data['vol'])
|
|
369
|
+
|
|
370
|
+
elif item_id == 'part':
|
|
371
|
+
return Particle(item_data)
|
|
372
|
+
|
|
373
|
+
elif item_id == 'pot':
|
|
374
|
+
return Potion(item_data['pot'], item_data['dur'], item_data['amp'])
|
|
375
|
+
|
|
376
|
+
elif item_id == 'g_val':
|
|
377
|
+
return GameValue(item_data['type'], item_data['target'])
|
|
378
|
+
|
|
379
|
+
elif item_id == 'vec':
|
|
380
|
+
return Vector(item_data['x'], item_data['y'], item_data['z'])
|
|
381
|
+
|
|
382
|
+
elif item_id == 'pn_el':
|
|
383
|
+
description = item_data.get('description') or ''
|
|
384
|
+
note = item_data.get('note') or ''
|
|
385
|
+
param_type = ParameterType(PARAMETER_TYPE_LOOKUP.index(item_data['type']))
|
|
386
|
+
if item_data['optional']:
|
|
387
|
+
if 'default_value' in item_data:
|
|
388
|
+
return Parameter(item_data['name'], param_type, item_data['plural'], True, description, note, item_from_dict(item_data['default_value']))
|
|
389
|
+
return Parameter(item_data['name'], param_type, item_data['plural'], True, description, note)
|
|
390
|
+
return Parameter(item_data['name'], param_type, item_data['plural'], False, description, note)
|
|
391
|
+
|
|
392
|
+
elif item_id in {'bl_tag', 'hint'}: # Ignore tags and hints
|
|
393
|
+
return
|
|
394
|
+
|
|
395
|
+
else:
|
|
396
|
+
raise PyreException(f'Unrecognized item id `{item_id}`')
|