Coder Social home page Coder Social logo

mojangutils's Introduction

MojangUtils

MojangUtils is a utility library for the popular NBTAPI.
MojangUtils mainly focuses on the implementation of NBTPaths.

Usage

You can freely download, share, alter and ofcourse use this code.
Too use or "import" the project, download the source code and add it to your project. Though refactoring of the import is probably needed then.
However, this code is not "multi-version" compatible, yet (?). So manier import will probably not be functioning anyways and some alterations might need to be made.

MojangsonUtils

The MojangsonUtils class has 3 main functionalities:

  • Formatting; Format NBT extensively with the #getInteractiveMojangson method
  • Getting; Retrieving data via the #getDataFromPath method
  • Setting; Setting data into NBT via the <T> #setDataToPath method

Too create an instance of MojangsonUtils use the MojangsonUtilsBuilder too create an instance with the formatting you desire.

NBTPath

NBTPaths are meant to allow the traversal of NBT with text! This is especially useful if you want users to be able to input and work with NBT.
NBTPaths are therefore just a collection of NBTKeys with a certain string value.
Too create a NBTPath create a NBTPathBuilder first and add all neccessery keys to it, before ceating the actual NBTPath.
This is done to ensure that NBTPaths don't change after being created.

NBTKey

There are 2 types of NBTKeys:

  • NBTKey; A string key for key-value pairs/NBTCompounds
  • NBTArrayKey; A integer key for lists or arrays

Creating either can be done with their respective #parseStringToKey function.

Code Examples

Since MojangsonUtils is the main aspect of the code library, let's start there:

final MojangsonUtils utils = new MojangsonUtilsBuilder("##")
                .setValCol(ChatColor.RED)
                .setValTypeCol(ChatColor.MAGIC)
                .setTagCol(ChatColor.AQUA)
                .create();

Here we create an instance of MojansonUtils where the Separator is "##". This means that NBTPathBuilders using this instance will split the provided String at every instance of "##".

final NBTPath baublesPath = new NBTPathBuilder(utils).parseString("ForgeCaps##baubles:container##Items").create();

Here utils is a the instance of the MojangsonUtils class from above.
The #praseString method will split the provided String at every "##", resulting in the following path:
ForgeCaps -> baubles:container -> Items

But how do NBTArrayKeys work? Very simply:

final NBTArrayKey arrKey = NBTArrayKey.parseToArrayKey(0);

This creates in secret a regular NBTKey with a key value of "[0]". The same formatting can be used when parsing a String to NBTPathBuilder:

final NBTPath arrKey = new NBTPathBuilder(utils).parseString("[0]").create();

Both do practically the same, but one is alot easier todo and recommended.

In case you want to create an empty NBTPath you can do it the following:

final NBTPath emptyPath = new NBTPathBuilder(utils).create();

mojangutils's People

Contributors

conorsmine avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.