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

[Proposal] Refactor for nbt builder #41

Open
SettingDust opened this issue Oct 14, 2022 · 6 comments
Open

[Proposal] Refactor for nbt builder #41

SettingDust opened this issue Oct 14, 2022 · 6 comments

Comments

@SettingDust
Copy link

SettingDust commented Oct 14, 2022

Current:

nbtCompound {
    put("id", "minecraft:grass")
    put("Count", 5.toByte())
    put("tag", nbtCompound { put("foo", "bar") })
}

nbtList {
  add(1)
  add("foo")
}

// Should be renamed to `toTag`
1.toByte().toNbt()
"foo".toNbt()

New:

StringTag("foo")
IntTag(1)

Provide a compound tag builder scope. Return a compound tag

compoundTag {
    "id" to "minecraft:air"
    "Count" to ByteTag(5)
    "tag" to compoundTag {
        "type" to "stone"
        "items" to listTag {
            add(StringTag("minecraft:grass"))
        }
        "exclude" to listTag(StringTag("minecraft:stone"))
    }
}

Or(have to set JvmName for functions):

compoundTag {
    "id"("minecraft:air")
    "Count" { ByteTag(5) }
    "tag" { compoundTag {
        "type"("stone")
        "items" { 
          listTag {
              +"minecraft:grass"
              +StringTag("minecraft:grass")
          }
        }
        "exclude" { ListTag(StringTag("minecraft:stone")) }
    } }
}
@jakobkmar
Copy link
Member

Mh, I much prefer the current DSL, I am not the biggest fan of these implicit APIs hiding the actual function calls - the only place where I would actually do this might be a simpler version of the text builder.

@SettingDust
Copy link
Author

How about the functions for constructing tags just like ByteTag()?

@jakobkmar
Copy link
Member

What would be advantage over the currently provided extension functions which do the same?

@SettingDust
Copy link
Author

What would be advantage over the currently provided extension functions which do the same?

toNbt need the data type exactly same. Such as 5.toByte().toNbt(). Maybe we can provide two methods at same time

@Amejonah1200
Copy link

Amejonah1200 commented Nov 28, 2022

Wouldn't be possible to have

nbtCompound { 
  "id" to "minecraft:grass"
  "Count" to 5.toByte()
  "tag" {
    "foo" to "bar"
  }
 }

using context receivers?

@SettingDust
Copy link
Author

SettingDust commented Nov 28, 2022

Why can't? I use the extension functions implemented
I don't looking deep into context receiver. But I think it's possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants