Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
net.katsstuff:typenbt-mojangson_2.13
Advanced tools
The mojangson module for TypeNBT lets user parse and print mojangson
TypeNBT 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.
Add TypeNBT to your project by including this line in build.sbt
libraryDependencies += "net.katsstuff" %% "typenbt" % "0.5.1"
//Or this if you use Scala.js
libraryDependencies += "net.katsstuff" %%% "typenbt" % "0.5.1"
Why did I decide to write TypeNBT and not just use something that already existed.
NBTCompound.fromHList("first" -> "hi" :: "second" -> 5 :: "third" -> false :: HNil)
. NOTE: Requires the use of the typenbt-extra
moduletypenbt-mojangson
module.Here is some information about how to use TypeNBT in practice.
For all of these, make sure you import net.katsstuff.typenbt._
.
Converting a value to nbt can be done like this:
import net.katsstuff.typenbt._
5.nbt //Int, return NBTInt
"hi".nbt //String, returns NBTString
false.nbt //Boolean, returns NBTByte
IndexedSeq(2, 5).nbt //IndexedSeq[Int], returns NBTIntArray
NBTInt(1) //You can also create the NBTTag more explicitly
This 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 => NBT
.
There 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 => Option[Repr]
.
For cases where a value can always be safely converted from an nbt value, there exists SafeNBTDeserializer
. This is analogous to the type NBT => Repr
.
Next there is NBTView
which combines NBTSerializer
and NBTDeserializer
.
There is also SafeNBTView
which uses SafeNBTDeserializer
instead of NBTDeserializer
.
Then 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.
Lastly there is NBTType
which corresponds to the base nbt types. This also contains the byte id for the type.
For 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.
If you want more fanciness, then there is also the module typenbt-extra
, which contains some more operations which uses shapeless under the hood.
First add the dependency to your build.
libraryDependencies += "net.katsstuff" %% "typenbt-extra" % "0.5.1"
//Or this if you use Scala.js
libraryDependencies += "net.katsstuff" %%% "typenbt-extra" % "0.5.1"
Now 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.
TypeNBT also has another module for both parsing and creating mojangson.
libraryDependencies += "net.katsstuff" %% "typenbt-mojangson" % "0.5.1"
//Or this if you use Scala.js
libraryDependencies += "net.katsstuff" %%% "typenbt-mojangson" % "0.5.1"
You can then use Mojangson.toMojangson
and Mojangson.fromMojangson
There exists more examples on how to use TypeNBT in the examples directory.
FAQs
The mojangson module for TypeNBT lets user parse and print mojangson
We found that net.katsstuff:typenbt-mojangson_2.13 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.