Petal Documentation

This page aims to help showcase the commands and features Petal has to offer, as well as explaining how you can help contribute and make your own additions.

If you want to share your commands/features or just want help or report a bug join the discord!

💬
Join the community on Discord
Join

Petal Commands

Note

The PetalAdmin commands are only for players with that tag. To make yourself a PetalAdmin run the command below.

//add the tag
/tag @s add PetalAdmin
        
//remove the tag
/tag @s remove PetalAdmin

Commands Info

Note

Commands that are marked as dual have different effects depending on if you have the PetalAdmin tag or not.

/ss

This will set the block/container to the SS you choose. However, without the tag it will just tell you what to change.

/filter

This will set the hopper to the given SS filter. However, without the tag you need to run /filter blocker <value>. This will make the item in your hand into the blocker item.

Warning

All the commands that use the DebugDrawer have a bug where they show in all 3 dimensions regardless. As far as I know this is a Mojang problem and physically can't be fixed. However, if anyone has any ideas I'd be more than open to them.


Understanding how to use core.js

This will cover most aspects to understanding core.js and includes a few examples.

Understanding The Import System

The core.js file has a single import requirement import {c} from './core.js' then you use the "sub-imports" to get what you want.

API Shortcut Names


Helper Functions


Register a Command

Scriptevents

Register a script event for help tracking rSE(n, ds, params)

Example:

c.rSE("petal:example", "example description", "<arg1> <arg2>")

Parameter Type Helpers


Item & Inventory Functions

Spawn item with no velocity sI(d, i, a, l)

Get inventory container from block GI(b)

Get block inventory using BlockComponentTypes gBI(b)

Clear inventory CI(inv)

Set item in inventory slot SI(inv, i, id, n=1)


String & Formatting

Normalise string (remove "minecraft:", replace underscores, capitalise) NS(nm)

Remove quotes from string if present QS(s)


Player Interaction

Get block from player's view direction GV(p, d=6)

Send info message (yellow)

Send success message (green)

Send error message (red)


Validation

Validate binary code (string of 0s and 1s) BV(cd)


Colour Utilities

Convert hex color to RGB object HxC(h)


Debug Drawing

Remove array of debug shapes rS(arr)

Draw chunk outline dCO(x, z, y, cl, ln, cs=16)

Draw box around block dBx(co, cl, ln, dr=0)

Draw circle on axis dCr(cX, cY, cZ, r, ax, cl, sg, ln)

Draw sphere (3 circles on all axes) dSp(cX, cY, cZ, r, cl, sg=48, ln)

Clear debug drawing for player clD(m, pId)

Example Commands

Below are some commands that show the basic steps to get a working command.

Normal command

import {c} from './core.js'

c.s.beforeEvents.startup.subscribe(i => {
  c.rC(
    i,
    "petal:helloworld",
    "Says Hi back to you",
    c.CP.Any,
    [],
    (o) => {
      const p = o.sourceEntity
      if(!p) return
      
      c.MS(p, `Hi ${p.name}!`)
    }
  )
})

Admin command

import {c} from './core.js'

c.s.beforeEvents.startup.subscribe(i => {
  c.rC(
    i,
    "petal:admin",
    "Admin command",
    c.CP.Any,
    [],
    (o) => {
      const p = o.sourceEntity
      if(!p) return
      c.MS(p, "You are an admin!")
    },
    true // Requires PetalAdmin tag
  )
})

Drawing a debug box

const lines = []
const blockPos = {x: 0, y: 64, z: 0}
const color = c.HxC(0xFF00FF) // Magenta

c.dBx(blockPos, color, lines)

// Later, to remove:
c.rS(lines)