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