How to use prismarine-nbt - 8 common examples

To help you get started, we’ve selected a few prismarine-nbt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LeaPhant / skyblock-stats / lib.js View on Github external
async function getItems(base64){
    // API stores data as base64 encoded gzipped Minecraft NBT data
    let buf = Buffer.from(base64, 'base64');

    let data = await parseNbt(buf);
    data = nbt.simplify(data);

    let items = data.i;

    // Check backpack contents and add them to the list of items
    for(let [index, item] of items.entries()){
        if(objectPath.has(item, 'tag.display.Name') && (item.tag.display.Name.endsWith('Backpack') || item.tag.display.Name.endsWith('Itchy New Year Cake Bag'))){

            let keys = Object.keys(item.tag.ExtraAttributes);

            let backpackData;

            keys.forEach(key => {
                if(key.endsWith('backpack_data') || key == 'new_year_cake_bag_data')
                    backpackData = item.tag.ExtraAttributes[key];
            });
github PrismarineJS / mineflayer / lib / plugins / blocks.js View on Github external
function addBlockEntity (nbtData) {
    const blockEntity = nbt.simplify(nbtData)
    const absolutePoint = new Vec3(blockEntity.x, blockEntity.y, blockEntity.z)
    const loc = new Location(absolutePoint)

    // Handle signs
    if (blockEntity.id === 'minecraft:sign' || blockEntity.id === 'Sign') {
      const prepareJson = (i) => {
        const json = JSON.parse(blockEntity[`Text${i}`])
        json.text = json.text.replace(/^"|"$/g, '')
        return json
      }

      blockEntity.Text1 = new ChatMessage(prepareJson(1))
      blockEntity.Text2 = new ChatMessage(prepareJson(2))
      blockEntity.Text3 = new ChatMessage(prepareJson(3))
      blockEntity.Text4 = new ChatMessage(prepareJson(4))
github PrismarineJS / node-minecraft-protocol / src / datatypes / minecraft.js View on Github external
function writeCompressedNbt (value, buffer, offset) {
  if (value === undefined) {
    buffer.writeInt16BE(-1, offset)
    return offset + 2
  }
  const nbtBuffer = Buffer.alloc(sizeOfNbt(value))
  nbt.proto.write(value, nbtBuffer, 0, 'nbt')

  const compressedNbt = zlib.gzipSync(nbtBuffer) // TODO: async
  compressedNbt.writeUInt8(0, 9) // clear the OS field to match MC

  buffer.writeInt16BE(compressedNbt.length, offset)
  compressedNbt.copy(buffer, offset + 2)
  return offset + 2 + compressedNbt.length
}
github InventivetalentDev / MineRender / src / model / modelConverter.js View on Github external
loadNBT(structure).then((rawNbt) => {
        NBT.parse(rawNbt, (err, data) => {
            if (err) {
                console.warn("Error while parsing NBT data");
                console.warn(err);
                return;
            }

            if (!PRODUCTION) {
                console.log("NBT Data:")
                console.log(data);
            }

            parseStructureData(data).then((data) => {
                cb(data);
            })
        })
    })
github LeaPhant / skyblock-stats / lib.js View on Github external
async function getBackpackContents(arraybuf){
    let buf = Buffer.from(arraybuf);

    let data = await parseNbt(buf);
    data = nbt.simplify(data);

    let items = data.i;

    for(let item of items){
        item.isInactive = true;
        item.inBackpack = true;
    }

    return items;
}
github 1b8 / schematic / lib / main.js View on Github external
Schematic.parse = function (data, callback) {
  if (!callback) callback = function (err) {
    if (err) throw err;
  };

  nbt.parse(data, function (err, data) {
    callback(err, err ? null : new Schematic(data));
  });
};
github PrismarineJS / node-minecraft-protocol / src / datatypes / minecraft.js View on Github external
function sizeOfNbt (value) {
  return nbt.proto.sizeOf(value, 'nbt')
}
github 1b8 / schematic / lib / main.js View on Github external
Schematic.toBuffer = function (schem) {
  return nbt.writeUncompressed(schem.updateRaw());
};

prismarine-nbt

A parser and serializer for NBT archives

MIT
Latest version published 8 days ago

Package Health Score

81 / 100
Full package analysis