Giter Club home page Giter Club logo

moonlakenbt's Introduction

MoonLakeNBT

Minecraft MoonLake NBT Lib By Month_Light

简介

中文 Minecraft WikiNBT 格式页面链接: NBT
基于 MinecraftNBT 格式所制作的 NBT 支持库, 读写 NBT 文件等等.

NBT 标签定义

每一个标签在数据树中都是一个独立的部分. 标签的第一个字节为标签类型(ID),其后两字节为存储名称的长度, 之后以 UTF-8 格式的字符串的方式存储标签. 尽管在默认的情况下 Minecraft 本身并不会存储带有空格的名称, 但是标签名称可以包含空格.

ID 图标 标签类型 对应类型 辅助信息 描述
0 N/A TAG_End NBTTagEnd 用于标记复合标签的结尾. 本标签无任何名称所以只有一个零字节.
1 TAG_Byte TAG_Byte NBTTagByte 1字节/8位, 有正负 有正负的整值数据类型, 通常用于布尔表达式.
2 TAG_Short TAG_Short NBTTagShort 2字节/16位, 有正负, 字节序: BE 有正负的整值数据类型.
3 TAG_Int TAG_Int NBTTagInteger 4字节/32位, 有正负, 字节序: BE 有正负的整值数据类型.
4 TAG_Long TAG_Long NBTTagLong 8字节/64位, 有正负, 字节序: BE 有正负的整值数据类型.
5 TAG_Float TAG_Float NBTTagFloat 4字节/32位, 有正负, 字节序: BE, IEEE 754-2008 标准, binary32. 有正负的浮点数据类型.
6 TAG_Double TAG_Double NBTTagDouble 8字节/32位, 有正负, 字节序: BE, IEEE 754-2008 标准, binary64. 有正负的浮点数据类型.
7 TAG_Byte_Array TAG_Byte_Array NBTTagByteArray TAG_Int 的辅助信息大小以及 TAG_Byte 的辅助信息大小. 数组.
8 TAG_String TAG_String NBTTagString 前2个字节 (TAG_Short) 存储字符串字符的个数(字符串的长度length). 然后存储 UTF-8 标准的字符串, 没有 '\0' 结束符, 只是以单纯的字符序列的形式存储. 一个采用 UTF-8 标准的字符串, 有尺寸限制, 也就是说会以空结尾.
9 TAG_List TAG_List NBTTagList 辅助信息的第1个字节 (TAG_Byte) 存储列表标签类型的 ID, 接下来的4个字节 (TAG_Int) 存储列表的 size, 接下来的字节将存储 size 个列表标签类型的辅助信息. 假如第一个字节是 0x08, id是8, 对应的标签是 TAG_String, 如果 size 是 0x00000004, 接下来将会存储4个 TAG_String 标签的辅助信息. 列表标签(既然都说了是列表)存储的内容都是相同类型的标签, 所以只在第一个字节表明标签类型. 一系列没有重复标签ID和标签名称的辅助信息.
10 TAG_Compound TAG_Compound NBTTagCompound 标签的完整形式, 需要附加 TAG_End 一系列完整的标签信息, 包括ID、名称以及辅助信息等. 任意两个标签都不会有相同的名称.
11 TAG_Int_Array TAG_Int_Array NBTTagIntegerArray 辅助信息前4个字节 (TAG_Int) 用于存储数组的大小 size, 紧接 size4 字节 (TAG_Int) 的数组数据. 占用存储空间: 4+4size Byte. 存储 TAG_Int 的辅助信息的数组.
  • 图标资源和部分内容均摘自中文 Minecraft Wiki 侵权删.

ing...

moonlakenbt's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ammarx

moonlakenbt's Issues

Getting only a specific field data

I have to basically read the Minecraft servers.dat file, which is located in the .minecraft folder.
I was able to get the following output

{ip:"dev.tagcraftmc.com",name:"Minecraft Server",icon:"big text here"}
{ip:"play.network.com",name:"Minecraft Server"}
{ip:"123",name:"Minecraft Server"}

using:

try {
    File file = new File("C:\\Users\\ammar\\AppData\\Roaming\\.minecraft\\servers.dat");
    NBTTagCompound root = NBTUtil.readFile(file, false);
    System.out.println("read: " + root);
    for (NBTBase servers : root.getList("servers")) {
        System.out.println(servers);
    }
} catch (IOException e) {
    e.printStackTrace();
}

However I wanted to ask, is there a way I can get IPs only to print?

P.S. I recently found your project and I have to say, this is totally amazing!

odd behavior of writing NBT data

I have a function which writes to the servers.dat file in the minecraft directory:

static void testWrite() {
        
        System.out.println("WRITE TEST");
        NBTTagCompound root = new NBTTagCompound();
        NBTTagList<NBTTagCompound> server = new NBTTagList<>("servers");
        NBTTagCompound data = new NBTTagCompound();
        data.setString("name", "name1");
        data.setString("ip", "dev.tagcraftmc.com");
        server.add(data);
        server.add(data);
        
        data.setString("name", "name2");
        data.setString("ip", "dev.tagcraftmc.com");
        server.add(data);
        root.put(server);
        System.out.println(root.toString());
        try {
            NBTUtil.writeFile(root, new File("C:\\Users\\ammar\\AppData\\Roaming\\.minecraft\\servers.dat"), false);
        } catch (IOException e) {
            e.printStackTrace();
        }
}

The expected out should be:
{servers:[0:{ip:"dev.tagcraftmc.com",name:"name1"},1:{ip:"dev.tagcraftmc.com",name:"name1"},2:{ip:"dev.tagcraftmc.com",name:"name2"}]}

While I seem to be getting:
{servers:[0:{ip:"dev.tagcraftmc.com",name:"name2"},1:{ip:"dev.tagcraftmc.com",name:"name2"},2:{ip:"dev.tagcraftmc.com",name:"name2"}]}

It seems like the new data is replacing all the old data. Am I doing something wrong over here or is this a bug?

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.