dfpyre 0.8.5__tar.gz → 0.8.6__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.6}/LICENSE +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.6}/PKG-INFO +2 -2
- {dfpyre-0.8.5 → dfpyre-0.8.6}/README.md +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/__init__.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/action_literals.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/actiondump.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/data/actiondump_min.json +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/items.py +68 -27
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/pyre.py +15 -13
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/scriptgen.py +5 -5
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/style.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.6}/dfpyre/util.py +0 -0
- {dfpyre-0.8.5 → dfpyre-0.8.6}/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.6
|
|
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}:
|
|
@@ -99,7 +103,7 @@ class Item(NbtItem):
|
|
|
99
103
|
type = 'item'
|
|
100
104
|
|
|
101
105
|
def format(self, slot: int|None):
|
|
102
|
-
formatted_dict = {"item": {"id": self.type, "data": {"item": self.
|
|
106
|
+
formatted_dict = {"item": {"id": self.type, "data": {"item": self.get_snbt()}}}
|
|
103
107
|
_add_slot(formatted_dict, slot)
|
|
104
108
|
return formatted_dict
|
|
105
109
|
|
|
@@ -111,50 +115,87 @@ class Item(NbtItem):
|
|
|
111
115
|
Add a DiamondFire custom tag to this item.
|
|
112
116
|
"""
|
|
113
117
|
if isinstance(tag_value, String):
|
|
114
|
-
|
|
118
|
+
tag = StringTag(tag_value.value)
|
|
119
|
+
elif isinstance(tag_value, str):
|
|
120
|
+
tag = StringTag(tag_value)
|
|
115
121
|
elif isinstance(tag_value, Number):
|
|
116
|
-
|
|
117
|
-
elif isinstance(tag_value, int):
|
|
118
|
-
|
|
122
|
+
tag = DoubleTag(float(tag_value.value))
|
|
123
|
+
elif isinstance(tag_value, (int, float)):
|
|
124
|
+
tag = DoubleTag(float(tag_value))
|
|
119
125
|
|
|
120
126
|
try:
|
|
121
|
-
|
|
127
|
+
custom_data_tag = self.get_component('minecraft:custom_data')
|
|
128
|
+
if 'PublicBukkitValues' in custom_data_tag:
|
|
129
|
+
pbv_tag = custom_data_tag['PublicBukkitValues']
|
|
130
|
+
else:
|
|
131
|
+
pbv_tag = CompoundTag()
|
|
122
132
|
except MCItemlibException:
|
|
123
|
-
|
|
133
|
+
custom_data_tag = CompoundTag()
|
|
134
|
+
pbv_tag = CompoundTag()
|
|
124
135
|
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
custom_data_tag['PublicBukkitValues'] = pbv_tag
|
|
137
|
+
|
|
138
|
+
pbv_tag[f'hypercube:{tag_name}'] = tag
|
|
139
|
+
self.set_component('minecraft:custom_data', custom_data_tag)
|
|
127
140
|
|
|
128
141
|
def get_tag(self, tag_name: str) -> str|float|None:
|
|
129
142
|
"""
|
|
130
143
|
Get a DiamondFire custom tag from this item.
|
|
131
144
|
"""
|
|
132
145
|
try:
|
|
133
|
-
|
|
146
|
+
custom_data_tag = self.get_component('minecraft:custom_data')
|
|
134
147
|
except MCItemlibException:
|
|
135
148
|
return None
|
|
136
149
|
|
|
137
|
-
|
|
138
|
-
return
|
|
139
|
-
|
|
150
|
+
if 'PublicBukkitValues' not in custom_data_tag:
|
|
151
|
+
return None
|
|
152
|
+
|
|
153
|
+
pbv_tag = custom_data_tag['PublicBukkitValues']
|
|
154
|
+
df_tag_value = pbv_tag.get(f'hypercube:{tag_name}')
|
|
155
|
+
if df_tag_value is None:
|
|
140
156
|
return None
|
|
157
|
+
|
|
158
|
+
if isinstance(df_tag_value, DoubleTag):
|
|
159
|
+
return float(df_tag_value)
|
|
160
|
+
if isinstance(df_tag_value, StringTag):
|
|
161
|
+
return str(df_tag_value)
|
|
141
162
|
|
|
142
|
-
def remove_tag(self, tag_name: str)
|
|
163
|
+
def remove_tag(self, tag_name: str):
|
|
143
164
|
"""
|
|
144
165
|
Remove a DiamondFire custom tag from this item.
|
|
145
|
-
|
|
146
|
-
:return: `True` on success, `False` on fail
|
|
147
166
|
"""
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return False
|
|
167
|
+
custom_data_tag = self.get_component('minecraft:custom_data')
|
|
168
|
+
pbv_tag = custom_data_tag['PublicBukkitValues']
|
|
169
|
+
del pbv_tag[f'hypercube:{tag_name}']
|
|
152
170
|
|
|
171
|
+
return True
|
|
172
|
+
|
|
173
|
+
def send_to_minecraft(self):
|
|
174
|
+
"""
|
|
175
|
+
Sends this item to Minecraft automatically.
|
|
176
|
+
"""
|
|
153
177
|
try:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
178
|
+
ws = websocket.WebSocket()
|
|
179
|
+
ws.connect(CODECLIENT_URL)
|
|
180
|
+
print(f'{COL_SUCCESS}Connected.{COL_RESET}')
|
|
181
|
+
|
|
182
|
+
command = f'give {self.get_snbt()}'
|
|
183
|
+
ws.send(command)
|
|
184
|
+
ws.close()
|
|
185
|
+
|
|
186
|
+
print(f'{COL_SUCCESS}Item sent to client successfully.{COL_RESET}')
|
|
187
|
+
return 0
|
|
188
|
+
|
|
189
|
+
except Exception as e:
|
|
190
|
+
if isinstance(e, ConnectionRefusedError):
|
|
191
|
+
print(f'{COL_ERROR}Could not connect to CodeClient API. Possible problems:')
|
|
192
|
+
print(f' - Minecraft is not open')
|
|
193
|
+
print(f' - CodeClient is not installed (get it here: https://modrinth.com/mod/codeclient)')
|
|
194
|
+
print(f' - CodeClient API is not enabled (enable it in CodeClient general settings)')
|
|
195
|
+
return 1
|
|
196
|
+
|
|
197
|
+
print(f'Connection failed: {e}')
|
|
198
|
+
return 2
|
|
158
199
|
|
|
159
200
|
|
|
160
201
|
class Location:
|
|
@@ -390,7 +431,7 @@ def item_from_dict(item_dict: dict) -> Any:
|
|
|
390
431
|
item_data = item_dict['data']
|
|
391
432
|
|
|
392
433
|
if item_id == 'item':
|
|
393
|
-
return Item.
|
|
434
|
+
return Item.from_snbt(item_data['item'])
|
|
394
435
|
|
|
395
436
|
elif item_id == 'txt':
|
|
396
437
|
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.6"
|
|
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]
|