dfpyre 0.8.2__tar.gz → 0.8.4__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.

@@ -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
@@ -21,8 +21,10 @@ This module works best with [CodeClient](https://modrinth.com/mod/codeclient) in
21
21
  - All code item types
22
22
  - Direct sending to DF via recode or codeclient
23
23
  - Automatic type conversion (int to num, str to text)
24
+ - Auto completed action names (if your IDE supports type hints)
24
25
  - Warnings for unrecognized actions and tags
25
- - Full tag support
26
+ - Shorthand format for variables
27
+ - Convert existing templates into equivalent Python code (see [Script Generation](#script-generation))
26
28
 
27
29
  ## Documentation
28
30
  ## Basics
@@ -467,6 +469,21 @@ t.generate_script('my_template.py') # generated python script will be written
467
469
 
468
470
  This feature is useful for getting a text representation of existing templates.
469
471
 
472
+
473
+ ### Inserting Codeblocks
474
+
475
+ Use the `insert` method to insert additional codeblocks into an existing template. By default, codeblocks will be added to the end of the template.
476
+
477
+ ```py
478
+ from dfpyre import *
479
+
480
+ my_template = player_event('Join', [
481
+ player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
482
+ ])
483
+ my_template.insert(player_action('SendMessage', 'Welcome!')) # Add a new codeblock to the end
484
+ ```
485
+
486
+
470
487
  ### Function List
471
488
 
472
489
  - **Events / Function / Process**
@@ -482,7 +499,7 @@ This feature is useful for getting a text representation of existing templates.
482
499
  - game_action
483
500
  - entity_action
484
501
 
485
- - **Conditionals / Loops**
502
+ - **Control Flow**
486
503
  - if_player
487
504
  - if_variable
488
505
  - if_game
@@ -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
 
@@ -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
  [tool.poetry]
2
2
  name = "dfpyre"
3
- version = "0.8.2"
3
+ version = "0.8.4"
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"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes