Open IndexOutOfMJ opened 3 months ago
Can you provide the files you tested?
That is a valid schematic, so no issues there. How are you getting the base64
value?
With this function:
async getData(reader: FileReader, file: Blob): Promise<string | null> { return new Promise((resolve) => { reader.onloadend = () => { if (typeof reader.result === 'string') { resolve(reader.result.replace('data:', '').replace(/^.+,/, '')); } }; reader.readAsDataURL(file); }); }
My best guess at this is that you're somehow loading the older nbt-ts
library instead of @enginehub/nbt-ts
, or some other such type mismatch is occurring. I'm personally unable to reproduce this. If you could provide a minimal project that reproduces the issue, that would be helpful. Otherwise, I would recommend double-checking the versions of everything.
Okay, the only two packages i'm using in this context are those:
"@enginehub/schematicwebviewer": "^4.9.0",
"buffer": "^6.0.3",
Can you approve this ?
I also ran into this same issue. To replicate i created a new Vite Project Added latest SchematicWebViewer, buffer, and blob-to-base64
This is my JS code
import {renderSchematic} from "@enginehub/schematicwebviewer";
import {Buffer} from "buffer";
import blobToBase64 from "blob-to-base64";
globalThis.Buffer = Buffer;
let temp = await fetch("./schem.schem")
let schematic = blobToBase64(await temp.blob(),(r,o)=>render(o))
function render(schematic) {
schematic = schematic.substring(37)
alert(schematic)
renderSchematic(document.querySelector('#schematicRenderer'),schematic , {
size: 500,
renderArrow: false,
renderBars: false,
corsBypassUrl: 'https://corsproxy.io/?',
});
}
in general this error means the NBT data is invalid. in your provided code i'm a bit confused by the random substring call there?
Yeah, that was the base64 api adding metadata about the encoding to the string, should have commented that
I managed to find the Root of this issue
The Problem is the getTagType function of the tag.js file. a transative dependency of SchematicJS
it checks what type the tag is instanceof.
However the function receives an object with following format ```{value:"examplevalue"}```` I added a unwrap to this function, and got it working again
if(tag instanceof Object){
tag = tag.value;
}````
hmm, is that from a deeply nested tag, or the root tag? i wonder if this is just an issue around root tag handling, as that differs between Sponge Schematic v2 & v3
I printed the object that is being passed into the function to the console using console.dir
It is instanceof Int2, wich is not being tested for in the getTagType function. It is the only time getTagType is called when displaying a schematic using SchematicWebviewer I noticed the code in my previous comment is faulty and only fixed this specific usecase
So is there a way to fix this problem ?
Hey,
I tried to load a .schem file and a .nbt file and ran in both cases in this issue:
Error: Invalid tag value at getTagType (nbt.js:15:9) at nbt.js:30:12 at Array.forEach ()
at tagToRecord (nbt.js:28:20)
at loadVersion2 (version2.js:49:5)
at loadSchematic (loader.js:45:15)
at renderer.js:113:13
at Generator.next ()
at renderer.js:44:66
at new ZoneAwarePromise (zone.js:2702:25)
This is the configuration i used: