Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NBT DSL #21

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

NBT DSL #21

wants to merge 6 commits into from

Conversation

pluiedev
Copy link

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

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