dfpyre 0.8.4__py3-none-any.whl → 0.8.6__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/__init__.py CHANGED
File without changes
dfpyre/action_literals.py CHANGED
File without changes
dfpyre/actiondump.py CHANGED
File without changes
File without changes
dfpyre/items.py CHANGED
@@ -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
- from dfpyre.style import is_ampersand_coded, ampersand_to_minimessage
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}:
@@ -23,7 +27,7 @@ def convert_argument(arg: Any):
23
27
  if shorthand_match:
24
28
  scope = VAR_SCOPES[shorthand_match.group(1)]
25
29
  return Variable(shorthand_match.group(2), scope)
26
- return Text(arg)
30
+ return String(arg)
27
31
  return arg
28
32
 
29
33
 
@@ -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.get_nbt()}}}
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
- tag_value = tag_value.value
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
- tag_value = float(tag_value.value)
117
- elif isinstance(tag_value, int):
118
- tag_value = float(tag_value)
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
- item_tags = self.get_custom_data('PublicBukkitValues')
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
- item_tags = {}
133
+ custom_data_tag = CompoundTag()
134
+ pbv_tag = CompoundTag()
124
135
 
125
- item_tags[f'hypercube:{tag_name}'] = tag_value
126
- self.set_custom_data('PublicBukkitValues', item_tags)
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
- item_tags = self.get_custom_data('PublicBukkitValues')
146
+ custom_data_tag = self.get_component('minecraft:custom_data')
134
147
  except MCItemlibException:
135
148
  return None
136
149
 
137
- try:
138
- return item_tags[f'hypercube:{tag_name}']
139
- except KeyError:
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) -> bool:
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
- try:
149
- item_tags = self.get_custom_data('PublicBukkitValues')
150
- except MCItemlibException:
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
- del item_tags[f'hypercube:{tag_name}']
155
- return True
156
- except KeyError:
157
- return False
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.from_nbt(item_data['item'])
434
+ return Item.from_snbt(item_data['item'])
394
435
 
395
436
  elif item_id == 'txt':
396
437
  return String(item_data['name'])
@@ -443,4 +484,4 @@ def item_from_dict(item_dict: dict) -> Any:
443
484
  return
444
485
 
445
486
  else:
446
- raise PyreException(f'Unrecognized item id `{item_id}`')
487
+ raise PyreException(f'Unrecognized item id `{item_id}`')
dfpyre/pyre.py CHANGED
@@ -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 mcitemlib.itemlib import Item as NbtItem
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 _get_template_item(template_code: str, name: str, author: str) -> NbtItem:
201
+ def _generate_template_item(template_code: str, name: str, author: str) -> Item:
202
202
  now = datetime.datetime.now()
203
203
 
204
- template_item = NbtItem('yellow_shulker_box')
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
- pbv_tag = {
215
- 'hypercube:codetemplatedata': f'{{"author":"{author}","name":"{name}","version": 1,"code":"{template_code}"}}',
216
- 'hypercube:pyre_creation_timestamp': now.timestamp()
217
- }
218
- template_item.set_custom_data('PublicBukkitValues', pbv_tag, raw=True)
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, method: Literal['recode', 'codeclient'], include_tags: bool=True) -> int:
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 = _get_template_item(template_code, self._get_template_name(), self.author)
327
- return template_item.send_to_minecraft(method, 'pyre')
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):
dfpyre/scriptgen.py CHANGED
@@ -40,13 +40,13 @@ class GeneratorFlags:
40
40
 
41
41
 
42
42
  def item_to_string(class_name: str, i: Item):
43
- i.nbt.data.pop('~DF_NBT', None)
43
+ i.nbt.pop('DF_NBT', None)
44
44
  stripped_id = i.get_id().replace('minecraft:', '')
45
- if i.nbt.key_set() == {'~id', '~count'}:
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}.from_nbt("""{i.get_nbt()}""")'
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):
dfpyre/style.py CHANGED
File without changes
dfpyre/util.py CHANGED
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dfpyre
3
- Version: 0.8.4
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.3.4,<0.4.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
 
