Skip to content
On this page

Common

KattonNbtApi

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

numericTagOf

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

Create a numeric Tag from a Number value.

Parameters

ParameterDescription
valueThe numeric value to convert

Returns

The appropriate NumericTag subtype

getValue

CommonFunction
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

The casted Tag or null if conversion is not possible

invoke

CommonFunction
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

The casted Tag or null if conversion is not possible

getOrValue

CommonFunction
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

The converted value or the default

invoke

CommonFunction
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

The converted value or the default

toBoolean

CommonFunction
kotlin
fun ByteTag?.toBoolean(): Boolean

Convert a ByteTag to a Boolean value.

parseNbt

CommonFunction
kotlin
fun parseNbt(nbt: String): CompoundTag

Parse an NBT string into a CompoundTag.

Parameters

ParameterDescription
nbtNBT string to parse

Returns

parsed CompoundTag

getEntityNbt

CommonFunction
kotlin
fun getEntityNbt(entity: Entity): CompoundTag

Get the full NBT data of an entity.

Parameters

ParameterDescription
entitythe target entity

Returns

CompoundTag representing the entity's data

setEntityNbt

CommonFunction
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

CommonFunction
kotlin
fun getBlockNbt(block: BlockEntity): CompoundTag

Get the NBT data of a block entity.

Parameters

ParameterDescription
blockthe target BlockEntity

Returns

CompoundTag representing the block entity's data

setBlockNbt

CommonFunction
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

CommonFunction
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

CompoundTag or null if no block entity exists

setBlockNbt

CommonFunction
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

true if set succeeded, false if no block entity present

getStorageNbt

CommonFunction
kotlin
fun getStorageNbt(id: Identifier): CompoundTag

Get stored command storage NBT by identifier.

Parameters

ParameterDescription
idstorage identifier

Returns

CompoundTag stored at id

setStorageNbt

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

Set stored command storage NBT by identifier.

Parameters

ParameterDescription
idstorage identifier
tagCompoundTag to store