Skip to main content

A package for creating and modifying code templates for the DiamondFire Minecraft server.

Project description

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

CodeClient Installation

This module works best with CodeClient installed. Once you've installed it, enable CodeClient API in the General config tab.

Features

  • All code block types
  • All code item types
  • Direct sending to DF via recode or codeclient
  • Automatic type conversion (int to Number, str to String)
  • Auto completed action names (if your IDE supports type hints)
  • Warnings for unrecognized actions and tags
  • Shorthand format for variables
  • Convert existing templates into equivalent Python code (see Script Generation)

Documentation

Basics

Var Items

Conditionals and Loops

Functions and Procedures

Extras


Setup

To start creating in pyre, use the player_event, entity_event, function, or process functions to start a template.

from dfpyre import *

template = player_event('Join', [

])

You can then insert additional codeblocks inside of that first function call.

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

from dfpyre import *

player_event('Join', [
  player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
]).build_and_send('codeclient')

Events and Actions

You can find a list of events and actions here

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

from dfpyre import *

player_event('Join', [
  player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS),
  player_action('GiveItems', Item('apple', 10))
]).build_and_send('codeclient')

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
    • Use the build method on a template object
  2. Build and send directly to your minecraft client (recommended)
    • Use the build_and_send method on a template object

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:
player_action('SendMessage', Text('%default joined.'))
player_action('SendMessage', '%default joined.')

Number

Alias: Num

Represents a DiamondFire number item:

Number(5)
Number(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:
set_variable('=', Variable('number'), Number(10))
set_variable('=', Variable('number'), 10)

Variable

Alias: Var

Represents a DiamondFire variable item:

Variable('num')
Variable('text1')

You can set variable values by using the set_variable method:

set_variable('=', Variable('num'), 12)  # sets 'num' to 12
set_variable('x', Variable('doubled'), Variable('num'), 2)  # sets 'doubled' to 24

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

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

Shorthand Variables

You can also use the variable shorthand format to express variables more tersely:

# These do the same thing:
set_variable('=', Variable('lineVar', scope='line'), 5)
set_variable('=', '$i lineVar', 5)

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

Here's the list of scope IDs:

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

Location

Alias: Loc

Represents a DiamondFire location item:

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

Example:

# Teleport player on join
from dfpyre import *

player_event('Join', [
  player_action('Teleport', Location(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

Alias: Snd

Represents a DiamondFire sound item:

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

Example:

# Plays 'Grass Place' sound on join
from dfpyre import *

player_event('Join', [
  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 *

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}})
player_event('Join', [
  player_action('Particle', part, Location(5, 50, 5))
])

Currently, the particle object does not support colors.

Potion

Alias: Pot

Represents a DiamondFire potion item:

# Gives speed 1 for 1 minute
Potion('Speed', dur=1200, amp=0)

Example:

# Gives the player infinite saturation 10
from dfpyre import *

player_event('Join', [
  player_action('GivePotion', Potion('Saturation', amp=10))
])

Game Value

Represents a DiamondFire game value item:

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

Example:

# Function that prints player count and CPU usage
from dfpyre import *

function('printData', [
  player_action('SendMessage', GameValue('Player Count'), GameValue('CPU Usage'))
])

Vector

Alias: Vec

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 *

player_event('Join', [
  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 *

name_parameter = parameter('name', ParameterType.TEXT)
function('SayHi', name_parameter, codeblocks=[
  player_action('SendMessage', 'Hello, ', Variable('name', 'line'))
])

Conditionals and Brackets

A list of conditionals and loops can be found here.

To create code inside of brackets, use the codeblocks argument. Here's an example:

# Prints 'clicked' when a player right clicks with a stick in their hand
from dfpyre import *

player_event('RightClick', [
  if_player('IsHolding', Item('stick'), codeblocks=[
    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 *

function('grounded', codeblocks=[
  if_player('IsGrounded', codeblocks=[
    player_action('ActionBar', 'on the ground')
  ]),
  else_([
    player_action('ActionBar', 'in the air')
  ])
])

Note that player_event, entity_event, and else_ do not require codeblocks=, but all other bracket blocks do.

Loops

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

# Prints numbers 1-5
from dfpyre import *

player_event('Join', [
  repeat('Multiple', Variable('i'), 5, codeblocks=[
    player_action('SendMessage', Variable('i'))
  ])
])

Creating Functions and Processes

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

# Function that gives a player 64 golden apples
from dfpyre import *

function('giveApples', codeblocks=[
  player_action('GiveItems', Item('golden_apple', 64))
])

Calling Functions and Processes

Calling Functions and processes is also simple:

from dfpyre import *

player_event('Join', [
  call_function('giveApples')
])

Editing Tags

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

from dfpyre import *

player_event('Join', [
  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)
# Do stuff with the template 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

This feature is useful for getting a text representation of existing templates.

Inserting Codeblocks

Use the insert method to insert additional codeblocks into an existing template. By default, codeblocks will be added to the end of the template.

from dfpyre import *

my_template = player_event('Join', [
  player_action('SendMessage', '%default has joined!', target=Target.ALL_PLAYERS)
])
my_template.insert(player_action('SendMessage', 'Welcome!'))  # Add a new codeblock to the end

Function List

  • Events / Function / Process

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

    • player_action
    • game_action
    • entity_action
  • Control Flow

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

    • control
    • select_object
    • set_variable

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dfpyre-0.8.13.tar.gz (337.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dfpyre-0.8.13-py3-none-any.whl (343.5 kB view details)

Uploaded Python 3

File details

Details for the file dfpyre-0.8.13.tar.gz.

File metadata

  • Download URL: dfpyre-0.8.13.tar.gz
  • Upload date:
  • Size: 337.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-63-generic

File hashes

Hashes for dfpyre-0.8.13.tar.gz
Algorithm Hash digest
SHA256 662a921b10894c55596eaa14f99965da5db6e5c726f61c042ac055e592ebc5fe
MD5 9a6984bdb8ab1f6699e3b96b1829f416
BLAKE2b-256 e4495f81e60128e21f4dd926dfcc5e8bb1a8753d37e00adfa071af2a320817d6

See more details on using hashes here.

File details

Details for the file dfpyre-0.8.13-py3-none-any.whl.

File metadata

  • Download URL: dfpyre-0.8.13-py3-none-any.whl
  • Upload date:
  • Size: 343.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-63-generic

File hashes

Hashes for dfpyre-0.8.13-py3-none-any.whl
Algorithm Hash digest
SHA256 e313d258b553dfde51b84623089cd10787a8b823c28b15afd7e878a3f4d794c6
MD5 1427bfd0b26a209f427b8e050212bddb
BLAKE2b-256 28b3dd658a4d0dad0998cef34b77b9085ec7b633cd578f4da9cc0c4570b95027

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page