{"id":15050664,"url":"https://github.com/katrix/typenbt","last_synced_at":"2025-04-10T02:19:40.090Z","repository":{"id":57737296,"uuid":"69351490","full_name":"Katrix/TypeNBT","owner":"Katrix","description":"A Scala NBT library that let's you focus on the data","archived":false,"fork":false,"pushed_at":"2022-03-23T19:26:44.000Z","size":255,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T02:19:35.816Z","etag":null,"topics":["hacktoberfest","minecraft","nbt","scala","scalajs","type-safe"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Katrix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-27T11:52:07.000Z","updated_at":"2024-01-16T04:52:59.000Z","dependencies_parsed_at":"2022-08-24T14:59:40.829Z","dependency_job_id":null,"html_url":"https://github.com/Katrix/TypeNBT","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katrix%2FTypeNBT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katrix%2FTypeNBT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katrix%2FTypeNBT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katrix%2FTypeNBT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Katrix","download_url":"https://codeload.github.com/Katrix/TypeNBT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142915,"owners_count":21054672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","minecraft","nbt","scala","scalajs","type-safe"],"created_at":"2024-09-24T21:28:49.432Z","updated_at":"2025-04-10T02:19:40.071Z","avatar_url":"https://github.com/Katrix.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeNBT\n\nTypeNBT is a idiomatic, type safe NBT library for Scala. TypeNBT allows you to focus on the data in the code, not the NBT as most other libraries requires.\n\nAdd TypeNBT to your project by including this line in build.sbt\n```scala\nlibraryDependencies += \"net.katsstuff\" %% \"typenbt\" % \"0.5.1\"\n//Or this if you use Scala.js\nlibraryDependencies += \"net.katsstuff\" %%% \"typenbt\" % \"0.5.1\"\n```\n\n## Why TypeNBT?\nWhy did I decide to write TypeNBT and not just use something that already existed.\n* You can find TypeNBT on maven\n* Everything in TypeNBT is immutable, this includes the collections\n* TypeNBT is type safe. There are no surprises when running the code and getting an exception back because you expected the wrong data type. Even the list is type safe\n* It includes the type information at runtime. How do serialize an empty list in other libraries, you can't really, but here you can do that\n* Convert anything to NBT. TypeNBT defines typeclasses for encoding and decoding a value to NBT. This aspect of the library isn't hidden away either. Instead it's a core part of how it works\n* Create a NBTCompound easily. TypeNBT easily allows you to create your entire NBTCompound in a single line using a HList like this `NBTCompound.fromHList(\"first\" -\u003e \"hi\" :: \"second\" -\u003e 5 :: \"third\" -\u003e false :: HNil)`. *NOTE*: Requires the use of the `typenbt-extra` module\n* Easy conversion to and from common types not represented by raw NBT. Notice the boolean in the above line\n* Full support for Mojangson parsing. *NOTE*: Requires the `typenbt-mojangson` module.\n* TypeNBT works for Scala.js\n\n## Using TypeNBT\n\nHere is some information about how to use TypeNBT in practice.\nFor all of these, make sure you import `net.katsstuff.typenbt._`.\n\n## Creating NBTTag, and the typeclasses that TypeNBT uses\n\nConverting a value to nbt can be done like this:\n```scala\nimport net.katsstuff.typenbt._\n5.nbt //Int, return NBTInt\n\"hi\".nbt //String, returns NBTString\nfalse.nbt //Boolean, returns NBTByte\nIndexedSeq(2, 5).nbt //IndexedSeq[Int], returns NBTIntArray\nNBTInt(1) //You can also create the NBTTag more explicitly\n```\n\n### NBTSerializer\nThis uses the typeclass `NBTSerializer[Repr, NBT]` which takes to types, the type to convert from, and the type to convert to. This is analogous to the type `Repr =\u003e NBT`.\n\n### NBTDeserializer\nThere is also `NBTDeserializer[Repr, NBT]` which goes the other way around, except that it returns an `Option` as the data might not be valid for a given type. This is analogous to the type `NBT =\u003e Option[Repr]`.\n\n### SafeNBTDeserializer\nFor cases where a value can always be safely converted from an nbt value, there exists `SafeNBTDeserializer`. This is analogous to the type `NBT =\u003e Repr`.\n\n### NBTView\nNext there is `NBTView` which combines `NBTSerializer` and `NBTDeserializer`. \n\n### SafeNBTView\nThere is also `SafeNBTView` which uses `SafeNBTDeserializer` instead of `NBTDeserializer`. \n\n### CaseLike\nThen there is `NBTViewCaseLike` and `SafeNBTViewCaseLike`. Which adds apply and unapply methods to the view to make certain types behave like they are normal nbt types. For example, you can do `NBTBoolean(false)` which will then convert the boolean to an nbt byte. \n\n### NBTType\nLastly there is `NBTType` which corresponds to the base nbt types. This also contains the byte id for the type.\n\n## On multiple type parameter lists\n\nFor some methods like `NBTCompount#getValue`, TypeNBT uses multiple parameter lists in the form of anonymous classes. Unless you really want to, you generally only have to fill in one of them.\n\n## typenbt-extra\nIf you want more fanciness, then there is also the module `typenbt-extra`, which contains some more operations which uses shapeless under the hood.\n\nFirst add the dependency to your build.\n```scala\nlibraryDependencies += \"net.katsstuff\" %% \"typenbt-extra\" % \"0.5.1\"\n//Or this if you use Scala.js\nlibraryDependencies += \"net.katsstuff\" %%% \"typenbt-extra\" % \"0.5.1\"\n```\n\nNow you can convert a `HList` into a `NBTCompound` or add a `HList` to an existing `NBTCompound`. First make sure you have your HList. The HList must consist of tuples from string to values that an NBTSerializer exists for. Then import `net.katsstuff.typenbt.extra._` and call `NBTCompound.fromHList(hList)` or do `compound ++ hList`. TypeNBT takes care of the rest.\n\n## typenbt-mojangson\nTypeNBT also has another module for both parsing and creating mojangson.\n\n```scala\nlibraryDependencies += \"net.katsstuff\" %% \"typenbt-mojangson\" % \"0.5.1\"\n//Or this if you use Scala.js\nlibraryDependencies += \"net.katsstuff\" %%% \"typenbt-mojangson\" % \"0.5.1\"\n```\n\nYou can then use `Mojangson.toMojangson` and `Mojangson.fromMojangson`\n\n## Examples\nThere exists more examples on how to use TypeNBT in the examples directory.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatrix%2Ftypenbt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatrix%2Ftypenbt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatrix%2Ftypenbt/lists"}