dfpyre 0.8.5__tar.gz → 0.8.7__tar.gz
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-0.8.5 → dfpyre-0.8.7}/LICENSE +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.7}/PKG-INFO +2 -2
- {dfpyre-0.8.5 → dfpyre-0.8.7}/README.md +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/__init__.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/action_literals.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/actiondump.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/data/actiondump_min.json +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/items.py +111 -52
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/pyre.py +15 -13
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/scriptgen.py +5 -5
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/style.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.7}/dfpyre/util.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.7}/pyproject.toml +2 -2
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dfpyre
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.7
|
|
4
4
|
Summary: A package for creating and modifying code templates for the DiamondFire Minecraft server.
|
|
5
5
|
Home-page: https://github.com/Amp63/pyre
|
|
6
6
|
License: MIT
|
|
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
-
Requires-Dist: mcitemlib (>=0.
|
|
15
|
+
Requires-Dist: mcitemlib (>=0.4.1,<0.5.0)
|
|
16
16
|
Project-URL: Repository, https://github.com/Amp63/pyre
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -5,15 +5,19 @@ Class definitions for code items.
|
|
|
5
5
|
from enum import Enum
|
|
6
6
|
import re
|
|
7
7
|
from typing import Literal, Any
|
|
8
|
-
|
|
9
|
-
from dfpyre.util import PyreException, warn
|
|
8
|
+
import websocket
|
|
10
9
|
from mcitemlib.itemlib import Item as NbtItem, MCItemlibException
|
|
10
|
+
from amulet_nbt import DoubleTag, StringTag, CompoundTag
|
|
11
|
+
from dfpyre.style import is_ampersand_coded, ampersand_to_minimessage
|
|
12
|
+
from dfpyre.util import PyreException, warn, COL_SUCCESS, COL_WARN, COL_ERROR, COL_RESET
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
NUMBER_REGEX = r'^-?\d*\.?\d+$'
|
|
14
16
|
VAR_SHORTHAND_REGEX = r'^\$([gsli]) (.+)$'
|
|
15
17
|
VAR_SCOPES = {'g': 'unsaved', 's': 'saved', 'l': 'local', 'i': 'line'}
|
|
16
18
|
|
|
19
|
+
CODECLIENT_URL = 'ws://localhost:31375'
|
|
20
|
+
|
|
17
21
|
|
|
18
22
|
def convert_argument(arg: Any):
|
|
19
23
|
if type(arg) in {int, float}:
|
|
@@ -38,12 +42,13 @@ class String:
|
|
|
38
42
|
"""
|
|
39
43
|
type = 'txt'
|
|
40
44
|
|
|
41
|
-
def __init__(self, value: str):
|
|
45
|
+
def __init__(self, value: str, slot: int|None=None):
|
|
42
46
|
self.value = value
|
|
47
|
+
self.slot = slot
|
|
43
48
|
|
|
44
49
|
def format(self, slot: int|None):
|
|
45
50
|
formatted_dict = {"item": {"id": self.type, "data": {"name": self.value}}}
|
|
46
|
-
_add_slot(formatted_dict, slot)
|
|
51
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
47
52
|
return formatted_dict
|
|
48
53
|
|
|
49
54
|
def __repr__(self) -> str:
|
|
@@ -58,14 +63,15 @@ class Text:
|
|
|
58
63
|
"""
|
|
59
64
|
type = 'comp'
|
|
60
65
|
|
|
61
|
-
def __init__(self, value: str):
|
|
66
|
+
def __init__(self, value: str, slot: int|None=None):
|
|
62
67
|
if is_ampersand_coded(value):
|
|
63
68
|
value = ampersand_to_minimessage(value)
|
|
64
69
|
self.value = value
|
|
70
|
+
self.slot = slot
|
|
65
71
|
|
|
66
72
|
def format(self, slot: int|None):
|
|
67
73
|
formatted_dict = {"item": {"id": self.type, "data": {"name": self.value}}}
|
|
68
|
-
_add_slot(formatted_dict, slot)
|
|
74
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
69
75
|
return formatted_dict
|
|
70
76
|
|
|
71
77
|
def __repr__(self) -> str:
|
|
@@ -78,12 +84,13 @@ class Number:
|
|
|
78
84
|
"""
|
|
79
85
|
type = 'num'
|
|
80
86
|
|
|
81
|
-
def __init__(self, num: int|float|str):
|
|
87
|
+
def __init__(self, num: int|float|str, slot: int|None=None):
|
|
82
88
|
self.value = num
|
|
89
|
+
self.slot = slot
|
|
83
90
|
|
|
84
91
|
def format(self, slot: int|None):
|
|
85
92
|
formatted_dict = {"item": {"id": self.type, "data": {"name": str(self.value)}}}
|
|
86
|
-
_add_slot(formatted_dict, slot)
|
|
93
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
87
94
|
return formatted_dict
|
|
88
95
|
|
|
89
96
|
def __repr__(self) -> str:
|
|
@@ -98,9 +105,13 @@ class Item(NbtItem):
|
|
|
98
105
|
"""
|
|
99
106
|
type = 'item'
|
|
100
107
|
|
|
108
|
+
def __init__(self, item_id: str, count: int=1, slot: int | None=None):
|
|
109
|
+
super().__init__(item_id, count)
|
|
110
|
+
self.slot = slot
|
|
111
|
+
|
|
101
112
|
def format(self, slot: int|None):
|
|
102
|
-
formatted_dict = {"item": {"id": self.type, "data": {"item": self.
|
|
103
|
-
_add_slot(formatted_dict, slot)
|
|
113
|
+
formatted_dict = {"item": {"id": self.type, "data": {"item": self.get_snbt()}}}
|
|
114
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
104
115
|
return formatted_dict
|
|
105
116
|
|
|
106
117
|
def __repr__(self) -> str:
|
|
@@ -111,50 +122,87 @@ class Item(NbtItem):
|
|
|
111
122
|
Add a DiamondFire custom tag to this item.
|
|
112
123
|
"""
|
|
113
124
|
if isinstance(tag_value, String):
|
|
114
|
-
|
|
125
|
+
tag = StringTag(tag_value.value)
|
|
126
|
+
elif isinstance(tag_value, str):
|
|
127
|
+
tag = StringTag(tag_value)
|
|
115
128
|
elif isinstance(tag_value, Number):
|
|
116
|
-
|
|
117
|
-
elif isinstance(tag_value, int):
|
|
118
|
-
|
|
129
|
+
tag = DoubleTag(float(tag_value.value))
|
|
130
|
+
elif isinstance(tag_value, (int, float)):
|
|
131
|
+
tag = DoubleTag(float(tag_value))
|
|
119
132
|
|
|
120
133
|
try:
|
|
121
|
-
|
|
134
|
+
custom_data_tag = self.get_component('minecraft:custom_data')
|
|
135
|
+
if 'PublicBukkitValues' in custom_data_tag:
|
|
136
|
+
pbv_tag = custom_data_tag['PublicBukkitValues']
|
|
137
|
+
else:
|
|
138
|
+
pbv_tag = CompoundTag()
|
|
122
139
|
except MCItemlibException:
|
|
123
|
-
|
|
140
|
+
custom_data_tag = CompoundTag()
|
|
141
|
+
pbv_tag = CompoundTag()
|
|
124
142
|
|
|
125
|
-
|
|
126
|
-
|
|
143
|
+
custom_data_tag['PublicBukkitValues'] = pbv_tag
|
|
144
|
+
|
|
145
|
+
pbv_tag[f'hypercube:{tag_name}'] = tag
|
|
146
|
+
self.set_component('minecraft:custom_data', custom_data_tag)
|
|
127
147
|
|
|
128
148
|
def get_tag(self, tag_name: str) -> str|float|None:
|
|
129
149
|
"""
|
|
130
150
|
Get a DiamondFire custom tag from this item.
|
|
131
151
|
"""
|
|
132
152
|
try:
|
|
133
|
-
|
|
153
|
+
custom_data_tag = self.get_component('minecraft:custom_data')
|
|
134
154
|
except MCItemlibException:
|
|
135
155
|
return None
|
|
136
156
|
|
|
137
|
-
|
|
138
|
-
return item_tags[f'hypercube:{tag_name}']
|
|
139
|
-
except KeyError:
|
|
157
|
+
if 'PublicBukkitValues' not in custom_data_tag:
|
|
140
158
|
return None
|
|
159
|
+
|
|
160
|
+
pbv_tag = custom_data_tag['PublicBukkitValues']
|
|
161
|
+
df_tag_value = pbv_tag.get(f'hypercube:{tag_name}')
|
|
162
|
+
if df_tag_value is None:
|
|
163
|
+
return None
|
|
164
|
+
|
|
165
|
+
if isinstance(df_tag_value, DoubleTag):
|
|
166
|
+
return float(df_tag_value)
|
|
167
|
+
if isinstance(df_tag_value, StringTag):
|
|
168
|
+
return str(df_tag_value)
|
|
141
169
|
|
|
142
|
-
def remove_tag(self, tag_name: str)
|
|
170
|
+
def remove_tag(self, tag_name: str):
|
|
143
171
|
"""
|
|
144
172
|
Remove a DiamondFire custom tag from this item.
|
|
145
|
-
|
|
146
|
-
:return: `True` on success, `False` on fail
|
|
147
173
|
"""
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return False
|
|
174
|
+
custom_data_tag = self.get_component('minecraft:custom_data')
|
|
175
|
+
pbv_tag = custom_data_tag['PublicBukkitValues']
|
|
176
|
+
del pbv_tag[f'hypercube:{tag_name}']
|
|
152
177
|
|
|
178
|
+
return True
|
|
179
|
+
|
|
180
|
+
def send_to_minecraft(self):
|
|
181
|
+
"""
|
|
182
|
+
Sends this item to Minecraft automatically.
|
|
183
|
+
"""
|
|
153
184
|
try:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
185
|
+
ws = websocket.WebSocket()
|
|
186
|
+
ws.connect(CODECLIENT_URL)
|
|
187
|
+
print(f'{COL_SUCCESS}Connected.{COL_RESET}')
|
|
188
|
+
|
|
189
|
+
command = f'give {self.get_snbt()}'
|
|
190
|
+
ws.send(command)
|
|
191
|
+
ws.close()
|
|
192
|
+
|
|
193
|
+
print(f'{COL_SUCCESS}Item sent to client successfully.{COL_RESET}')
|
|
194
|
+
return 0
|
|
195
|
+
|
|
196
|
+
except Exception as e:
|
|
197
|
+
if isinstance(e, ConnectionRefusedError):
|
|
198
|
+
print(f'{COL_ERROR}Could not connect to CodeClient API. Possible problems:')
|
|
199
|
+
print(f' - Minecraft is not open')
|
|
200
|
+
print(f' - CodeClient is not installed (get it here: https://modrinth.com/mod/codeclient)')
|
|
201
|
+
print(f' - CodeClient API is not enabled (enable it in CodeClient general settings){COL_RESET}')
|
|
202
|
+
return 1
|
|
203
|
+
|
|
204
|
+
print(f'Connection failed: {e}')
|
|
205
|
+
return 2
|
|
158
206
|
|
|
159
207
|
|
|
160
208
|
class Location:
|
|
@@ -163,12 +211,13 @@ class Location:
|
|
|
163
211
|
"""
|
|
164
212
|
type = 'loc'
|
|
165
213
|
|
|
166
|
-
def __init__(self, x: float=0, y: float=0, z: float=0, pitch: float=0, yaw: float=0):
|
|
214
|
+
def __init__(self, x: float=0, y: float=0, z: float=0, pitch: float=0, yaw: float=0, slot: int | None=None):
|
|
167
215
|
self.x = float(x)
|
|
168
216
|
self.y = float(y)
|
|
169
217
|
self.z = float(z)
|
|
170
218
|
self.pitch = float(pitch)
|
|
171
219
|
self.yaw = float(yaw)
|
|
220
|
+
self.slot = slot
|
|
172
221
|
|
|
173
222
|
def format(self, slot: int|None):
|
|
174
223
|
formatted_dict = {"item": {
|
|
@@ -184,7 +233,7 @@ class Location:
|
|
|
184
233
|
}
|
|
185
234
|
}
|
|
186
235
|
}}
|
|
187
|
-
_add_slot(formatted_dict, slot)
|
|
236
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
188
237
|
return formatted_dict
|
|
189
238
|
|
|
190
239
|
def __repr__(self) -> str:
|
|
@@ -199,16 +248,18 @@ class Variable:
|
|
|
199
248
|
"""
|
|
200
249
|
type = 'var'
|
|
201
250
|
|
|
202
|
-
def __init__(self, name: str, scope: Literal['unsaved', 'game', 'saved', 'local', 'line']='unsaved'):
|
|
251
|
+
def __init__(self, name: str, scope: Literal['unsaved', 'game', 'saved', 'local', 'line']='unsaved', slot: int | None=None):
|
|
203
252
|
self.name = name
|
|
204
253
|
|
|
205
254
|
if scope == 'game':
|
|
206
255
|
scope = 'unsaved'
|
|
207
256
|
self.scope = scope
|
|
257
|
+
|
|
258
|
+
self.slot = slot
|
|
208
259
|
|
|
209
260
|
def format(self, slot: int|None):
|
|
210
261
|
formatted_dict = {"item": {"id": self.type,"data": {"name": self.name, "scope": self.scope}}}
|
|
211
|
-
_add_slot(formatted_dict, slot)
|
|
262
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
212
263
|
return formatted_dict
|
|
213
264
|
|
|
214
265
|
def __repr__(self) -> str:
|
|
@@ -223,14 +274,15 @@ class Sound:
|
|
|
223
274
|
"""
|
|
224
275
|
type = 'snd'
|
|
225
276
|
|
|
226
|
-
def __init__(self, name: str, pitch: float=1.0, vol: float=2.0):
|
|
277
|
+
def __init__(self, name: str, pitch: float=1.0, vol: float=2.0, slot: int | None=None):
|
|
227
278
|
self.name = name
|
|
228
279
|
self.pitch = pitch
|
|
229
280
|
self.vol = vol
|
|
281
|
+
self.slot = slot
|
|
230
282
|
|
|
231
283
|
def format(self, slot: int|None):
|
|
232
284
|
formatted_dict = {"item": {"id": self.type,"data": {"sound": self.name, "pitch": self.pitch, "vol": self.vol}}}
|
|
233
|
-
_add_slot(formatted_dict, slot)
|
|
285
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
234
286
|
return formatted_dict
|
|
235
287
|
|
|
236
288
|
def __repr__(self) -> str:
|
|
@@ -244,12 +296,13 @@ class Particle:
|
|
|
244
296
|
Represents a DiamondFire particle object.
|
|
245
297
|
"""
|
|
246
298
|
type = 'part'
|
|
247
|
-
def __init__(self, particle_data: dict):
|
|
299
|
+
def __init__(self, particle_data: dict, slot: int | None=None):
|
|
248
300
|
self.particle_data = particle_data
|
|
301
|
+
self.slot = slot
|
|
249
302
|
|
|
250
303
|
def format(self, slot: int|None):
|
|
251
304
|
formatted_dict = {"item": {"id": self.type, "data": self.particle_data}}
|
|
252
|
-
_add_slot(formatted_dict, slot)
|
|
305
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
253
306
|
return formatted_dict
|
|
254
307
|
|
|
255
308
|
def __repr__(self) -> str:
|
|
@@ -262,14 +315,15 @@ class Potion:
|
|
|
262
315
|
"""
|
|
263
316
|
type = 'pot'
|
|
264
317
|
|
|
265
|
-
def __init__(self, name: str, dur: int=1000000, amp: int=0):
|
|
318
|
+
def __init__(self, name: str, dur: int=1000000, amp: int=0, slot: int | None=None):
|
|
266
319
|
self.name = name
|
|
267
320
|
self.dur = dur
|
|
268
321
|
self.amp = amp
|
|
322
|
+
self.slot = slot
|
|
269
323
|
|
|
270
324
|
def format(self, slot: int|None):
|
|
271
325
|
formatted_dict = {"item": {"id": self.type,"data": {"pot": self.name, "dur": self.dur, "amp": self.amp}}}
|
|
272
|
-
_add_slot(formatted_dict, slot)
|
|
326
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
273
327
|
return formatted_dict
|
|
274
328
|
|
|
275
329
|
def __repr__(self) -> str:
|
|
@@ -284,13 +338,14 @@ class GameValue:
|
|
|
284
338
|
"""
|
|
285
339
|
type = 'g_val'
|
|
286
340
|
|
|
287
|
-
def __init__(self, name: str, target: str='Default'):
|
|
341
|
+
def __init__(self, name: str, target: str='Default', slot: int | None=None):
|
|
288
342
|
self.name = name
|
|
289
343
|
self.target = target
|
|
344
|
+
self.slot = slot
|
|
290
345
|
|
|
291
346
|
def format(self, slot: int|None):
|
|
292
347
|
formatted_dict = {"item": {"id": self.type, "data": {"type": self.name, "target": self.target}}}
|
|
293
|
-
_add_slot(formatted_dict, slot)
|
|
348
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
294
349
|
return formatted_dict
|
|
295
350
|
|
|
296
351
|
def __repr__(self) -> str:
|
|
@@ -303,14 +358,15 @@ class Vector:
|
|
|
303
358
|
"""
|
|
304
359
|
type = 'vec'
|
|
305
360
|
|
|
306
|
-
def __init__(self, x: float=0.0, y: float=0.0, z: float=0.0):
|
|
361
|
+
def __init__(self, x: float=0.0, y: float=0.0, z: float=0.0, slot: int | None=None):
|
|
307
362
|
self.x = float(x)
|
|
308
363
|
self.y = float(y)
|
|
309
364
|
self.z = float(z)
|
|
365
|
+
self.slot = slot
|
|
310
366
|
|
|
311
367
|
def format(self, slot: int|None):
|
|
312
368
|
formatted_dict = {"item": {"id": self.type, "data": {"x": self.x, "y": self.y, "z": self.z}}}
|
|
313
|
-
_add_slot(formatted_dict, slot)
|
|
369
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
314
370
|
return formatted_dict
|
|
315
371
|
|
|
316
372
|
def __repr__(self) -> str:
|
|
@@ -319,6 +375,7 @@ class Vector:
|
|
|
319
375
|
Vec = Vector # Vector alias
|
|
320
376
|
|
|
321
377
|
|
|
378
|
+
|
|
322
379
|
PARAMETER_TYPE_LOOKUP = ['txt', 'comp', 'num', 'loc', 'vec', 'snd', 'part', 'pot', 'item', 'any', 'var', 'list', 'dict']
|
|
323
380
|
|
|
324
381
|
class ParameterType(Enum):
|
|
@@ -345,7 +402,8 @@ class Parameter:
|
|
|
345
402
|
"""
|
|
346
403
|
type = 'pn_el'
|
|
347
404
|
|
|
348
|
-
def __init__(self, name: str, param_type: ParameterType, plural: bool=False, optional: bool=False,
|
|
405
|
+
def __init__(self, name: str, param_type: ParameterType, plural: bool=False, optional: bool=False,
|
|
406
|
+
description: str="", note: str="", default_value=None, slot: int | None=None):
|
|
349
407
|
self.name = name
|
|
350
408
|
self.param_type = param_type
|
|
351
409
|
self.plural = plural
|
|
@@ -353,7 +411,7 @@ class Parameter:
|
|
|
353
411
|
self.description = description
|
|
354
412
|
self.note = note
|
|
355
413
|
self.default_value = convert_argument(default_value)
|
|
356
|
-
|
|
414
|
+
self.slot = slot
|
|
357
415
|
|
|
358
416
|
def format(self, slot: int):
|
|
359
417
|
formatted_dict = {"item": {
|
|
@@ -363,9 +421,10 @@ class Parameter:
|
|
|
363
421
|
"type": self.param_type.get_string_value(),
|
|
364
422
|
"plural": self.plural,
|
|
365
423
|
"optional": self.optional,
|
|
366
|
-
}}
|
|
367
|
-
"slot": slot
|
|
424
|
+
}}
|
|
368
425
|
}
|
|
426
|
+
_add_slot(formatted_dict, self.slot or slot)
|
|
427
|
+
|
|
369
428
|
if self.description:
|
|
370
429
|
formatted_dict['item']['data']['description'] = self.description
|
|
371
430
|
if self.note:
|
|
@@ -390,7 +449,7 @@ def item_from_dict(item_dict: dict) -> Any:
|
|
|
390
449
|
item_data = item_dict['data']
|
|
391
450
|
|
|
392
451
|
if item_id == 'item':
|
|
393
|
-
return Item.
|
|
452
|
+
return Item.from_snbt(item_data['item'])
|
|
394
453
|
|
|
395
454
|
elif item_id == 'txt':
|
|
396
455
|
return String(item_data['name'])
|
|
@@ -8,7 +8,7 @@ import json
|
|
|
8
8
|
from difflib import get_close_matches
|
|
9
9
|
import datetime
|
|
10
10
|
from enum import Enum
|
|
11
|
-
from
|
|
11
|
+
from amulet_nbt import CompoundTag
|
|
12
12
|
from dfpyre.util import *
|
|
13
13
|
from dfpyre.items import *
|
|
14
14
|
from dfpyre.scriptgen import generate_script, GeneratorFlags
|
|
@@ -162,7 +162,7 @@ def _check_applied_tags(tags: list[dict], applied_tags: dict[str, str], codebloc
|
|
|
162
162
|
|
|
163
163
|
def _reformat_codeblock_tags(tags: list[dict], codeblock_type: str, codeblock_action: str, applied_tags: dict[str, str]):
|
|
164
164
|
"""
|
|
165
|
-
Turns tag objects into DiamondFire formatted tag items
|
|
165
|
+
Turns tag objects into DiamondFire formatted tag items.
|
|
166
166
|
"""
|
|
167
167
|
|
|
168
168
|
def format_tag(option: str, name: str):
|
|
@@ -189,7 +189,7 @@ def _reformat_codeblock_tags(tags: list[dict], codeblock_type: str, codeblock_ac
|
|
|
189
189
|
|
|
190
190
|
def _get_codeblock_tags(codeblock_type: str, codeblock_name: str, applied_tags: dict[str, str]):
|
|
191
191
|
"""
|
|
192
|
-
Get tags for the specified codeblock type and name
|
|
192
|
+
Get tags for the specified codeblock type and name.
|
|
193
193
|
"""
|
|
194
194
|
action_data = CODEBLOCK_DATA[codeblock_type][codeblock_name]
|
|
195
195
|
if 'deprecatedNote' in action_data:
|
|
@@ -198,10 +198,10 @@ def _get_codeblock_tags(codeblock_type: str, codeblock_name: str, applied_tags:
|
|
|
198
198
|
return _reformat_codeblock_tags(tags, codeblock_type, codeblock_name, applied_tags)
|
|
199
199
|
|
|
200
200
|
|
|
201
|
-
def
|
|
201
|
+
def _generate_template_item(template_code: str, name: str, author: str) -> Item:
|
|
202
202
|
now = datetime.datetime.now()
|
|
203
203
|
|
|
204
|
-
template_item =
|
|
204
|
+
template_item = Item('yellow_shulker_box')
|
|
205
205
|
template_item.set_name(f'&x&f&f&5&c&0&0>> &x&f&f&c&7&0&0{name}')
|
|
206
206
|
template_item.set_lore([
|
|
207
207
|
f'&8Author: {author}',
|
|
@@ -211,11 +211,13 @@ def _get_template_item(template_code: str, name: str, author: str) -> NbtItem:
|
|
|
211
211
|
'&7https://github.com/Amp63/pyre'
|
|
212
212
|
])
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
'
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
custom_data_tag = CompoundTag({
|
|
215
|
+
'PublicBukkitValues': CompoundTag({
|
|
216
|
+
'hypercube:codetemplatedata': StringTag(f'{{"author":"{author}","name":"{name}","version": 1,"code":"{template_code}"}}'),
|
|
217
|
+
'hypercube:pyre_creation_timestamp': DoubleTag(now.timestamp())
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
template_item.set_component('minecraft:custom_data', custom_data_tag)
|
|
219
221
|
|
|
220
222
|
return template_item
|
|
221
223
|
|
|
@@ -316,15 +318,15 @@ class DFTemplate:
|
|
|
316
318
|
return df_encode(json_string)
|
|
317
319
|
|
|
318
320
|
|
|
319
|
-
def build_and_send(self,
|
|
321
|
+
def build_and_send(self, include_tags: bool=True) -> int:
|
|
320
322
|
"""
|
|
321
323
|
Builds this template and sends it to DiamondFire automatically.
|
|
322
324
|
|
|
323
325
|
:param bool include_tags: If True, include item tags in code blocks. Otherwise omit them.
|
|
324
326
|
"""
|
|
325
327
|
template_code = self.build(include_tags)
|
|
326
|
-
template_item =
|
|
327
|
-
return template_item.send_to_minecraft(
|
|
328
|
+
template_item = _generate_template_item(template_code, self._get_template_name(), self.author)
|
|
329
|
+
return template_item.send_to_minecraft()
|
|
328
330
|
|
|
329
331
|
|
|
330
332
|
def generate_script(self, output_path: str, indent_size: int=4, literal_shorthand: bool=True, var_shorthand: bool=False):
|
|
@@ -40,13 +40,13 @@ class GeneratorFlags:
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
def item_to_string(class_name: str, i: Item):
|
|
43
|
-
i.nbt.
|
|
43
|
+
i.nbt.pop('DF_NBT', None)
|
|
44
44
|
stripped_id = i.get_id().replace('minecraft:', '')
|
|
45
|
-
if i.nbt.
|
|
45
|
+
if set(i.nbt.keys()) == {'id', 'count'}:
|
|
46
46
|
if i.get_count() == 1:
|
|
47
47
|
return f'{class_name}("{stripped_id}")'
|
|
48
48
|
return f'{class_name}("{stripped_id}", {i.get_count()})'
|
|
49
|
-
return f'{class_name}.
|
|
49
|
+
return f'{class_name}.from_snbt("""{i.get_snbt()}""")'
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
def argument_item_to_string(flags: GeneratorFlags, arg_item: object) -> str:
|
|
@@ -56,12 +56,12 @@ def argument_item_to_string(flags: GeneratorFlags, arg_item: object) -> str:
|
|
|
56
56
|
|
|
57
57
|
if isinstance(arg_item, String):
|
|
58
58
|
value = arg_item.value.replace('\n', '\\n')
|
|
59
|
+
if flags.literal_shorthand:
|
|
60
|
+
return f'"{value}"'
|
|
59
61
|
return f'{class_name}("{value}")'
|
|
60
62
|
|
|
61
63
|
if isinstance(arg_item, Text):
|
|
62
64
|
value = arg_item.value.replace('\n', '\\n')
|
|
63
|
-
if flags.literal_shorthand:
|
|
64
|
-
return f'"{value}"'
|
|
65
65
|
return f'{class_name}("{value}")'
|
|
66
66
|
|
|
67
67
|
if isinstance(arg_item, Number):
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "dfpyre"
|
|
3
|
-
version = "0.8.
|
|
3
|
+
version = "0.8.7"
|
|
4
4
|
description = "A package for creating and modifying code templates for the DiamondFire Minecraft server."
|
|
5
5
|
authors = ["Amp"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -12,7 +12,7 @@ exclude = ['examples', 'extra']
|
|
|
12
12
|
|
|
13
13
|
[tool.poetry.dependencies]
|
|
14
14
|
python = "^3.10"
|
|
15
|
-
mcitemlib = "^0.
|
|
15
|
+
mcitemlib = "^0.4.1"
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
[build-system]
|