dfpyre 0.7.2__py3-none-any.whl → 0.7.4__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 -77
- dfpyre/data/actiondump_min.json +1 -1
- dfpyre/items.py +372 -372
- dfpyre/pyre.py +457 -457
- dfpyre/scriptgen.py +152 -152
- dfpyre/style.py +21 -21
- dfpyre/util.py +28 -28
- {dfpyre-0.7.2.dist-info → dfpyre-0.7.4.dist-info}/LICENSE +21 -21
- {dfpyre-0.7.2.dist-info → dfpyre-0.7.4.dist-info}/METADATA +2 -2
- dfpyre-0.7.4.dist-info/RECORD +12 -0
- dfpyre-0.7.2.dist-info/RECORD +0 -12
- {dfpyre-0.7.2.dist-info → dfpyre-0.7.4.dist-info}/WHEEL +0 -0
dfpyre/items.py
CHANGED
|
@@ -1,373 +1,373 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Contains 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_CHAR = '$'
|
|
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 num(arg)
|
|
21
|
-
elif isinstance(arg, str):
|
|
22
|
-
if len(arg) > 2 and arg[0] == VAR_SHORTHAND_CHAR and arg[1] in VAR_SCOPES:
|
|
23
|
-
return var(arg[2:], VAR_SCOPES[arg[1]])
|
|
24
|
-
return text(arg)
|
|
25
|
-
return arg
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def _add_slot(d: dict, slot: int|None):
|
|
29
|
-
if slot is not None:
|
|
30
|
-
d['slot'] = slot
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class item(NbtItem):
|
|
34
|
-
"""
|
|
35
|
-
Represents a Minecraft item.
|
|
36
|
-
"""
|
|
37
|
-
type = 'item'
|
|
38
|
-
|
|
39
|
-
def format(self, slot: int|None):
|
|
40
|
-
formatted_dict = {"item": {"id": self.type, "data": {"item": self.get_nbt()}}}
|
|
41
|
-
_add_slot(formatted_dict, slot)
|
|
42
|
-
return formatted_dict
|
|
43
|
-
|
|
44
|
-
def __repr__(self) -> str:
|
|
45
|
-
return f'{self.__class__.__name__}({self.get_id()}, {self.get_count()})'
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
class string:
|
|
49
|
-
"""
|
|
50
|
-
Represents a DiamondFire string object. (`txt`)
|
|
51
|
-
"""
|
|
52
|
-
type = 'txt'
|
|
53
|
-
|
|
54
|
-
def __init__(self, value: str):
|
|
55
|
-
self.value = value
|
|
56
|
-
|
|
57
|
-
def format(self, slot: int|None):
|
|
58
|
-
formatted_dict = {"item": {"id": self.type, "data": {"name": self.value}}}
|
|
59
|
-
_add_slot(formatted_dict, slot)
|
|
60
|
-
return formatted_dict
|
|
61
|
-
|
|
62
|
-
def __repr__(self) -> str:
|
|
63
|
-
return f'{self.__class__.__name__}("{self.value}")'
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
class text:
|
|
67
|
-
"""
|
|
68
|
-
Represents a DiamondFire styled text object (`comp`)
|
|
69
|
-
"""
|
|
70
|
-
type = 'comp'
|
|
71
|
-
|
|
72
|
-
def __init__(self, value: str):
|
|
73
|
-
if is_ampersand_coded(value):
|
|
74
|
-
value = ampersand_to_minimessage(value)
|
|
75
|
-
self.value = value
|
|
76
|
-
|
|
77
|
-
def format(self, slot: int|None):
|
|
78
|
-
formatted_dict = {"item": {"id": self.type, "data": {"name": self.value}}}
|
|
79
|
-
_add_slot(formatted_dict, slot)
|
|
80
|
-
return formatted_dict
|
|
81
|
-
|
|
82
|
-
def __repr__(self) -> str:
|
|
83
|
-
return f'{self.__class__.__name__}("{self.value}")'
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
class num:
|
|
87
|
-
"""
|
|
88
|
-
Represents a DiamondFire number object.
|
|
89
|
-
"""
|
|
90
|
-
type = 'num'
|
|
91
|
-
|
|
92
|
-
def __init__(self, num: int|float|str):
|
|
93
|
-
self.value = num
|
|
94
|
-
|
|
95
|
-
def format(self, slot: int|None):
|
|
96
|
-
formatted_dict = {"item": {"id": self.type, "data": {"name": str(self.value)}}}
|
|
97
|
-
_add_slot(formatted_dict, slot)
|
|
98
|
-
return formatted_dict
|
|
99
|
-
|
|
100
|
-
def __repr__(self) -> str:
|
|
101
|
-
return f'{self.__class__.__name__}({self.value})'
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
class loc:
|
|
105
|
-
"""
|
|
106
|
-
Represents a DiamondFire location object.
|
|
107
|
-
"""
|
|
108
|
-
type = 'loc'
|
|
109
|
-
|
|
110
|
-
def __init__(self, x: float=0, y: float=0, z: float=0, pitch: float=0, yaw: float=0):
|
|
111
|
-
self.x = float(x)
|
|
112
|
-
self.y = float(y)
|
|
113
|
-
self.z = float(z)
|
|
114
|
-
self.pitch = float(pitch)
|
|
115
|
-
self.yaw = float(yaw)
|
|
116
|
-
|
|
117
|
-
def format(self, slot: int|None):
|
|
118
|
-
formatted_dict = {"item": {
|
|
119
|
-
"id": self.type,
|
|
120
|
-
"data": {
|
|
121
|
-
"isBlock": False,
|
|
122
|
-
"loc": {
|
|
123
|
-
"x": self.x,
|
|
124
|
-
"y": self.y,
|
|
125
|
-
"z": self.z,
|
|
126
|
-
"pitch": self.pitch,
|
|
127
|
-
"yaw": self.yaw
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}}
|
|
131
|
-
_add_slot(formatted_dict, slot)
|
|
132
|
-
return formatted_dict
|
|
133
|
-
|
|
134
|
-
def __repr__(self) -> str:
|
|
135
|
-
return f'{self.__class__.__name__}({self.x}, {self.y}, {self.z}, {self.pitch}, {self.yaw})'
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
class var:
|
|
139
|
-
"""
|
|
140
|
-
Represents a DiamondFire variable object.
|
|
141
|
-
"""
|
|
142
|
-
type = 'var'
|
|
143
|
-
|
|
144
|
-
def __init__(self, name: str, scope: Literal['unsaved', 'saved', 'local', 'line']='unsaved'):
|
|
145
|
-
self.name = name
|
|
146
|
-
self.scope = scope
|
|
147
|
-
|
|
148
|
-
def format(self, slot: int|None):
|
|
149
|
-
formatted_dict = {"item": {"id": self.type,"data": {"name": self.name, "scope": self.scope}}}
|
|
150
|
-
_add_slot(formatted_dict, slot)
|
|
151
|
-
return formatted_dict
|
|
152
|
-
|
|
153
|
-
def __repr__(self) -> str:
|
|
154
|
-
return f'{self.__class__.__name__}({self.scope}, "{self.name}")'
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
class sound:
|
|
158
|
-
"""
|
|
159
|
-
Represents a DiamondFire sound object.
|
|
160
|
-
"""
|
|
161
|
-
type = 'snd'
|
|
162
|
-
|
|
163
|
-
def __init__(self, name: str, pitch: float=1.0, vol: float=2.0):
|
|
164
|
-
self.name = name
|
|
165
|
-
self.pitch = pitch
|
|
166
|
-
self.vol = vol
|
|
167
|
-
|
|
168
|
-
def format(self, slot: int|None):
|
|
169
|
-
formatted_dict = {"item": {"id": self.type,"data": {"sound": self.name, "pitch": self.pitch, "vol": self.vol}}}
|
|
170
|
-
_add_slot(formatted_dict, slot)
|
|
171
|
-
return formatted_dict
|
|
172
|
-
|
|
173
|
-
def __repr__(self) -> str:
|
|
174
|
-
return f'{self.__class__.__name__}(pitch: {self.pitch}, volume: {self.vol})'
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
class particle:
|
|
178
|
-
"""
|
|
179
|
-
Represents a DiamondFire particle object.
|
|
180
|
-
"""
|
|
181
|
-
type = 'part'
|
|
182
|
-
def __init__(self, particle_data: dict):
|
|
183
|
-
self.particle_data = particle_data
|
|
184
|
-
|
|
185
|
-
def format(self, slot: int|None):
|
|
186
|
-
formatted_dict = {"item": {"id": self.type, "data": self.particle_data}}
|
|
187
|
-
_add_slot(formatted_dict, slot)
|
|
188
|
-
return formatted_dict
|
|
189
|
-
|
|
190
|
-
def __repr__(self) -> str:
|
|
191
|
-
return f'{self.__class__.__name__}({self.particle_data})'
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
class potion:
|
|
195
|
-
"""
|
|
196
|
-
Represents a DiamondFire potion object.
|
|
197
|
-
"""
|
|
198
|
-
type = 'pot'
|
|
199
|
-
|
|
200
|
-
def __init__(self, name: str, dur: int=1000000, amp: int=0):
|
|
201
|
-
self.name = name
|
|
202
|
-
self.dur = dur
|
|
203
|
-
self.amp = amp
|
|
204
|
-
|
|
205
|
-
def format(self, slot: int|None):
|
|
206
|
-
formatted_dict = {"item": {"id": self.type,"data": {"pot": self.name, "dur": self.dur, "amp": self.amp}}}
|
|
207
|
-
_add_slot(formatted_dict, slot)
|
|
208
|
-
return formatted_dict
|
|
209
|
-
|
|
210
|
-
def __repr__(self) -> str:
|
|
211
|
-
return f'{self.__class__.__name__}(effect: {self.name}, duration: {self.dur}, amplifier: {self.amp})'
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
class gamevalue:
|
|
215
|
-
"""
|
|
216
|
-
Represents a DiamondFire game value object.
|
|
217
|
-
"""
|
|
218
|
-
type = 'g_val'
|
|
219
|
-
|
|
220
|
-
def __init__(self, name: str, target: str='Default'):
|
|
221
|
-
self.name = name
|
|
222
|
-
self.target = target
|
|
223
|
-
|
|
224
|
-
def format(self, slot: int|None):
|
|
225
|
-
formatted_dict = {"item": {"id": self.type, "data": {"type": self.name, "target": self.target}}}
|
|
226
|
-
_add_slot(formatted_dict, slot)
|
|
227
|
-
return formatted_dict
|
|
228
|
-
|
|
229
|
-
def __repr__(self) -> str:
|
|
230
|
-
return f'{self.__class__.__name__}({self.name}, target: {self.target})'
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
class vector:
|
|
234
|
-
"""
|
|
235
|
-
Represents a DiamondFire vector object.
|
|
236
|
-
"""
|
|
237
|
-
type = 'vec'
|
|
238
|
-
|
|
239
|
-
def __init__(self, x: float=0.0, y: float=0.0, z: float=0.0):
|
|
240
|
-
self.x = float(x)
|
|
241
|
-
self.y = float(y)
|
|
242
|
-
self.z = float(z)
|
|
243
|
-
|
|
244
|
-
def format(self, slot: int|None):
|
|
245
|
-
formatted_dict = {"item": {"id": self.type, "data": {"x": self.x, "y": self.y, "z": self.z}}}
|
|
246
|
-
_add_slot(formatted_dict, slot)
|
|
247
|
-
return formatted_dict
|
|
248
|
-
|
|
249
|
-
def __repr__(self) -> str:
|
|
250
|
-
return f'{self.__class__.__name__}({self.x}, {self.y}, {self.z})'
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
PARAMETER_TYPE_LOOKUP = ['txt', 'comp', 'num', 'loc', 'vec', 'snd', 'part', 'pot', 'item', 'any', 'var', 'list', 'dict']
|
|
254
|
-
|
|
255
|
-
class ParameterType(Enum):
|
|
256
|
-
STRING = 0
|
|
257
|
-
TEXT = 1
|
|
258
|
-
NUMBER = 2
|
|
259
|
-
LOCATION = 3
|
|
260
|
-
VECTOR = 4
|
|
261
|
-
SOUND = 5
|
|
262
|
-
PARTICLE = 6
|
|
263
|
-
POTION_EFFECT = 7
|
|
264
|
-
ITEM = 8
|
|
265
|
-
ANY = 9
|
|
266
|
-
VAR = 10
|
|
267
|
-
LIST = 11
|
|
268
|
-
DICT = 12
|
|
269
|
-
|
|
270
|
-
def get_string_value(self) -> str:
|
|
271
|
-
return PARAMETER_TYPE_LOOKUP[self.value]
|
|
272
|
-
|
|
273
|
-
class parameter:
|
|
274
|
-
"""
|
|
275
|
-
Represents a DiamondFire parameter object.
|
|
276
|
-
"""
|
|
277
|
-
type = 'pn_el'
|
|
278
|
-
|
|
279
|
-
def __init__(self, name: str, param_type: ParameterType, plural: bool=False, optional: bool=False, description: str="", note: str="", default_value=None):
|
|
280
|
-
self.name = name
|
|
281
|
-
self.param_type = param_type
|
|
282
|
-
self.plural = plural
|
|
283
|
-
self.optional = optional
|
|
284
|
-
self.description = description
|
|
285
|
-
self.note = note
|
|
286
|
-
self.default_value = convert_argument(default_value)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
def format(self, slot: int):
|
|
290
|
-
formatted_dict = {"item": {
|
|
291
|
-
"id": self.type,
|
|
292
|
-
"data": {
|
|
293
|
-
"name": self.name,
|
|
294
|
-
"type": self.param_type.get_string_value(),
|
|
295
|
-
"plural": self.plural,
|
|
296
|
-
"optional": self.optional,
|
|
297
|
-
}},
|
|
298
|
-
"slot": slot
|
|
299
|
-
}
|
|
300
|
-
if self.description:
|
|
301
|
-
formatted_dict['item']['data']['description'] = self.description
|
|
302
|
-
if self.note:
|
|
303
|
-
formatted_dict['item']['data']['note'] = self.note
|
|
304
|
-
if self.default_value is not None:
|
|
305
|
-
if not self.optional:
|
|
306
|
-
warn(f'For parameter "{self.name}": Default value cannot be set if optional is False.')
|
|
307
|
-
elif self.plural:
|
|
308
|
-
warn(f'For parameter "{self.name}": Default value cannot be set while plural is True.')
|
|
309
|
-
else:
|
|
310
|
-
formatted_dict['item']['data']['default_value'] = self.default_value.format(None)['item']
|
|
311
|
-
|
|
312
|
-
return formatted_dict
|
|
313
|
-
|
|
314
|
-
def __repr__(self) -> str:
|
|
315
|
-
raw_type = str(self.param_type).partition('.')[2]
|
|
316
|
-
return f'{self.__class__.__name__}({self.name}, type: {raw_type})'
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
def _some_or(value: Any, none_value: Any):
|
|
320
|
-
"""
|
|
321
|
-
Returns `none_value` if `value` is None, otherwise returns `value`.
|
|
322
|
-
"""
|
|
323
|
-
if value is None:
|
|
324
|
-
return none_value
|
|
325
|
-
return value
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
def item_from_dict(item_dict: dict) -> object:
|
|
329
|
-
item_id = item_dict['id']
|
|
330
|
-
item_data = item_dict['data']
|
|
331
|
-
|
|
332
|
-
if item_id == 'item':
|
|
333
|
-
return item.from_nbt(item_data['item'])
|
|
334
|
-
elif item_id == 'txt':
|
|
335
|
-
return string(item_data['name'])
|
|
336
|
-
elif item_id == 'comp':
|
|
337
|
-
return text(item_data['name'])
|
|
338
|
-
elif item_id == 'num':
|
|
339
|
-
num_value = item_data['name']
|
|
340
|
-
if re.match(NUMBER_REGEX, num_value):
|
|
341
|
-
num_value = float(item_data['name'])
|
|
342
|
-
if num_value % 1 == 0:
|
|
343
|
-
num_value = int(num_value)
|
|
344
|
-
return num(num_value)
|
|
345
|
-
return num(num_value)
|
|
346
|
-
elif item_id == 'loc':
|
|
347
|
-
item_loc = item_data['loc']
|
|
348
|
-
return loc(item_loc['x'], item_loc['y'], item_loc['z'], item_loc['pitch'], item_loc['yaw'])
|
|
349
|
-
elif item_id == 'var':
|
|
350
|
-
return var(item_data['name'], item_data['scope'])
|
|
351
|
-
elif item_id == 'snd':
|
|
352
|
-
return sound(item_data['sound'], item_data['pitch'], item_data['vol'])
|
|
353
|
-
elif item_id == 'part':
|
|
354
|
-
return particle(item_data)
|
|
355
|
-
elif item_id == 'pot':
|
|
356
|
-
return potion(item_data['pot'], item_data['dur'], item_data['amp'])
|
|
357
|
-
elif item_id == 'g_val':
|
|
358
|
-
return gamevalue(item_data['type'], item_data['target'])
|
|
359
|
-
elif item_id == 'vec':
|
|
360
|
-
return vector(item_data['x'], item_data['y'], item_data['z'])
|
|
361
|
-
elif item_id == 'pn_el':
|
|
362
|
-
description = _some_or(item_data.get('description'), '')
|
|
363
|
-
note = _some_or(item_data.get('note'), '')
|
|
364
|
-
param_type = ParameterType(PARAMETER_TYPE_LOOKUP.index(item_data['type']))
|
|
365
|
-
if item_data['optional']:
|
|
366
|
-
if 'default_value' in item_data:
|
|
367
|
-
return parameter(item_data['name'], param_type, item_data['plural'], True, description, note, item_from_dict(item_data['default_value']))
|
|
368
|
-
return parameter(item_data['name'], param_type, item_data['plural'], True, description, note)
|
|
369
|
-
return parameter(item_data['name'], param_type, item_data['plural'], False, description, note)
|
|
370
|
-
elif item_id in {'bl_tag', 'hint'}:
|
|
371
|
-
return
|
|
372
|
-
else:
|
|
1
|
+
"""
|
|
2
|
+
Contains 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_CHAR = '$'
|
|
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 num(arg)
|
|
21
|
+
elif isinstance(arg, str):
|
|
22
|
+
if len(arg) > 2 and arg[0] == VAR_SHORTHAND_CHAR and arg[1] in VAR_SCOPES:
|
|
23
|
+
return var(arg[2:], VAR_SCOPES[arg[1]])
|
|
24
|
+
return text(arg)
|
|
25
|
+
return arg
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _add_slot(d: dict, slot: int|None):
|
|
29
|
+
if slot is not None:
|
|
30
|
+
d['slot'] = slot
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class item(NbtItem):
|
|
34
|
+
"""
|
|
35
|
+
Represents a Minecraft item.
|
|
36
|
+
"""
|
|
37
|
+
type = 'item'
|
|
38
|
+
|
|
39
|
+
def format(self, slot: int|None):
|
|
40
|
+
formatted_dict = {"item": {"id": self.type, "data": {"item": self.get_nbt()}}}
|
|
41
|
+
_add_slot(formatted_dict, slot)
|
|
42
|
+
return formatted_dict
|
|
43
|
+
|
|
44
|
+
def __repr__(self) -> str:
|
|
45
|
+
return f'{self.__class__.__name__}({self.get_id()}, {self.get_count()})'
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class string:
|
|
49
|
+
"""
|
|
50
|
+
Represents a DiamondFire string object. (`txt`)
|
|
51
|
+
"""
|
|
52
|
+
type = 'txt'
|
|
53
|
+
|
|
54
|
+
def __init__(self, value: str):
|
|
55
|
+
self.value = value
|
|
56
|
+
|
|
57
|
+
def format(self, slot: int|None):
|
|
58
|
+
formatted_dict = {"item": {"id": self.type, "data": {"name": self.value}}}
|
|
59
|
+
_add_slot(formatted_dict, slot)
|
|
60
|
+
return formatted_dict
|
|
61
|
+
|
|
62
|
+
def __repr__(self) -> str:
|
|
63
|
+
return f'{self.__class__.__name__}("{self.value}")'
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class text:
|
|
67
|
+
"""
|
|
68
|
+
Represents a DiamondFire styled text object (`comp`)
|
|
69
|
+
"""
|
|
70
|
+
type = 'comp'
|
|
71
|
+
|
|
72
|
+
def __init__(self, value: str):
|
|
73
|
+
if is_ampersand_coded(value):
|
|
74
|
+
value = ampersand_to_minimessage(value)
|
|
75
|
+
self.value = value
|
|
76
|
+
|
|
77
|
+
def format(self, slot: int|None):
|
|
78
|
+
formatted_dict = {"item": {"id": self.type, "data": {"name": self.value}}}
|
|
79
|
+
_add_slot(formatted_dict, slot)
|
|
80
|
+
return formatted_dict
|
|
81
|
+
|
|
82
|
+
def __repr__(self) -> str:
|
|
83
|
+
return f'{self.__class__.__name__}("{self.value}")'
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class num:
|
|
87
|
+
"""
|
|
88
|
+
Represents a DiamondFire number object.
|
|
89
|
+
"""
|
|
90
|
+
type = 'num'
|
|
91
|
+
|
|
92
|
+
def __init__(self, num: int|float|str):
|
|
93
|
+
self.value = num
|
|
94
|
+
|
|
95
|
+
def format(self, slot: int|None):
|
|
96
|
+
formatted_dict = {"item": {"id": self.type, "data": {"name": str(self.value)}}}
|
|
97
|
+
_add_slot(formatted_dict, slot)
|
|
98
|
+
return formatted_dict
|
|
99
|
+
|
|
100
|
+
def __repr__(self) -> str:
|
|
101
|
+
return f'{self.__class__.__name__}({self.value})'
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class loc:
|
|
105
|
+
"""
|
|
106
|
+
Represents a DiamondFire location object.
|
|
107
|
+
"""
|
|
108
|
+
type = 'loc'
|
|
109
|
+
|
|
110
|
+
def __init__(self, x: float=0, y: float=0, z: float=0, pitch: float=0, yaw: float=0):
|
|
111
|
+
self.x = float(x)
|
|
112
|
+
self.y = float(y)
|
|
113
|
+
self.z = float(z)
|
|
114
|
+
self.pitch = float(pitch)
|
|
115
|
+
self.yaw = float(yaw)
|
|
116
|
+
|
|
117
|
+
def format(self, slot: int|None):
|
|
118
|
+
formatted_dict = {"item": {
|
|
119
|
+
"id": self.type,
|
|
120
|
+
"data": {
|
|
121
|
+
"isBlock": False,
|
|
122
|
+
"loc": {
|
|
123
|
+
"x": self.x,
|
|
124
|
+
"y": self.y,
|
|
125
|
+
"z": self.z,
|
|
126
|
+
"pitch": self.pitch,
|
|
127
|
+
"yaw": self.yaw
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}}
|
|
131
|
+
_add_slot(formatted_dict, slot)
|
|
132
|
+
return formatted_dict
|
|
133
|
+
|
|
134
|
+
def __repr__(self) -> str:
|
|
135
|
+
return f'{self.__class__.__name__}({self.x}, {self.y}, {self.z}, {self.pitch}, {self.yaw})'
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class var:
|
|
139
|
+
"""
|
|
140
|
+
Represents a DiamondFire variable object.
|
|
141
|
+
"""
|
|
142
|
+
type = 'var'
|
|
143
|
+
|
|
144
|
+
def __init__(self, name: str, scope: Literal['unsaved', 'saved', 'local', 'line']='unsaved'):
|
|
145
|
+
self.name = name
|
|
146
|
+
self.scope = scope
|
|
147
|
+
|
|
148
|
+
def format(self, slot: int|None):
|
|
149
|
+
formatted_dict = {"item": {"id": self.type,"data": {"name": self.name, "scope": self.scope}}}
|
|
150
|
+
_add_slot(formatted_dict, slot)
|
|
151
|
+
return formatted_dict
|
|
152
|
+
|
|
153
|
+
def __repr__(self) -> str:
|
|
154
|
+
return f'{self.__class__.__name__}({self.scope}, "{self.name}")'
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class sound:
|
|
158
|
+
"""
|
|
159
|
+
Represents a DiamondFire sound object.
|
|
160
|
+
"""
|
|
161
|
+
type = 'snd'
|
|
162
|
+
|
|
163
|
+
def __init__(self, name: str, pitch: float=1.0, vol: float=2.0):
|
|
164
|
+
self.name = name
|
|
165
|
+
self.pitch = pitch
|
|
166
|
+
self.vol = vol
|
|
167
|
+
|
|
168
|
+
def format(self, slot: int|None):
|
|
169
|
+
formatted_dict = {"item": {"id": self.type,"data": {"sound": self.name, "pitch": self.pitch, "vol": self.vol}}}
|
|
170
|
+
_add_slot(formatted_dict, slot)
|
|
171
|
+
return formatted_dict
|
|
172
|
+
|
|
173
|
+
def __repr__(self) -> str:
|
|
174
|
+
return f'{self.__class__.__name__}(pitch: {self.pitch}, volume: {self.vol})'
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class particle:
|
|
178
|
+
"""
|
|
179
|
+
Represents a DiamondFire particle object.
|
|
180
|
+
"""
|
|
181
|
+
type = 'part'
|
|
182
|
+
def __init__(self, particle_data: dict):
|
|
183
|
+
self.particle_data = particle_data
|
|
184
|
+
|
|
185
|
+
def format(self, slot: int|None):
|
|
186
|
+
formatted_dict = {"item": {"id": self.type, "data": self.particle_data}}
|
|
187
|
+
_add_slot(formatted_dict, slot)
|
|
188
|
+
return formatted_dict
|
|
189
|
+
|
|
190
|
+
def __repr__(self) -> str:
|
|
191
|
+
return f'{self.__class__.__name__}({self.particle_data})'
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class potion:
|
|
195
|
+
"""
|
|
196
|
+
Represents a DiamondFire potion object.
|
|
197
|
+
"""
|
|
198
|
+
type = 'pot'
|
|
199
|
+
|
|
200
|
+
def __init__(self, name: str, dur: int=1000000, amp: int=0):
|
|
201
|
+
self.name = name
|
|
202
|
+
self.dur = dur
|
|
203
|
+
self.amp = amp
|
|
204
|
+
|
|
205
|
+
def format(self, slot: int|None):
|
|
206
|
+
formatted_dict = {"item": {"id": self.type,"data": {"pot": self.name, "dur": self.dur, "amp": self.amp}}}
|
|
207
|
+
_add_slot(formatted_dict, slot)
|
|
208
|
+
return formatted_dict
|
|
209
|
+
|
|
210
|
+
def __repr__(self) -> str:
|
|
211
|
+
return f'{self.__class__.__name__}(effect: {self.name}, duration: {self.dur}, amplifier: {self.amp})'
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class gamevalue:
|
|
215
|
+
"""
|
|
216
|
+
Represents a DiamondFire game value object.
|
|
217
|
+
"""
|
|
218
|
+
type = 'g_val'
|
|
219
|
+
|
|
220
|
+
def __init__(self, name: str, target: str='Default'):
|
|
221
|
+
self.name = name
|
|
222
|
+
self.target = target
|
|
223
|
+
|
|
224
|
+
def format(self, slot: int|None):
|
|
225
|
+
formatted_dict = {"item": {"id": self.type, "data": {"type": self.name, "target": self.target}}}
|
|
226
|
+
_add_slot(formatted_dict, slot)
|
|
227
|
+
return formatted_dict
|
|
228
|
+
|
|
229
|
+
def __repr__(self) -> str:
|
|
230
|
+
return f'{self.__class__.__name__}({self.name}, target: {self.target})'
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class vector:
|
|
234
|
+
"""
|
|
235
|
+
Represents a DiamondFire vector object.
|
|
236
|
+
"""
|
|
237
|
+
type = 'vec'
|
|
238
|
+
|
|
239
|
+
def __init__(self, x: float=0.0, y: float=0.0, z: float=0.0):
|
|
240
|
+
self.x = float(x)
|
|
241
|
+
self.y = float(y)
|
|
242
|
+
self.z = float(z)
|
|
243
|
+
|
|
244
|
+
def format(self, slot: int|None):
|
|
245
|
+
formatted_dict = {"item": {"id": self.type, "data": {"x": self.x, "y": self.y, "z": self.z}}}
|
|
246
|
+
_add_slot(formatted_dict, slot)
|
|
247
|
+
return formatted_dict
|
|
248
|
+
|
|
249
|
+
def __repr__(self) -> str:
|
|
250
|
+
return f'{self.__class__.__name__}({self.x}, {self.y}, {self.z})'
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
PARAMETER_TYPE_LOOKUP = ['txt', 'comp', 'num', 'loc', 'vec', 'snd', 'part', 'pot', 'item', 'any', 'var', 'list', 'dict']
|
|
254
|
+
|
|
255
|
+
class ParameterType(Enum):
|
|
256
|
+
STRING = 0
|
|
257
|
+
TEXT = 1
|
|
258
|
+
NUMBER = 2
|
|
259
|
+
LOCATION = 3
|
|
260
|
+
VECTOR = 4
|
|
261
|
+
SOUND = 5
|
|
262
|
+
PARTICLE = 6
|
|
263
|
+
POTION_EFFECT = 7
|
|
264
|
+
ITEM = 8
|
|
265
|
+
ANY = 9
|
|
266
|
+
VAR = 10
|
|
267
|
+
LIST = 11
|
|
268
|
+
DICT = 12
|
|
269
|
+
|
|
270
|
+
def get_string_value(self) -> str:
|
|
271
|
+
return PARAMETER_TYPE_LOOKUP[self.value]
|
|
272
|
+
|
|
273
|
+
class parameter:
|
|
274
|
+
"""
|
|
275
|
+
Represents a DiamondFire parameter object.
|
|
276
|
+
"""
|
|
277
|
+
type = 'pn_el'
|
|
278
|
+
|
|
279
|
+
def __init__(self, name: str, param_type: ParameterType, plural: bool=False, optional: bool=False, description: str="", note: str="", default_value=None):
|
|
280
|
+
self.name = name
|
|
281
|
+
self.param_type = param_type
|
|
282
|
+
self.plural = plural
|
|
283
|
+
self.optional = optional
|
|
284
|
+
self.description = description
|
|
285
|
+
self.note = note
|
|
286
|
+
self.default_value = convert_argument(default_value)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def format(self, slot: int):
|
|
290
|
+
formatted_dict = {"item": {
|
|
291
|
+
"id": self.type,
|
|
292
|
+
"data": {
|
|
293
|
+
"name": self.name,
|
|
294
|
+
"type": self.param_type.get_string_value(),
|
|
295
|
+
"plural": self.plural,
|
|
296
|
+
"optional": self.optional,
|
|
297
|
+
}},
|
|
298
|
+
"slot": slot
|
|
299
|
+
}
|
|
300
|
+
if self.description:
|
|
301
|
+
formatted_dict['item']['data']['description'] = self.description
|
|
302
|
+
if self.note:
|
|
303
|
+
formatted_dict['item']['data']['note'] = self.note
|
|
304
|
+
if self.default_value is not None:
|
|
305
|
+
if not self.optional:
|
|
306
|
+
warn(f'For parameter "{self.name}": Default value cannot be set if optional is False.')
|
|
307
|
+
elif self.plural:
|
|
308
|
+
warn(f'For parameter "{self.name}": Default value cannot be set while plural is True.')
|
|
309
|
+
else:
|
|
310
|
+
formatted_dict['item']['data']['default_value'] = self.default_value.format(None)['item']
|
|
311
|
+
|
|
312
|
+
return formatted_dict
|
|
313
|
+
|
|
314
|
+
def __repr__(self) -> str:
|
|
315
|
+
raw_type = str(self.param_type).partition('.')[2]
|
|
316
|
+
return f'{self.__class__.__name__}({self.name}, type: {raw_type})'
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def _some_or(value: Any, none_value: Any):
|
|
320
|
+
"""
|
|
321
|
+
Returns `none_value` if `value` is None, otherwise returns `value`.
|
|
322
|
+
"""
|
|
323
|
+
if value is None:
|
|
324
|
+
return none_value
|
|
325
|
+
return value
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def item_from_dict(item_dict: dict) -> object:
|
|
329
|
+
item_id = item_dict['id']
|
|
330
|
+
item_data = item_dict['data']
|
|
331
|
+
|
|
332
|
+
if item_id == 'item':
|
|
333
|
+
return item.from_nbt(item_data['item'])
|
|
334
|
+
elif item_id == 'txt':
|
|
335
|
+
return string(item_data['name'])
|
|
336
|
+
elif item_id == 'comp':
|
|
337
|
+
return text(item_data['name'])
|
|
338
|
+
elif item_id == 'num':
|
|
339
|
+
num_value = item_data['name']
|
|
340
|
+
if re.match(NUMBER_REGEX, num_value):
|
|
341
|
+
num_value = float(item_data['name'])
|
|
342
|
+
if num_value % 1 == 0:
|
|
343
|
+
num_value = int(num_value)
|
|
344
|
+
return num(num_value)
|
|
345
|
+
return num(num_value)
|
|
346
|
+
elif item_id == 'loc':
|
|
347
|
+
item_loc = item_data['loc']
|
|
348
|
+
return loc(item_loc['x'], item_loc['y'], item_loc['z'], item_loc['pitch'], item_loc['yaw'])
|
|
349
|
+
elif item_id == 'var':
|
|
350
|
+
return var(item_data['name'], item_data['scope'])
|
|
351
|
+
elif item_id == 'snd':
|
|
352
|
+
return sound(item_data['sound'], item_data['pitch'], item_data['vol'])
|
|
353
|
+
elif item_id == 'part':
|
|
354
|
+
return particle(item_data)
|
|
355
|
+
elif item_id == 'pot':
|
|
356
|
+
return potion(item_data['pot'], item_data['dur'], item_data['amp'])
|
|
357
|
+
elif item_id == 'g_val':
|
|
358
|
+
return gamevalue(item_data['type'], item_data['target'])
|
|
359
|
+
elif item_id == 'vec':
|
|
360
|
+
return vector(item_data['x'], item_data['y'], item_data['z'])
|
|
361
|
+
elif item_id == 'pn_el':
|
|
362
|
+
description = _some_or(item_data.get('description'), '')
|
|
363
|
+
note = _some_or(item_data.get('note'), '')
|
|
364
|
+
param_type = ParameterType(PARAMETER_TYPE_LOOKUP.index(item_data['type']))
|
|
365
|
+
if item_data['optional']:
|
|
366
|
+
if 'default_value' in item_data:
|
|
367
|
+
return parameter(item_data['name'], param_type, item_data['plural'], True, description, note, item_from_dict(item_data['default_value']))
|
|
368
|
+
return parameter(item_data['name'], param_type, item_data['plural'], True, description, note)
|
|
369
|
+
return parameter(item_data['name'], param_type, item_data['plural'], False, description, note)
|
|
370
|
+
elif item_id in {'bl_tag', 'hint'}:
|
|
371
|
+
return
|
|
372
|
+
else:
|
|
373
373
|
raise PyreException(f'Unrecognized item id `{item_id}`')
|