Command API Reference
The command API is focused on making the built-in Minecraft commands easier to work with.
NBT Data
Module for all NBT related container types and functions.
Not all of these NBT container types need to be constructed on their own because most functions that use them as parameters can convert their primitive types directly. (e.g. a dict
can be used instead of constructing an NbtObj
)
Attributes:
Name | Type | Description |
---|---|---|
NbtPrimitive |
Union[str, int, bool, dict, list]
|
Data types that can be converted into valid NBT data |
Bool
dataclass
Bases: Value
Container type for NBT Boolean values.
Attributes:
Name | Type | Description |
---|---|---|
value |
bool
|
Bool |
Byte
dataclass
Bases: Value
Container type for NBT Byte values.
Attributes:
Name | Type | Description |
---|---|---|
value |
int
|
Int representation of bytes |
Float
dataclass
Bases: Value
Container type for NBT Float values.
Attributes:
Name | Type | Description |
---|---|---|
value |
float
|
Float |
Int
dataclass
NbtList
dataclass
NbtObj
dataclass
Bases: Value
Container type for NBT Compound values. (e.i. JSON object)
Attributes:
Name | Type | Description |
---|---|---|
value |
dict
|
Dict representation of object |
NbtPath
dataclass
Bases: CmdObject
Container type for NBT paths
Attributes:
Name | Type | Description |
---|---|---|
path |
str
|
String data path (e.g. Inventory[0]) |
at(index)
key(subpath)
Short
dataclass
Bases: Value
Container type for NBT Short values.
Attributes:
Name | Type | Description |
---|---|---|
value |
int
|
Int representation of short |
Str
dataclass
Bases: Value
Container type for string values
Attributes:
Name | Type | Description |
---|---|---|
value |
str
|
String value. Double quotes will be escaped when used in commands |
Value
dataclass
as_nbt(primitive_value)
Convert the given type into its NBT wrapped type if possible
Attributes:
Name | Type | Description |
---|---|---|
primitive_value |
value |
Returns:
Type | Description |
---|---|
Union[Value, Str, Bool, Int, NbtObj, NbtList]
|
NBT subtype that corresponds to the given Python type value |
Raises:
Type | Description |
---|---|
ValueError
|
When a NBT type is not found for the given value |
Selectors
Module for all entity selector container types and functions
Selector
dataclass
Bases: CmdObject
Base container type for entity selectors
Attributes:
Name | Type | Description |
---|---|---|
entity_type |
str
|
type of entity (e.g. @s, @p) |
arguments |
tuple
|
selector arguments built with |
Example
Data Command
Module for all data command container types and functions
Attributes:
Name | Type | Description |
---|---|---|
TargetType |
Union[StoragePath, EntityPath, BlockPath]
|
Data types that can be used as the target of a data command. (e.g. the one being affected) |
SourceType |
Union[StoragePath, EntityPath, BlockPath, Value, NbtPrimitive]
|
Data types that can be used as the source of a data command. (e.g. the one being read from) |
BlockPath
dataclass
Bases: DataPath
, Tellable
A container for a block path
Attributes:
Name | Type | Description |
---|---|---|
pos |
str
|
block pos string triplet (e.g. "~ 1 ~") |
Example
to_tellable()
Converts this container type to a tellraw printable element
Returns:
Type | Description |
---|---|
dict
|
dict tellraw element |
DataCondition
dataclass
Parent class of data command container types that can be used in execute conditions
has_value(expected_value)
DataPath
dataclass
Bases: NbtPath
, DataCondition
Base class to all data path types
See BlockPath
, EntityPath
, and StoragePath
for examples.
append(value)
Append the value to the end of this data path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
any
|
Source data type |
required |
Returns:
Type | Description |
---|---|
Self
|
Self |
merge(source, modify=True)
Merge the data source into this data path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
any
|
Source data type |
required |
modify |
bool
|
Flag for using "data modify ... merge" or "data merge ..." |
True
|
Returns:
Type | Description |
---|---|
Self
|
Self |
remove()
Remove the data at this data path
Returns:
Type | Description |
---|---|
Self
|
Self |
set(value)
Set the data path to the given value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
any
|
Can be of any data path, NBT primitive, or Value type. |
required |
Returns:
Type | Description |
---|---|
Self
|
Self |
set_from_score(score, result_type='int', scale=1)
Save the given score's value into this data path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
score |
Score
|
source score |
required |
result_type |
str
|
data path data type |
'int'
|
scale |
int
|
multiplier |
1
|
Returns:
Type | Description |
---|---|
Self
|
Self |
to_score(holder=None, objective=None)
Convert this data path to a score value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
holder |
str
|
score holder |
None
|
objective |
str
|
score objective |
None
|
Returns:
Type | Description |
---|---|
Score
|
Score |
EntityPath
dataclass
Bases: DataPath
, Tellable
A container for an entity path
Attributes:
Name | Type | Description |
---|---|---|
selector |
str
|
entity selector |
Example
to_tellable()
Converts this container type to a tellraw printable element
Returns:
Type | Description |
---|---|
dict
|
dict tellraw element |
StoragePath
dataclass
Bases: DataPath
, Tellable
A container for a storage path
Attributes:
Name | Type | Description |
---|---|---|
namespace |
str
|
storage namespace |
to_tellable()
Converts this container type to a tellraw printable element
Returns:
Type | Description |
---|---|
dict
|
dict tellraw element |
data_get(target)
Command template function for "data get ..."
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
TargetType
|
target path |
required |
Returns:
Type | Description |
---|---|
Iterator[str]
|
yielded command |
data_merge(target, source)
Command template function for "data merge ..."
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
TargetType
|
target path |
required |
source |
Value
|
source path or value |
required |
Returns:
Type | Description |
---|---|
Iterator[str]
|
yielded command |
data_modify_append(target, source)
Command template function for "data modify ... append ..."
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
TargetType
|
target path |
required |
source |
SourceType
|
source path or value |
required |
Returns:
Type | Description |
---|---|
Iterator[str]
|
yielded command |
data_modify_merge(target, source)
Command template function for "data modify ... merge ..."
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
TargetType
|
target path |
required |
source |
SourceType
|
source path or value |
required |
Returns:
Type | Description |
---|---|
Iterator[str]
|
yielded command |
data_modify_set(target, source)
Sets the target path to the given source path or value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
TargetType
|
target path |
required |
source |
SourceType
|
source path or value |
required |
Returns:
Type | Description |
---|---|
Iterator[str]
|
yielded command |
data_remove(target)
Command template function for "data remove ..." Args: target: target path
Returns:
Type | Description |
---|---|
Iterator[str]
|
yielded command |
get_target_type(target)
Utility function for getting the string representation of the class type to be used in commands Args: target: data path, NBT primitive, or value type
Returns:
Type | Description |
---|---|
str
|
string representation of type |
Raises:
Type | Description |
---|---|
ValueError
|
if given an unhandled container type |
Execute Command
Module for all execute command container types and functions
execute(*conditions, limit=3)
Context manager to execute the inner statements with the given conditions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions |
str
|
execute conditions e.g. if, unless, store, etc to apply to each command |
()
|
limit |
int
|
the maximum number of inline commands to allow before creating a generated mcfunction file. If |
3
|
if_(*conditions)
Scoreboard Command
Score
dataclass
Bases: CmdObject
, ScoreCondition
, Tellable
Container to hold a score holder and objective
add(count=1)
Command to add an amount to a player score
enable()
Command to enable a player score
get()
Command to get a player score
remove(count=1)
Command to remove an amount from a player score
reset()
Command to reset a player score
set()
Command to set a player score
score_add(score, count=1)
Command to add an amount to a player score
score_enable(score)
Command to enable the score
score_get(score)
Command to get a player score
score_objectives_add(name, type=None)
Command to add an objective. Type defaults to "dummy"
score_remove(score, count=1)
Command to remove an amount from a player score
score_reset(score)
Command to reset the score
score_set(score)
Command to set a player score
Tag Command
Module for all tag command container types and functions
Tag
dataclass
Bases: CmdObject
Command template function to add a tag to the given selector
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Optional name for the tag |
__invert__()
add(entity_selector)
Add this tag to the given entity
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_selector |
Selector
|
Entity to add this tag to |
required |
Returns: Self
negate()
remove(entity_selector)
Remove this tag from the given entity
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_selector |
Selector
|
Entity to remove this tag from |
required |
Returns: Self