NBT File Loader for CraftNite

Parse NBT files (like .schematic files) in the browser

目前為 2025-01-10 提交的版本,檢視 最新版本

// ==UserScript==
// @name         NBT File Loader for CraftNite
// @namespace    cheatnite69
// @version      1.0
// @description  Parse NBT files (like .schematic files) in the browser
// @author       unknown
// @match        https://craftnite.io/*
// @run-at       document-start
// @license      MIT
// @grant        GM_addStyle
// ==/UserScript==

// Function to handle file input and parse NBT data
function handleNBTFileUpload(file) {
    const reader = new FileReader();
    
    reader.onload = function(event) {
        const data = event.target.result;
        
        // Use nbt-parser to parse the file data (as an ArrayBuffer)
        try {
            const parsed = NBT.parse(data);
            console.log(parsed); // You can process the NBT data here
            
            // Example of extracting some data from parsed NBT (depends on your file structure)
            const entities = parsed.Entities || [];
            const blocks = parsed.Blocks || [];
            console.log('Entities:', entities);
            console.log('Blocks:', blocks);
        } catch (error) {
            console.error('Error parsing NBT file:', error);
        }
    };
    
    reader.onerror = function(error) {
        console.error('Error reading the file:', error);
    };
    
    // Read the file as an ArrayBuffer
    reader.readAsArrayBuffer(file);
}

// Function to trigger file upload
function createFileUpload() {
    const fileInput = document.createElement('input');
    fileInput.type = 'file';
    fileInput.accept = '.schematic';  // Accept .schematic files (NBT files)
    
    fileInput.addEventListener('change', function(event) {
        const file = event.target.files[0];
        if (file) {
            handleNBTFileUpload(file); // Parse the selected NBT file
        }
    });
    
    document.body.appendChild(fileInput);  // Optionally, append to the body for user interaction
}

// Trigger the file upload
createFileUpload();