Skip to content

Latest commit

 

History

History
496 lines (345 loc) · 10.4 KB

README.md

File metadata and controls

496 lines (345 loc) · 10.4 KB

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 num, str to text)
  • Warnings for unrecognized actions and tags
  • Full tag support

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.

Function 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
  • Other

    • control
    • select_object
    • set_variable