Skip to content
On this page
Common

KattonNbtApi

common/src/main/kotlin/top/katton/api/dpcaller/KattonNbtApi.kt
Create a numeric Tag from a Number value.

numericTagOf ​

numericTagOfCommonFunction
kotlin
fun <T : Number> numericTagOf(value: T)

Create a numeric Tag from a Number value.

Parameters ​

ParameterDescription
valueThe numeric value to convert

Returns ​

appropriate NumericTag subtype

getValue ​

getValueCommonFunction
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 ​

ParameterDescription
tagTypeThe target TagType

Returns ​

casted Tag or null if conversion is not possible

invoke ​

invokeCommonFunction
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 ​

ParameterDescription
tagTypeThe target TagType

Returns ​

casted Tag or null if conversion is not possible

getOrValue ​

getOrValueCommonFunction
kotlin
fun <V> Tag?.getOrValue(default: V): V

Safely 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 ​

ParameterDescription
defaultThe default value to return if conversion fails

Returns ​

converted value or the default

invoke ​

invokeCommonFunction
kotlin
@Suppress("UNCHECKED_CAST")
@Suppress("UNCHECKED_CAST") operator fun <V> Tag?.invoke(default: V): V

Safely 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 ​

ParameterDescription
defaultThe default value to return if conversion fails

Returns ​

converted value or the default

toBoolean ​

toBooleanCommonFunction
kotlin
fun ByteTag?.toBoolean(): Boolean

Convert a ByteTag to a Boolean value.

parseNbt ​

parseNbtCommonFunction
kotlin
fun parseNbt(nbt: String): CompoundTag

Parse an NBT string into a CompoundTag.

Parameters ​

ParameterDescription
nbtNBT string to parse

Returns ​

CompoundTag

getEntityNbt ​

getEntityNbtCommonFunction
kotlin
fun getEntityNbt(entity: Entity): CompoundTag

Get the full NBT data of an entity.

Parameters ​

ParameterDescription
entitythe target entity

Returns ​

representing the entity's data

setEntityNbt ​

setEntityNbtCommonFunction
kotlin
fun setEntityNbt(entity: Entity, tag: CompoundTag)

Replace the NBT data of an entity.

Parameters ​

ParameterDescription
entitythe target entity
tagthe CompoundTag to set on the entity

getBlockNbt ​

getBlockNbtCommonFunction
kotlin
fun getBlockNbt(block: BlockEntity): CompoundTag

Get the NBT data of a block entity.

Parameters ​

ParameterDescription
blockthe target BlockEntity

Returns ​

representing the block entity's data

setBlockNbt ​

setBlockNbtCommonFunction
kotlin
fun setBlockNbt(block: BlockEntity, tag: CompoundTag)

Replace the NBT data of a block entity.

Parameters ​

ParameterDescription
blockthe target BlockEntity
tagthe CompoundTag to set on the block entity

getBlockNbt ​

getBlockNbtCommonFunction
kotlin
fun getBlockNbt(level: Level, pos: BlockPos): CompoundTag?

Get the NBT data of a block at a position if it has a block entity.

Parameters ​

ParameterDescription
levellevel to query
posposition of the block

Returns ​

or null if no block entity exists

setBlockNbt ​

setBlockNbtCommonFunction
kotlin
fun setBlockNbt(level: Level, pos: BlockPos, tag: CompoundTag): Boolean

Set the NBT of a block entity at the given position.

Parameters ​

ParameterDescription
levellevel to modify
posblock position
tagCompoundTag to set

Returns ​

if set succeeded, false if no block entity present

getStorageNbt ​

getStorageNbtCommonFunction
kotlin
fun getStorageNbt(id: Identifier): CompoundTag

Get stored command storage NBT by identifier.

Parameters ​

ParameterDescription
idstorage identifier

Returns ​

stored at id

setStorageNbt ​

setStorageNbtCommonFunction
kotlin
fun setStorageNbt(id: Identifier, tag: CompoundTag)

Set stored command storage NBT by identifier.

Parameters ​

ParameterDescription
idstorage identifier
tagCompoundTag to store