Skip to content

NBT DSL#21

Draft
pluiedev wants to merge 6 commits intoQuiltMC:mainfrom
pluiedev:dev/nbt
Draft

NBT DSL#21
pluiedev wants to merge 6 commits intoQuiltMC:mainfrom
pluiedev:dev/nbt

Conversation

@pluiedev
Copy link
Copy Markdown

This PR includes two APIs for creating, manipulating and retrieving NBT data.

The NBT creation DSL allows one to create nested NBT tags easily via an idiomatic DSL, like so:

fun sample() = buildNbtCompound {
    putCompound("explicitSyntax") {
        put("looks like this", 42.0)
    }

    "abbreviatedSyntax"("looks like that")

    "you"(3.0f)
    "can"(true)
    "put"(3.toByte())
    "a lot"(30L)
    "of"(Identifier("different data"))
    "in"(BlockPos.ORIGIN)
    "here" compound {
        "ooh"("nesting!")
        "listsAreWeird" list {
            add(40.0)
            add(2.0)
            add(30.0)
        }
    }
}

The structural access API revolves around NbtStruct, which allows users to define a data structure that gets data from and puts data into an NbtCompound. For example:

class Sample(nbt: NbtCompound): NbtStruct(nbt) {
    val elephant by int()
    val hi by double("explicitKey")
    val nested by listOfStructs(::Nested)
}

class Nested(nbt: NbtCompound): NbtStruct(nbt) {
    val hey by string()
}

The Sample struct should accept NBT data like this: (SNBT)

{elephant:33,explicitKey:42.0d,nested:[{hey:"there"},{hey:"yo"},{hey:"Jude"}]}
  • NBT Creation API
  • Structural Access API
    • Nullable/optional fields?
  • Nullable access to NBT data
  • Finally decide on what to do with lists
  • Perhaps other APIs as well?

Closes #6.

@pluiedev pluiedev marked this pull request as draft June 15, 2022 02:25
@Kroppeb
Copy link
Copy Markdown

Kroppeb commented Jun 16, 2022

Why do classes have to extend NbtStruct? Feels quite limiting? It's not something that is needed for stuff like Kotlin's map delegations.

@Oliver-makes-code Oliver-makes-code added enhancement New feature or request draft For in-progress requests labels Jun 25, 2022
@SilverAndro
Copy link
Copy Markdown
Contributor

Why do classes have to extend NbtStruct? Feels quite limiting? It's not something that is needed for stuff like Kotlin's map delegations.

I mean, are these meaningful outside of an NbtStruct? They seem to rely on the internal nbt field so im unsure how you would make them function without that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

draft For in-progress requests enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NBT API/DSL

4 participants