Skip to content
/ pyre Public

A library for the Diamondfire Minecraft server that allows you to create and compile code templates.

License

Notifications You must be signed in to change notification settings

Amp63/pyre

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyre

A package for external creation of code templates for the DiamondFire Minecraft server (mcdiamondfire.com).

PyPi Link: https://pypi.org/project/dfpyre/

Installation

Run the following command in a terminal:

pip install dfpyre

Features

  • All code block types
  • All code item types
  • Direct sending to DF via recode or codeclient
  • Automatic type conversion (int to num, str to text)
  • Name checking ("did you mean ___?" for close matches)
  • Default tag values

Documentation

Basics

Var Items

Conditionals and Loops

Functions and Procedures

Extras


Setup

To start creating in pyre, you have to create a DFTemplate object like so:

from dfpyre import *
t = DFTemplate()

Basically everything stems from this template object.

This is the basic layout of a file:

from dfpyre import *
t = DFTemplate()
# [Event, Function, or Process]
# [Your code here]
t.build()

The commented lines represent where you will insert calls to methods in the template object.

Here's a complete program that prints a message to every player when a player joins:

from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
t.build_and_send('codeclient')

Events and Actions

You can find a list of events and actions here

As shown in setup, every code line must start with an event, function, or process. After that, you're free to put anything you want.

The following program sends a message to all players and gives a player 10 apples upon joining:

from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
t.player_action('GiveItems', item('apple', 10))

Building

You have 2 different options for building your code line. You can either:

  1. Save the compressed template code to a variable and send it to minecraft later
  2. Build and send directly to your minecraft client (recommended)

If you choose the first option, the code would look something like this:

from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
template_code = t.build()  # do whatever you want with this

If you choose the second option, you can do this:

from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
t.build_and_send('codeclient')  # builds and sends automatically to minecraft

Variable Items

Text

Represents a diamondfire text item:

text('hello %default.')

If a regular string is passed to a method as a chest parameter, it will automatically be converted to a text object:

# These do the same thing:
t.player_action('SendMessage', text('%default joined.'))
t.player_action('SendMessage', '%default joined.')

Number

Represents a diamondfire number item:

num(5)
num(3.14)

If a regular integer or float is passed to a method as a chest parameter, it will automatically be converted to a num object:

# These do the same thing:
t.set_variable('=', var('number'), num(10))
t.set_variable('=', var('number'), 10)

Variable

Represents a diamondfire variable item:

var('num')
var('text1')

You can set variable values by using the set_variable method:

t.set_variable('=', var('num'), 12)  # sets 'num' to 12
t.set_variable('x', var('doubled'), var('num'), 2)  # sets 'doubled' to 24

You can set the scope of the variable by using the scope argument:

t.set_variable('=', var(num1, scope='unsaved'), 12)  # `unsaved` is the same as a game variable.
t.set_variable('=', var(num1, scope='saved'), 12)
t.set_variable('=', var(num1, scope='local'), 12)

Shorthand Variables

You can also use the variable shorthand format like this:

# These do the same thing:
t.set_variable('=', var('lineVar', scope='line'), 5)
t.set_variable('=', '$ilineVar', 5)

Shorthand vars should be formatted like this: $[scope id][var name]

Here's a list of the scope IDs:

  • g = Game (unsaved)
  • s = Saved
  • l = Local
  • i = Line

Location

Represents a diamondfire location item:

loc(x=25.5, y=50, z=25.5, pitch=0, yaw=-90)

Example:

# teleport player on join
from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('Teleport', loc(10, 50, 10))

Item

Represents a minecraft item:

item('stick', count=5)
item('stone', 64)

To add extra data to an item, you can use any methods from the mcitemlib library

Sound

Represents a diamondfire sound item:

sound('Wood Break', pitch=1.5, vol=2.0)

Example:

# plays 'Grass Place' sound on join
from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('PlaySound', sound('Grass Place'))

Particle

Represents a diamondfire particle item:

particle({'particle':'Cloud','cluster':{'amount':1,'horizontal':0.0,'vertical':0.0},'data':{'x':1.0,'y':0.0,'z':0.0,'motionVariation':100}})

Example:

# plays a white cloud particle effect at 5, 50, 5
from dfpyre import *
t = DFTemplate()
t.player_event('Join')
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}})
t.player_action('Particle', part, loc(5, 50, 5))

Currently, the particle object does not support colors.

Potion

Represents a diamondfire potion item:

# gives speed 1 for 1 minute
potion('Speed', dur=1200, amp=0)

Example:

# gives the player infinite saturation 255
from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('GivePotion', potion('Saturation', amp=254))