@@ -38,7 +38,7 @@ This module works best with [CodeClient](https://modrinth.com/mod/codeclient) in
38
38
  - All code block types
39
39
  - All code item types
40
40
  - Direct sending to DF via recode or codeclient
41
- - Automatic type conversion (int to num, str to text)
41
+ - Automatic type conversion (`int` to `Number`, `str` to `String`)
42
42
  - Auto completed action names (if your IDE supports type hints)
43
43
  - Warnings for unrecognized actions and tags
44
44
  - Shorthand format for variables
@@ -0,0 +1,13 @@
1
+ dfpyre/__init__.py,sha256=apPsSxJ1Tztfl71MoORoSmDfX7LyKLYlLwOGeLQUitw,25
2
+ dfpyre/action_literals.py,sha256=jvI3ZI1_rnDqS58q5Z0_bb5jgKJ2pu_pgN-1whXpEDQ,16212
3
+ dfpyre/actiondump.py,sha256=MVI1kVJBNpab882Tgqo-xtemiBN2W1_2OcopBcRupWQ,2587
4
+ dfpyre/data/actiondump_min.json,sha256=hFcIbG_G55FWwqRSW6X77ZrKkQiXLs4CGgJrZgyR2Gg,1938799
5
+ dfpyre/items.py,sha256=9HR5vKR1zHOfhd2RW-j1a7klDTXvGlML3qNmF4C1XXk,15024
6
+ dfpyre/pyre.py,sha256=mVyoW3VQqX-Qg9DzEAfmLSalaVXy96Aw5WUB4kcNc5s,24612
7
+ dfpyre/scriptgen.py,sha256=YwgKDQAYBNVtkU7q__DmC9Bv30Wck9MlSvpdzOAncNw,7585
8
+ dfpyre/style.py,sha256=mLW1CFvvi8_9fk8JaH10I5S4WI0YBdQIXHtI3G_4sR8,980
9
+ dfpyre/util.py,sha256=EpX4XGwwX0A9MlObuQTEuHj4Q-55wj29m8am8ULPmz8,791
10
+ dfpyre-0.8.6.dist-info/LICENSE,sha256=_vuDskB0ja2c-Fgm7Gt8Q8cO9NsLNpZAVyvmZwX7E6o,1060
11
+ dfpyre-0.8.6.dist-info/METADATA,sha256=ZG8A6oSldYFpW1a_lTbfvgIV2w_4nLj-fyb8ab6a0zI,11948
12
+ dfpyre-0.8.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
+ dfpyre-0.8.6.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,13 +0,0 @@
1
- dfpyre/__init__.py,sha256=apPsSxJ1Tztfl71MoORoSmDfX7LyKLYlLwOGeLQUitw,25
2
- dfpyre/action_literals.py,sha256=jvI3ZI1_rnDqS58q5Z0_bb5jgKJ2pu_pgN-1whXpEDQ,16212
3
- dfpyre/actiondump.py,sha256=MVI1kVJBNpab882Tgqo-xtemiBN2W1_2OcopBcRupWQ,2587
4
- dfpyre/data/actiondump_min.json,sha256=hFcIbG_G55FWwqRSW6X77ZrKkQiXLs4CGgJrZgyR2Gg,1938799
5
- dfpyre/items.py,sha256=4FWCCAfJ2Wc6JqwTJFy_V-mwJXdT7b831AdGZpEftNw,13237
6
- dfpyre/pyre.py,sha256=NOBcllwx1RiUJhAf-bqGRN7Z9046nKm2efBJsddLgow,24567
7
- dfpyre/scriptgen.py,sha256=X0GeH3DYJXXuXEF3Jj5joBu-MC94L2oswGCU1IlhToQ,7589
8
- dfpyre/style.py,sha256=mLW1CFvvi8_9fk8JaH10I5S4WI0YBdQIXHtI3G_4sR8,980
9
- dfpyre/util.py,sha256=EpX4XGwwX0A9MlObuQTEuHj4Q-55wj29m8am8ULPmz8,791
10
- dfpyre-0.8.4.dist-info/LICENSE,sha256=_vuDskB0ja2c-Fgm7Gt8Q8cO9NsLNpZAVyvmZwX7E6o,1060
11
- dfpyre-0.8.4.dist-info/METADATA,sha256=SHapZvjDxoyORZCttqBVKwah-PkSRxnmVzko97vdEww,11935
12
- dfpyre-0.8.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
13
- dfpyre-0.8.4.dist-info/RECORD,,