Common
KattonNbtApi
Create a numeric Tag from a Number value.
numericTagOf
getValue
kotlin
fun <T : Tag> Tag?.getValue(tagType: TagType<T>): T?Safely cast a Tag to a specific TagType.
Performs automatic type conversion where possible:
- Numeric tags can be converted between numeric types
- String tags can be parsed into other types
- Collection tags can be converted between array types
Parameters
| Parameter | Description |
|---|---|
tagType | The target TagType |
Returns
The casted Tag or null if conversion is not possible
invoke
kotlin
@Suppress("UNCHECKED_CAST")
@Suppress("UNCHECKED_CAST") operator fun <T : Tag> Tag?.invoke(tagType: TagType<T>): T?Safely cast a Tag to a specific TagType.
Performs automatic type conversion where possible:
- Numeric tags can be converted between numeric types
- String tags can be parsed into other types
- Collection tags can be converted between array types
Parameters
| Parameter | Description |
|---|---|
tagType | The target TagType |
Returns
The casted Tag or null if conversion is not possible
getOrValue
kotlin
fun <V> Tag?.getOrValue(default: V): VSafely get a value from a Tag with a default fallback.
Performs automatic type conversion where possible:
- Numeric tags return numeric values
- String tags return string values
- Collection tags return lists
Parameters
| Parameter | Description |
|---|---|
default | The default value to return if conversion fails |
Returns
The converted value or the default
invoke
kotlin
@Suppress("UNCHECKED_CAST")
@Suppress("UNCHECKED_CAST") operator fun <V> Tag?.invoke(default: V): VSafely get a value from a Tag with a default fallback.
Performs automatic type conversion where possible:
- Numeric tags return numeric values
- String tags return string values
- Collection tags return lists
Parameters
| Parameter | Description |
|---|---|
default | The default value to return if conversion fails |
Returns
The converted value or the default
toBoolean
kotlin
fun ByteTag?.toBoolean(): BooleanConvert a ByteTag to a Boolean value.
parseNbt
getEntityNbt
setEntityNbt
kotlin
fun setEntityNbt(entity: Entity, tag: CompoundTag)Replace the NBT data of an entity.
Parameters
| Parameter | Description |
|---|---|
entity | the target entity |
tag | the CompoundTag to set on the entity |
getBlockNbt
setBlockNbt
kotlin
fun setBlockNbt(block: BlockEntity, tag: CompoundTag)Replace the NBT data of a block entity.
Parameters
| Parameter | Description |
|---|---|
block | the target BlockEntity |
tag | the CompoundTag to set on the block entity |
getBlockNbt
setBlockNbt
getStorageNbt
setStorageNbt
kotlin
fun setStorageNbt(id: Identifier, tag: CompoundTag)Set stored command storage NBT by identifier.
Parameters
| Parameter | Description |
|---|---|
id | storage identifier |
tag | CompoundTag to store |