Game Value

Represents a diamondfire game value item:

gamevalue('Player Count')
gamevalue('Location' target='Selection')

Example:

# function that prints player count and cpu
from dfpyre import *
t = DFTemplate()
t.function('printData')
t.player_action('SendMessage', gamevalue('Player Count'), gamevalue('CPU Usage'))

Vector

Represents a diamondfire vector item:

vector(x=1.1, y=0.0, z=0.5)

Example:

# sets the player's x velocity to 1.0 on join
from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('SetVelocity', vector(x=1.0, y=0.0, z=0.0))

Parameter

Represents a diamondfire parameter item:

parameter('text', ParameterType.STRING)

Example:

# builds a function that says "Hello, [name]" where `name` is the inputted parameter.
from dfpyre import *
t = DFTemplate()
name_parameter = parameter('name', ParameterType.TEXT)
t.function('SayHi', name_parameter)
t.player_action('SendMessage', 'Hello, ', var('name', 'line'))

Conditionals and Brackets

A list of conditionals and loops can be found here.

A specific syntax must be followed when creating conditionals and loops. Each conditional statement must be followed by a bracket() method, which will contain code. Here's an example:

# prints 'clicked' when a player right clicks with a stick in their hand
from dfpyre import *
t = DFTemplate()
t.player_event('RightClick')
t.if_player('IsHolding', item('stick'))
t.bracket(
    t.player_action('SendMessage', 'clicked')
)

To create an else statement, use the else_ method:

# says the player is 'on the ground' when grounded and 'in the air' otherwise.
from dfpyre import *
t = DFTemplate()
t.function('grounded')
t.if_player('IsGrounded')
t.bracket(
    t.player_action('ActionBar', 'on the ground')
)
t.else_()
t.bracket(
    t.player_action('ActionBar', 'in the air')
)

Loops

As for loops, the bracket syntax is the same and will automatically change to "repeat-type" brackets:

# prints numbers 1-5
from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.repeat('Multiple', var('i'), 5)
t.bracket(
    t.player_action('SendMessage', var('i'))
)

Creating Functions and Processes

To create a function or process, just start the template with a function or process method:

# function that gives a player 64 golden apples
from dfpyre import *
t = DFTemplate()
t.function('doStuff')
t.player_action('GiveItems', item('golden_apple', 64))

Calling Functions and Processes

Calling Functions and processes is also simple:

from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.call_function('doStuff')

Editing Tags

You can edit an action's tags by passing the tags argument to a template method:

from dfpyre import *
t = DFTemplate()
t.player_event('Join')
t.player_action('SendMessage', 'hello', tags={'Alignment Mode': 'Centered'})

If you choose not to modify a specific tag, its default value will be used. Order does not matter when adding multiple tag entries.

Importing from Code

You can import existing templates from their built code using the from_code method:

from dfpyre import *
template_code = 'H4sIAGVyIGYC/3WOMQ7CMAxFz4LnDsw5AhITI6qQSaw2IrGrxkJCVe5eh3boAJP9n/Kfs8AziX8VcPcFYgC3Zej26YDexGoZvUZhAxeJ3PI8WMtKSrnV+1q7P4op4Yfmx244qG7E4Uql4EA/jNv2Jc3qJU/2KqBiY4yZjI6UkpzAjkNJouDO1X7S1xUDaGUl2QAAAA=='

t = DFTemplate.from_code(template_code)
# add onto the template from here

Script Generation

You can also generate an equivalent python script for a template from a template object:

from dfpyre import *
template_code = 'H4sIAGVyIGYC/3WOMQ7CMAxFz4LnDsw5AhITI6qQSaw2IrGrxkJCVe5eh3boAJP9n/Kfs8AziX8VcPcFYgC3Zej26YDexGoZvUZhAxeJ3PI8WMtKSrnV+1q7P4op4Yfmx244qG7E4Uql4EA/jNv2Jc3qJU/2KqBiY4yZjI6UkpzAjkNJouDO1X7S1xUDaGUl2QAAAA=='

t = DFTemplate.from_code(template_code)
t.generate_script('my_template.py')    # generated python script will be written to my_template.py

Method List

  • Events / Function / Process

    • player_event
    • entity_event
    • function
    • process
    • call_function
    • start_process
  • Actions

    • player_action
    • game_action
    • entity_action
  • Conditionals / Loops

    • if_player
    • if_variable
    • if_game
    • if_entity
    • else_
    • repeat
    • bracket
  • Other

    • control
    • select_object
    • set_variable

About

A library for the Diamondfire Minecraft server that allows you to create and compile code templates.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages