Skip to main content

A package for external creation of 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/

Features

  • All code block types
  • All code item types
  • Direct sending to DF via recode
  • 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.playerEvent('Join')
t.playerAction('SendMessage', '%default has joined!', target='AllPlayers')
t.buildAndSend()

Events/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.playerEvent('Join')
t.playerAction('SendMessage', '%default has joined!', target='AllPlayers')
t.playerAction('GiveItems', item('apple', 10))

Building

You basically 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.playerEvent('Join')
t.playerAction('SendMessage', '%default has joined!', target='AllPlayers')
templateCode, templateName = t.build()  # NOTE: build() returns a tuple with code at index 0 and a formatted name at index 1.

sendToDf(code, name=templateName)  # Send to minecraft client via recode item api

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

from dfpyre import *
t = DFTemplate()
t.playerEvent('Join')
t.playerAction('SendMessage', '%default has joined!', target='AllPlayers')
t.buildAndSend()  # 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.playerAction('SendMessage', text('%default joined.'))
t.playerAction('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.setVariable('=', var('number'), num(10))
t.setVariable('=', var('number'), 10)

Variable

Represents a diamondfire variable item:

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

You can set variable values by using the setVariable method:

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

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

t.setVariable('=', var(num1, scope='game'), 12)  # both 'game' or 'unsaved' can be passed for the scope here
t.setVariable('=', var(num1, scope='saved'), 12)
t.setVariable('=', var(num1, scope='local'), 12)

Location

Represents a diamondfire location item:

# (var= is not required if numbers are in order, but is more readable)
loc(x=25.5, y=50, z=25.5, pitch=0, yaw=-90)

Example:

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

Item

Represents a minecraft item:

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

Extra nbt (enchants, lore, etc.) is not supported right now.

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.playerEvent('Join')
t.playerAction('PlaySound', sound('Grass Place'))

Particle

Represents a diamondfire particle item:

particle(name='Cloud', amount=10, horizontal=1.0, vertical=0.5, 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.playerEvent('Join')
t.playerAction('Particle', particle('Cloud'), 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.playerEvent('Join')
t.playerAction('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.playerAction('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.playerEvent('Join')
t.playerAction('SetVelocity', vector(x=1.0, y=0.0, z=0.0))

Conditionals/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.playerEvent('RightClick')
t.ifPlayer('IsHolding', item('stick'))
t.bracket(
    t.playerAction('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.ifPlayer('IsGrounded')
t.bracket(
    t.playerAction('ActionBar', 'on the ground')
)
t.else_()
t.bracket(
    t.playerAction('ActionBar', 'in the air')
)
t.build()

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.playerEvent('Join')
t.repeat('Multiple', var('i'), 5)
t.bracket(
    t.playerAction('SendMessage', var('i'))
)

Creating Functions/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.playerAction('GiveItems', item('golden_apple', 64))

Calling Functions/Processes

Calling Functions and processes is also simple:

from dfpyre import *
t = DFTemplate()
t.playerEvent('Join')
t.callFunction('doStuff')

Function parameters can also be inputted easier. Check here for more info.

Functions with Parameters

Lets say that we have this function that prints out double (numx2) of what was inputted (num):

# prints numbers 1-5
from dfpyre import *
t = DFTemplate()
t.function('double')
t.setVariable('x', var('numx2'), var('num'), 2)
t.playerAction('SendMessage', var('numx2'))

To easily pass the required parameter num, we can use the parameters keyword like this:

# prints numbers 1-5
from dfpyre import *
t = DFTemplate()
t.playerEvent('Join')
t.callFunction('double', parameters={'num': 5})

This basically just sets a local variable for each key in parameters before the function is called.

Special Return

Similar to functions with parameters, return_ is an extension of the function method.

When you want to return a given value from a function, you can use return_ like this:

from dfpyre import *
t = DFTemplate()
t.function('return10')
t.return_(returndata={'retnum': 10})
t.buildAndSend()

For each value in returndata, a local variable will be set for each entry. After all of the variables are set, a control('Return') block is automatically added to the end of the line. This allows you to access these local variables after the function returns.

Method List

  • Events / Function / Process

    • playerEvent
    • entityEvent
    • function
    • process
    • callFunction
    • startProcess
  • Actions

    • playerAction
    • gameAction
    • entityAction
  • Conditionals / Loops

    • ifPlayer
    • ifVariable
    • ifGame
    • ifEntity
    • else_ (dont forget underscore)
    • repeat
    • bracket (more info above)
  • Other

    • control
    • selectObject
    • setVariable
  • Extras

    • return_

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.4.4.tar.gz (17.1 kB view hashes)

Uploaded Source

Built Distribution

dfpyre-0.4.4-py3-none-any.whl (17.4 kB view hashes)

Uploaded Python 3

Supported by

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