Error when loading a schematic
Hello,
I'm having an issue with the schematic4j library: I can't load .schem files (Sponge format v3) in my Kotlin plugin. I'm using PaperMC 1.21.4, and I’ve added this version of schematic4j as a dependency.
Currently, my code looks like this:
val schematic: String = ""
private fun pasteSchematic(schematic: String) {
val schem = SchematicLoader.load("plugins/FastAsyncWorldEdit/schematics/$schematic")
logger.info("Loaded ${schem.name()} : ${schem.width()}x${schem.height()}x${schem.length()}")
}
However, the logger outputs:
[Typewriter] Loaded null : 0x0x0
I'm sorry to bother you, and I appreciate any help. Looking forward to your response, Xaya
This version : https://github.com/LegendsOfXania/schematic4j
I checked that the schematic existed and that it wasn't corrupted.
I recently have run into this issue as well. Using fabric loader 1.21.4 and world edit to save my schematic. The schematic works in Minecraft (though it is very large, not sure if that plays a part). When trying to use this tool all the methods return there being 0 blocks. Code snippet below
File schemFile = new File(filepath);
System.out.println("file");
System.out.println(filepath);
try {
System.out.println("Chemin du fichier: " + schemFile.getAbsolutePath());
if (!schemFile.exists()) {
throw new IOException("Le fichier n'existe pas: " + schemFile.getAbsolutePath());
}
Schematic schematic = SchematicLoader.load(schemFile);
controller.showProgressBar();
int totalBlocks = schematic.width() * schematic.length() * schematic.height();
System.out.println("Blocks");
System.out.println(totalBlocks);
I have confirmed the file exists and is not corrupted.
Hello @JaCrispySSB @LegendsOfXania , I don't think SandroHc is maintaining this project anymore since he's stopped responding to/updating it in over 2 years. However, I may be able to help both of you, I have a private fork of this repository which can read litematics and sponge schematics just fine. If you'd like to use this please add me on Discord at ryandev.
Hey @RyanLandDev! Yes, I do not have the mental capacity/motivation to support the project at the moment.
I have added you as as a collaborator so you can manage it as you see fit.
I can also find a way to give you access to the Maven Central repository, so you can publish new versions without breaking existing projects.
Hey @RyanLandDev! Yes, I do not have the mental capacity/motivation to support the project at the moment.
I have added you as as a collaborator so you can manage it as you see fit.
I can also find a way to give you access to the Maven Central repository, so you can publish new versions without breaking existing projects.
Thank you for your response.
I will probably update the project with fixes/enhancements in the near future. I think that a lot of developers could benefit from this.
And sure, that would be great.
I'm sorry for being unresponsive. Leaving my projects unmaintained always leaves a bad taste in my mouth. Sometimes life just gets in the way.
I hope everything goes well for you @SandroHc . Also, @RyanLandDev I've sent you a friend request on Discord to chat (xayatv)
Haven't received anything, make sure you've got the correct username - "ryandev." with the dot
I've think I've found the problem. World Edit typically generates schematics with an extra sub-compound tag called Schematic under the root tag similar to this SNBT:
"": {
Schematic: {
Blocks: {
Palette: {
"minecraft:stone": 0
"minecraft:cobblestone": 1
}
Data: bytes(...)
BlockEntities: []
}
Version: 3
Length: 33S
Metadata: {
WorldEdit: {
Origin: ints(8, -60, 8)
Platforms: {
"enginehub:fabric": {
Version: "7.3.16+cbf4bd5"
Name: Fabric-Official
}
}
EditingPlatform: "enginehub:fabric"
Version: "7.3.16"
}
Date: 1759923072977L
}
Height: 1S
DataVersion: 4440
Width: 33S
Offset: ints(-16, -1, -16)
}
}
However, [SpongeParser}(https://github.com/SandroHc/schematic4j/blob/master/src/main/java/net/sandrohc/schematic4j/parser/SpongeParser.java) ingores this sub-tag alltogether and assumes all children belong to the root resulting with zero / empty data.
As a workaround one can load their schematics similar to this:
final NamedTag rootTag = NBTUtil.Reader.read().from(...); // path, InputStream, or byte[]
final CompoundTag nbt = rootTag!=null&& rootTag.getTag() instanceof CompoundTag? (CompoundTag) rootTag.getTag() :null;
final CompoundTag schematicRoot = nbt.getCompoundTag("Schematic");
Schematic schematic = SchematicLoader.parse(schematicRoot);
In addition, you may need to use a GZIPInputStream if your schematic is compressed (which is very likely).