dfpyre 0.7.8__tar.gz → 0.9.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.
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Amp
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Amp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
dfpyre-0.9.4/PKG-INFO ADDED
@@ -0,0 +1,537 @@
1
+ Metadata-Version: 2.4
2
+ Name: dfpyre
3
+ Version: 0.9.4
4
+ Summary: A package for creating and modifying code templates for the DiamondFire Minecraft server.
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Keywords: diamondfire,minecraft,template,item
8
+ Author: Amp
9
+ Requires-Python: >=3.10
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Provides-Extra: dev
17
+ Requires-Dist: mcitemlib (>=0.5.2)
18
+ Requires-Dist: pytest (>=9.0.2) ; extra == "dev"
19
+ Requires-Dist: rapidnbt (>=1.3.3)
20
+ Requires-Dist: twine (>=6.2.0) ; extra == "dev"
21
+ Requires-Dist: websocket-client (>=1.9.0)
22
+ Project-URL: Repository, https://github.com/Amp63/pyre
23
+ Description-Content-Type: text/markdown
24
+
25
+ # pyre
26
+
27
+ A package for external creation of code templates for the DiamondFire Minecraft server (mcDiamondFire.com).
28
+
29
+ PyPi Link: https://pypi.org/project/dfpyre/
30
+
31
+ ## Installation
32
+
33
+ Run the following command in a terminal:
34
+ ```
35
+ pip install dfpyre
36
+ ```
37
+
38
+
39
+ ### CodeClient Installation
40
+
41
+ This module works best with [CodeClient](https://modrinth.com/mod/codeclient) installed. Once you've installed it, enable `CodeClient API` in the General config tab.
42
+
43
+ ## Features
44
+ - All code block types
45
+ - All code item types
46
+ - Direct sending to DF via recode or codeclient
47
+ - Automatic type conversion (`int` to `Number`, `str` to `String`)
48
+ - Auto completed action names (if your IDE supports type hints)
49
+ - Warnings for unrecognized actions and tags
50
+ - Shorthand format for variables
51
+ - Convert existing templates into equivalent Python code (see [Script Generation](#script-generation))
52
+
53
+ ## Documentation
54
+ ## Basics
55
+
56
+ - [Setting up a program](#setup)
57
+ - [Events and Actions](#events-and-actions)
58
+ - [Building](#building)
59
+
60
+ ## Var Items
61
+
62
+ - [Text](#text)
63
+ - [Number](#number)
64
+ - [Variable](#variable)
65
+ - [Location](#location)
66
+ - [Item](#item)
67
+ - [Sound](#sound)
68
+ - [Particle](#particle)
69
+ - [Potion](#potion)
70
+ - [Game Value](#game-value)
71
+ - [Vector](#vector)
72
+ - [Parameter](#parameter)
73
+
74
+ ## Conditionals and Loops
75
+
76
+ - [Conditionals and Brackets](#conditionals-and-brackets)
77
+ - [Loops](#loops)
78
+
79
+ ## Functions and Procedures
80
+
81
+ - [Creating Functions and Processes](#creating-functions-and-processes)
82
+ - [Calling Functions and Processes](#calling-functions-and-processes)
83
+
84
+ ## Extras
85
+
86
+ - [Editing Tags](#editing-tags)
87
+ - [Importing from Code](#importing-from-code)
88
+ - [Script Generation](#script-generation)
89
+ - [Function List](#function-list)
90
+
91
+ ___
92
+
93
+ ## Setup
94
+
95
+ To start creating in pyre, use the `player_event`, `entity_event`, `function`, or `process` functions to start a template.
96
+
97
+ ```py
98
+ from dfpyre import *
99
+
100
+ template = player_event('Join', [
101
+
102
+ ])
103
+ ```
104
+
105
+ You can then insert additional codeblocks inside of that first function call.
106
+
107
+ Here's a complete program that prints a message to every player when a player joins:
108
+
109
+ ```py
110
+ from dfpyre import *
111
+
112
+ player_event('Join', [
113
+ player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
114
+ ]).build_and_send('codeclient')
115
+ ```
116
+
117
+ ## Events and Actions
118
+
119
+ You can find a list of events and actions [here](#function-list)
120
+
121
+ The following program sends a message to all players and gives a player 10 apples upon joining:
122
+
123
+ ```py
124
+ from dfpyre import *
125
+
126
+ player_event('Join', [
127
+ player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS),
128
+ player_action('GiveItems', Item('apple', 10))
129
+ ]).build_and_send('codeclient')
130
+ ```
131
+
132
+ ## Building
133
+
134
+ You have 2 different options for building your code line.
135
+ You can either:
136
+
137
+ 1. Save the compressed template code to a variable and send it to minecraft later
138
+ - Use the `build` method on a template object
139
+ 2. Build and send directly to your minecraft client (recommended)
140
+ - Use the `build_and_send` method on a template object
141
+
142
+ ## Variable Items
143
+
144
+ ### Text
145
+
146
+ Represents a DiamondFire text item:
147
+
148
+ ```py
149
+ Text('hello %default.')
150
+ ```
151
+
152
+ If a regular string is passed to a method as a chest parameter, it will automatically be converted to a text object:
153
+
154
+ ```py
155
+ # These do the same thing:
156
+ player_action('SendMessage', Text('%default joined.'))
157
+ player_action('SendMessage', '%default joined.')
158
+ ```
159
+
160
+ ### Number
161
+
162
+ Alias: `Num`
163
+
164
+ Represents a DiamondFire number item:
165
+
166
+ ```py
167
+ Number(5)
168
+ Number(3.14)
169
+ ```
170
+
171
+ If a regular integer or float is passed to a method as a chest parameter, it will automatically be converted to a num object:
172
+
173
+ ```py
174
+ # These do the same thing:
175
+ set_variable('=', Variable('number'), Number(10))
176
+ set_variable('=', Variable('number'), 10)
177
+ ```
178
+
179
+ ### Variable
180
+
181
+ Alias: `Var`
182
+
183
+ Represents a DiamondFire variable item:
184
+
185
+ ```py
186
+ Variable('num')
187
+ Variable('text1')
188
+ ```
189
+
190
+ You can set variable values by using the `set_variable` method:
191
+
192
+ ```py
193
+ set_variable('=', Variable('num'), 12) # sets 'num' to 12
194
+ set_variable('x', Variable('doubled'), Variable('num'), 2) # sets 'doubled' to 24
195
+ ```
196
+
197
+ You can set the scope of the variable using the `scope` argument:
198
+
199
+ ```py
200
+ set_variable('=', Variable('num1', scope='unsaved'), 12) # `unsaved` is the same as a game variable.
201
+ set_variable('=', Variable('num2', scope='saved'), 12)
202
+ set_variable('=', Variable('num3', scope='local'), 12)
203
+ ```
204
+
205
+ #### Shorthand Variables
206
+
207
+ You can also use the variable shorthand format to express variables more tersely:
208
+ ```py
209
+ # These do the same thing:
210
+ set_variable('=', Variable('lineVar', scope='line'), 5)
211
+ set_variable('=', '$i lineVar', 5)
212
+ ```
213
+
214
+ Shorthand vars should be formatted like this: `$[scope id] [var name]`
215
+
216
+ Here's the list of scope IDs:
217
+ - `g` = Game (unsaved)
218
+ - `s` = Saved
219
+ - `l` = Local
220
+ - `i` = Line
221
+
222
+ ### Location
223
+
224
+ Alias: `Loc`
225
+
226
+ Represents a DiamondFire location item:
227
+
228
+ ```py
229
+ Location(x=25.5, y=50, z=25.5, pitch=0, yaw=-90)
230
+ ```
231
+
232
+ Example:
233
+
234
+ ```py
235
+ # Teleport player on join
236
+ from dfpyre import *
237
+
238
+ player_event('Join', [
239
+ player_action('Teleport', Location(10, 50, 10))
240
+ ])
241
+ ```
242
+
243
+ ### Item
244
+
245
+ Represents a minecraft item:
246
+
247
+ ```py
248
+ Item('stick', count=5)
249
+ Item('stone', 64)
250
+ ```
251
+
252
+ To add extra data to an item, you can use any methods from the [mcitemlib](https://github.com/Amp63/mcitemlib) library
253
+
254
+ ### Sound
255
+
256
+ Alias: `Snd`
257
+
258
+ Represents a DiamondFire sound item:
259
+
260
+ ```py
261
+ Sound('Wood Break', pitch=1.5, vol=2.0)
262
+ ```
263
+
264
+ Example:
265
+
266
+ ```py
267
+ # Plays 'Grass Place' sound on join
268
+ from dfpyre import *
269
+
270
+ player_event('Join', [
271
+ player_action('PlaySound', Sound('Grass Place'))
272
+ ])
273
+ ```
274
+
275
+ ### Particle
276
+
277
+ Represents a DiamondFire particle item:
278
+
279
+ ```py
280
+ Particle({'particle':'Cloud','cluster':{'amount':1,'horizontal':0.0,'vertical':0.0},'data':{'x':1.0,'y':0.0,'z':0.0,'motionVariation':100}})
281
+ ```
282
+
283
+ Example:
284
+
285
+ ```py
286
+ # Plays a white cloud particle effect at 5, 50, 5
287
+ from dfpyre import *
288
+
289
+ part = Particle({'particle':'Cloud','cluster':{'amount':1,'horizontal':0.0,'vertical':0.0},'data':{'x':1.0,'y':0.0,'z':0.0,'motionVariation':100}})
290
+ player_event('Join', [
291
+ player_action('Particle', part, Location(5, 50, 5))
292
+ ])
293
+ ```
294
+
295
+ Currently, the particle object does not support colors.
296
+
297
+ ### Potion
298
+
299
+ Alias: `Pot`
300
+
301
+ Represents a DiamondFire potion item:
302
+
303
+ ```py
304
+ # Gives speed 1 for 1 minute
305
+ Potion('Speed', dur=1200, amp=0)
306
+ ```
307
+
308
+ Example:
309
+
310
+ ```py
311
+ # Gives the player infinite saturation 10
312
+ from dfpyre import *
313
+
314
+ player_event('Join', [
315
+ player_action('GivePotion', Potion('Saturation', amp=10))
316
+ ])
317
+ ```
318
+
319
+ ### Game Value
320
+
321
+ Represents a DiamondFire game value item:
322
+
323
+ ```py
324
+ GameValue('Player Count')
325
+ GameValue('Location' target='Selection')
326
+ ```
327
+
328
+ Example:
329
+
330
+ ```py
331
+ # Function that prints player count and CPU usage
332
+ from dfpyre import *
333
+
334
+ function('printData', [
335
+ player_action('SendMessage', GameValue('Player Count'), GameValue('CPU Usage'))
336
+ ])
337
+ ```
338
+
339
+ ### Vector
340
+
341
+ Alias: `Vec`
342
+
343
+ Represents a DiamondFire vector item:
344
+
345
+ ```py
346
+ Vector(x=1.1, y=0.0, z=0.5)
347
+ ```
348
+
349
+ Example:
350
+
351
+ ```py
352
+ # Sets the player's x velocity to 1.0 on join
353
+ from dfpyre import *
354
+
355
+ player_event('Join', [
356
+ player_action('SetVelocity', Vector(x=1.0, y=0.0, z=0.0))
357
+ ])
358
+ ```
359
+
360
+ ### Parameter
361
+
362
+ Represents a DiamondFire parameter item:
363
+
364
+ ```py
365
+ Parameter('text', ParameterType.STRING)
366
+ ```
367
+
368
+ Example:
369
+
370
+ ```py
371
+ # Builds a function that says "Hello, [name]" where `name` is the inputted parameter.
372
+ from dfpyre import *
373
+
374
+ name_parameter = parameter('name', ParameterType.TEXT)
375
+ function('SayHi', name_parameter, codeblocks=[
376
+ player_action('SendMessage', 'Hello, ', Variable('name', 'line'))
377
+ ])
378
+ ```
379
+
380
+ ### Conditionals and Brackets
381
+
382
+ A list of conditionals and loops can be found [here](#function-list).
383
+
384
+ To create code inside of brackets, use the `codeblocks` argument. Here's an example:
385
+
386
+ ```py
387
+ # Prints 'clicked' when a player right clicks with a stick in their hand
388
+ from dfpyre import *
389
+
390
+ player_event('RightClick', [
391
+ if_player('IsHolding', Item('stick'), codeblocks=[
392
+ player_action('SendMessage', 'clicked')
393
+ ])
394
+ ])
395
+ ```
396
+
397
+ To create an `else` statement, use the `else_` method:
398
+
399
+ ```py
400
+ # Says the player is 'on the ground' when grounded and 'in the air' otherwise.
401
+ from dfpyre import *
402
+
403
+ function('grounded', codeblocks=[
404
+ if_player('IsGrounded', codeblocks=[
405
+ player_action('ActionBar', 'on the ground')
406
+ ]),
407
+ else_([
408
+ player_action('ActionBar', 'in the air')
409
+ ])
410
+ ])
411
+ ```
412
+
413
+ Note that `player_event`, `entity_event`, and `else_` do not require `codeblocks=`, but all other bracket blocks do.
414
+
415
+ ### Loops
416
+
417
+ As for loops, the syntax is the same and will automatically change to "repeat-type" brackets:
418
+
419
+ ```py
420
+ # Prints numbers 1-5
421
+ from dfpyre import *
422
+
423
+ player_event('Join', [
424
+ repeat('Multiple', Variable('i'), 5, codeblocks=[
425
+ player_action('SendMessage', Variable('i'))
426
+ ])
427
+ ])
428
+ ```
429
+
430
+ ### Creating Functions and Processes
431
+
432
+ To create a function or process, just start the template with `function` or `process`:
433
+
434
+ ```py
435
+ # Function that gives a player 64 golden apples
436
+ from dfpyre import *
437
+
438
+ function('giveApples', codeblocks=[
439
+ player_action('GiveItems', Item('golden_apple', 64))
440
+ ])
441
+ ```
442
+
443
+ ### Calling Functions and Processes
444
+
445
+ Calling Functions and processes is also simple:
446
+
447
+ ```py
448
+ from dfpyre import *
449
+
450
+ player_event('Join', [
451
+ call_function('giveApples')
452
+ ])
453
+ ```
454
+
455
+ ### Editing Tags
456
+ You can modify an action's tags by passing the `tags` argument to a template method:
457
+
458
+ ```py
459
+ from dfpyre import *
460
+
461
+ player_event('Join', [
462
+ player_action('SendMessage', 'hello', tags={'Alignment Mode': 'Centered'})
463
+ ])
464
+ ```
465
+
466
+ If you choose not to modify a specific tag, its default value will be used.
467
+ Order does not matter when adding multiple tag entries.
468
+
469
+ ### Importing from Code
470
+
471
+ You can import existing templates from their built code using the `from_code` method:
472
+
473
+ ```py
474
+ from dfpyre import *
475
+
476
+ template_code = 'H4sIAGVyIGYC/3WOMQ7CMAxFz4LnDsw5AhITI6qQSaw2IrGrxkJCVe5eh3boAJP9n/Kfs8AziX8VcPcFYgC3Zej26YDexGoZvUZhAxeJ3PI8WMtKSrnV+1q7P4op4Yfmx244qG7E4Uql4EA/jNv2Jc3qJU/2KqBiY4yZjI6UkpzAjkNJouDO1X7S1xUDaGUl2QAAAA=='
477
+ t = DFTemplate.from_code(template_code)
478
+ # Do stuff with the template here
479
+ ```
480
+
481
+
482
+ ### Script Generation
483
+
484
+ You can also generate an equivalent Python script for a template from a template object:
485
+
486
+ ```py
487
+ from dfpyre import *
488
+
489
+ template_code = 'H4sIAGVyIGYC/3WOMQ7CMAxFz4LnDsw5AhITI6qQSaw2IrGrxkJCVe5eh3boAJP9n/Kfs8AziX8VcPcFYgC3Zej26YDexGoZvUZhAxeJ3PI8WMtKSrnV+1q7P4op4Yfmx244qG7E4Uql4EA/jNv2Jc3qJU/2KqBiY4yZjI6UkpzAjkNJouDO1X7S1xUDaGUl2QAAAA=='
490
+ t = DFTemplate.from_code(template_code)
491
+ t.generate_script('my_template.py') # generated python script will be written to my_template.py
492
+ ```
493
+
494
+ This feature is useful for getting a text representation of existing templates.
495
+
496
+
497
+ ### Inserting Codeblocks
498
+
499
+ Use the `insert` method to insert additional codeblocks into an existing template. By default, codeblocks will be added to the end of the template.
500
+
501
+ ```py
502
+ from dfpyre import *
503
+
504
+ my_template = player_event('Join', [
505
+ player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
506
+ ])
507
+ my_template.insert(player_action('SendMessage', 'Welcome!')) # Add a new codeblock to the end
508
+ ```
509
+
510
+
511
+ ### Function List
512
+
513
+ - **Events / Function / Process**
514
+ - player_event
515
+ - entity_event
516
+ - function
517
+ - process
518
+ - call_function
519
+ - start_process
520
+
521
+ - **Actions**
522
+ - player_action
523
+ - game_action
524
+ - entity_action
525
+
526
+ - **Control Flow**
527
+ - if_player
528
+ - if_variable
529
+ - if_game
530
+ - if_entity
531
+ - else_
532
+ - repeat
533
+
534
+ - **Other**
535
+ - control
536
+ - select_object
537
+ - set_variable