dfpyre 0.8.2__py3-none-any.whl → 0.8.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/items.py CHANGED
@@ -7,7 +7,7 @@ import re
7
7
  from typing import Literal, Any
8
8
  from dfpyre.style import is_ampersand_coded, ampersand_to_minimessage
9
9
  from dfpyre.util import PyreException, warn
10
- from mcitemlib.itemlib import Item as NbtItem
10
+ from mcitemlib.itemlib import Item as NbtItem, MCItemlibException
11
11
 
12
12
 
13
13
  NUMBER_REGEX = r'^-?\d*\.?\d+$'
@@ -32,21 +32,6 @@ def _add_slot(d: dict, slot: int|None):
32
32
  d['slot'] = slot
33
33
 
34
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
35
  class String:
51
36
  """
52
37
  Represents a DiamondFire string object. (`txt`)
@@ -107,6 +92,71 @@ class Number:
107
92
  Num = Number # Number alias
108
93
 
109
94
 
95
+ class Item(NbtItem):
96
+ """
97
+ Represents a Minecraft item.
98
+ """
99
+ type = 'item'
100
+
101
+ def format(self, slot: int|None):
102
+ formatted_dict = {"item": {"id": self.type, "data": {"item": self.get_nbt()}}}
103
+ _add_slot(formatted_dict, slot)
104
+ return formatted_dict
105
+
106
+ def __repr__(self) -> str:
107
+ return f'{self.__class__.__name__}({self.get_id()}, {self.get_count()})'
108
+
109
+ def set_tag(self, tag_name: str, tag_value: str|int|float|String|Number):
110
+ """
111
+ Add a DiamondFire custom tag to this item.
112
+ """
113
+ if isinstance(tag_value, String):
114
+ tag_value = tag_value.value
115
+ elif isinstance(tag_value, Number):
116
+ tag_value = float(tag_value.value)
117
+ elif isinstance(tag_value, int):
118
+ tag_value = float(tag_value)
119
+
120
+ try:
121
+ item_tags = self.get_custom_data('PublicBukkitValues')
122
+ except MCItemlibException:
123
+ item_tags = {}
124
+
125
+ item_tags[f'hypercube:{tag_name}'] = tag_value
126
+ self.set_custom_data('PublicBukkitValues', item_tags)
127
+
128
+ def get_tag(self, tag_name: str) -> str|float|None:
129
+ """
130
+ Get a DiamondFire custom tag from this item.
131
+ """
132
+ try:
133
+ item_tags = self.get_custom_data('PublicBukkitValues')
134
+ except MCItemlibException:
135
+ return None
136
+
137
+ try:
138
+ return item_tags[f'hypercube:{tag_name}']
139
+ except KeyError:
140
+ return None
141
+
142
+ def remove_tag(self, tag_name: str) -> bool:
143
+ """
144
+ Remove a DiamondFire custom tag from this item.
145
+
146
+ :return: `True` on success, `False` on fail
147
+ """
148
+ try:
149
+ item_tags = self.get_custom_data('PublicBukkitValues')
150
+ except MCItemlibException:
151
+ return False
152
+
153
+ try:
154
+ del item_tags[f'hypercube:{tag_name}']
155
+ return True
156
+ except KeyError:
157
+ return False
158
+
159
+
110
160
  class Location:
111
161
  """
112
162
  Represents a DiamondFire location object.
@@ -335,7 +385,7 @@ class Parameter:
335
385
  return f'{self.__class__.__name__}({self.name}, type: {raw_type})'
336
386
 
337
387
 
338
- def item_from_dict(item_dict: dict) -> object:
388
+ def item_from_dict(item_dict: dict) -> Any:
339
389
  item_id = item_dict['id']
340
390
  item_data = item_dict['data']
341
391
 
dfpyre/pyre.py CHANGED
@@ -291,6 +291,8 @@ class DFTemplate:
291
291
  else:
292
292
  self.codeblocks[index:index+len(insert_codeblocks)] = insert_codeblocks
293
293
  elif isinstance(insert_codeblocks, CodeBlock):
294
+ if index == -1:
295
+ index = len(self.codeblocks)
294
296
  self.codeblocks.insert(index, insert_codeblocks)
295
297
  else:
