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!
Petal Commands
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
Commands that are marked as dual have different effects depending on if you have the PetalAdmin tag or not.
/ssThis will set the block/container to the SS you choose. However, without the tag it will just tell you what to change.
/filterThis 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.
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
- c.s = system
- c.w = world
- c.IS = ItemStack
- c.CP = CommandPermissionLevel
- c.CT = CustomCommandParamType
- c.BCT = BlockComponentTypes
- c.DD = debugDrawer
- c.DL = DebugLine
Helper Functions
- c.rC() = Register Command
- c.rSE() = Register Script Event (for tracking)
- c.MI(), c.MS(), c.ME() = Send messages (Info, Success, Error)
- c.GV() = Get block from View
- c.GI() = Get Inventory from block
- c.SI() = Set Item in inventory
- c.CI() = Clear Inventory
- c.NS() = Nice String (formats item names)
- c.QS() = Quote Strip (removes quotes from strings)
Register a Command
- i = CustomCommandRegistry instance
- n = Command name
(e.g., "petal:example")
- ds = Description string
- p = Permission level
(e.g., `c.CP.Any`)
- m = Mandatory parameters array
- op = Optional parameters array
- cb = Callback function `(o) => {}`
- tr = Requires PetalAdmin tag (default: false)
- enums = Object of enum definitions
- dM = Dual mode flag (default: false)
Register a script event for help tracking rSE(n, ds, params)
- n = Command name
(e.g., "petal:example")
- ds = Description string
- params = Parameter format string
Example:
c.rSE("petal:example", "example description", "<arg1> <arg2>")Parameter Type Helpers
- IT(n) = Item Type Parameter
Returns
{type: CT.ItemType, name: n} - I(n) = Integer Parameter
Returns
{type: CT.Integer, name: n} - L(n) = Location Parameter
Returns
{type: CT.Location, name: n} - Str(n) = String Parameter
Returns
{type: CT.String, name: n} - ET(n) = Entity Type Parameter
Returns
{type: CT.EntityType, name: n} - F(n) = Float Parameter
Returns
{type: CT.Float, name: n} - E(n) = Enum Parameter
Returns
{type: CT.Enum, name: n}
Item & Inventory Functions
Spawn item with no velocity sI(d, i, a, l)
- d = Dimension
- i = Item ID
- a = Amount
- l = Location
- Returns: ItemEntity
Get inventory container from block GI(b)
- b = Block
Returns: Container or null
Get block inventory using BlockComponentTypes gBI(b)
- b = Block
Returns: Container or null
Clear inventory CI(inv)
- inv = Inventory container
Set item in inventory slot SI(inv, i, id, n=1)
- inv = Inventory container
- i = Slot index
- id = Item ID
- n = Amount (default: 1)
String & Formatting
Normalise string (remove "minecraft:", replace underscores, capitalise) NS(nm)
- nm = String to normalise
Returns: Formatted string
Example: `"minecraft:diamond_sword"` --> `"Diamond Sword"`
Remove quotes from string if present QS(s)
- s = String to process
Returns: Unquoted string
Player Interaction
Get block from player's view direction GV(p, d=6)
- p = Player
- d = Max distance (default: 6)
Returns: Block or null
Send info message (yellow)
- p = Player
- m = Message
Format: "§5Petal§f §e{message}§r"
In Game:
Send success message (green)
- p = Player
- m = Message
Format: "§5Petal§f §a{message}§r"
In Game:
Send error message (red)
- p = Player
- m = Message
Format: "§5Petal§f §c{message}§r"
In Game:
Validation
Validate binary code (string of 0s and 1s) BV(cd)
- cd = Code to validate
Returns: Boolean
Colour Utilities
Convert hex color to RGB object HxC(h)
- h = Hex color (e.g., 0xFF00FF)
Returns: {red, green, blue}
Debug Drawing
Remove array of debug shapes rS(arr)
- arr = Array of DebugLine shapes
Draw chunk outline dCO(x, z, y, cl, ln, cs=16)
- x = X coordinate
- y = Y coordinate
- z = Z coordinate
- cl = Colour object
- ln = Lines array
- cs = Chunk size (default: 16)
Draw box around block dBx(co, cl, ln, dr=0)
- co = Block coordinates {x, y, z}
- cl = Colour object
- ln = Lines array
- dr = Duration (default: 0 = permanent)
Draw circle on axis dCr(cX, cY, cZ, r, ax, cl, sg, ln)
- cX, cY, cZ = Center coordinates
- r = Radius
- ax = Axis ('x', 'y', or 'z')
- cl = Colour object
- sg = Segments (smoothness)
- ln = Lines array
Draw sphere (3 circles on all axes) dSp(cX, cY, cZ, r, cl, sg=48, ln)
- cX, cY, cZ = Center coordinates
- r = Radius
- cl = Colour object
- sg = Segments (default: 48)
- ln = Lines array
Clear debug drawing for player clD(m, pId)
- m = Map containing player debug data
- pId = Player ID
Returns: Boolean (success/failure)
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)