296
298
  raise PyreException('Expected CodeBlock or list[CodeBlock] to insert.')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dfpyre
3
- Version: 0.8.2
3
+ Version: 0.8.4
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
@@ -39,8 +39,10 @@ This module works best with [CodeClient](https://modrinth.com/mod/codeclient) in
39
39
  - All code item types
40
40
  - Direct sending to DF via recode or codeclient
41
41
  - Automatic type conversion (int to num, str to text)
42
+ - Auto completed action names (if your IDE supports type hints)
42
43
  - Warnings for unrecognized actions and tags
43
- - Full tag support
44
+ - Shorthand format for variables
45
+ - Convert existing templates into equivalent Python code (see [Script Generation](#script-generation))
44
46
 
45
47
  ## Documentation
46
48
  ## Basics
@@ -485,6 +487,21 @@ t.generate_script('my_template.py') # generated python script will be written
485
487
 
486
488
  This feature is useful for getting a text representation of existing templates.
487
489
 
490
+
491
+ ### Inserting Codeblocks
492
+
493
+ Use the `insert` method to insert additional codeblocks into an existing template. By default, codeblocks will be added to the end of the template.
494
+
495
+ ```py
496
+ from dfpyre import *
497
+
498
+ my_template = player_event('Join', [
499
+ player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
500
+ ])
501
+ my_template.insert(player_action('SendMessage', 'Welcome!')) # Add a new codeblock to the end
502
+ ```
503
+
504
+
488
505
  ### Function List
489
506
 
490
507
  - **Events / Function / Process**
@@ -500,7 +517,7 @@ This feature is useful for getting a text representation of existing templates.
500
517
  - game_action
501
518
  - entity_action
502
519
 
503
- - **Conditionals / Loops**
520
+ - **Control Flow**
504
521
  - if_player
505
522
  - if_variable
506
523
  - if_game
@@ -2,12 +2,12 @@ dfpyre/__init__.py,sha256=apPsSxJ1Tztfl71MoORoSmDfX7LyKLYlLwOGeLQUitw,25
2
2
  dfpyre/action_literals.py,sha256=jvI3ZI1_rnDqS58q5Z0_bb5jgKJ2pu_pgN-1whXpEDQ,16212
3
3
  dfpyre/actiondump.py,sha256=MVI1kVJBNpab882Tgqo-xtemiBN2W1_2OcopBcRupWQ,2587
4
4
  dfpyre/data/actiondump_min.json,sha256=hFcIbG_G55FWwqRSW6X77ZrKkQiXLs4CGgJrZgyR2Gg,1938799
5
- dfpyre/items.py,sha256=fNcgX6oHc8F65Aj6TCC8BE0XhGsOmrLnPVcSZB3oPB0,11662
6
- dfpyre/pyre.py,sha256=DM7QuLIPMRlHh13frzyx__6t-Auvx3yOjr2wiXRXzsI,24494
5
+ dfpyre/items.py,sha256=4FWCCAfJ2Wc6JqwTJFy_V-mwJXdT7b831AdGZpEftNw,13237
6
+ dfpyre/pyre.py,sha256=NOBcllwx1RiUJhAf-bqGRN7Z9046nKm2efBJsddLgow,24567
7
7
  dfpyre/scriptgen.py,sha256=X0GeH3DYJXXuXEF3Jj5joBu-MC94L2oswGCU1IlhToQ,7589
8
8
  dfpyre/style.py,sha256=mLW1CFvvi8_9fk8JaH10I5S4WI0YBdQIXHtI3G_4sR8,980
9
9
  dfpyre/util.py,sha256=EpX4XGwwX0A9MlObuQTEuHj4Q-55wj29m8am8ULPmz8,791
10
- dfpyre-0.8.2.dist-info/LICENSE,sha256=_vuDskB0ja2c-Fgm7Gt8Q8cO9NsLNpZAVyvmZwX7E6o,1060
11
- dfpyre-0.8.2.dist-info/METADATA,sha256=tbmPOL3dSlog2RVTj7_PcWG4Wf0TbA-0JvCZ1sNgrtY,11335
12
- dfpyre-0.8.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
13
- dfpyre-0.8.2.dist-info/RECORD,,
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,,
File without changes