SmylerMC / litemapy

Litemapy's goal is to provide an easy to use way to read and edit Litematica's schematic file format
GNU General Public License v3.0
51 stars 5 forks source link

Exception while trying to read schematic from file #7

Closed Masken8 closed 2 years ago

Masken8 commented 2 years ago

I have a script that makes a 128x1x128 plane of minecraft:cobblestone with setblock and it runs with no errors. When I try to load the .litematic file with Litematica in Minecraft 1.17.1 I get "Exception while trying to read schematic from file".

Litematic.zip

SmylerMC commented 2 years ago

Can you provide the code you are using to generate that schematic please ?

SmylerMC commented 2 years ago

It looks like the NBT data is wrong, can you please provide me with your version of NBT lib as well please.

Masken8 commented 2 years ago
import sys
import csv
from PIL import Image, ImageColor
from litemapy import Schematic, Region, BlockState

ColorToBlock = {}

with open("colortoblock.csv", "r") as file:
    reader = csv.reader(file)
    for row in reader:
        rgbStringList = row[0].split(",", 2)
        r, g, b = int(rgbStringList[0]), int(rgbStringList[1]), int(rgbStringList[2])
        blockId = row[1]
        colorTuple = ImageColor.getcolor(f"rgb({r},{g},{b})", "RGB")
        ColorToBlock[colorTuple] = BlockState(f"minecraft:{blockId}")

input = sys.argv[1] # bmp
name = sys.argv[2] # litematic name
with Image.open(input) as im:
    (width, height) = im.size

    reg = Region(0,0,0,width, 1, height)

    schem = reg.as_schematic(name="karta")

    pix = im.load()

    for y in range(0, height):
        for x in range(0, width):
            if not pix[x,y]:
                break

            reg.setblock(x, 0, y, ColorToBlock[pix[x,y]])

    schem.save(f"{name}.litematic")

I think it's NBT lib 2.0.1

SmylerMC commented 2 years ago

I think it's NBT lib 2.0.1

NBT lib 2.0+ is not backward compatible so it broke litemapy. Try updating litemapy to 0.4.0a0, that should solve it.

Devnary commented 2 years ago

I got the same, but I used the example code without modifying.

Versions : Minecraft : 1.17.1 Litematica : 0.0.0-dev.20210906.183617 Litemapy : 0.4.0a0 nbtlib : 2.0.1

Masken8 commented 2 years ago

Updated, still broken. mapart.zip

SmylerMC commented 2 years ago

After some digging, it seems to be coming down to this issue in NBT lib: https://github.com/vberlier/nbtlib/issues/153 . I will be waiting for them to fix it. In the mean time, installing nbtlib 1.12.1 and litemapy 0.3.1a0 works.

SmylerMC commented 2 years ago

Fixed in f71f46b0b8d40bb981f4dea9fa97bb14ec631014 by forcing a newer version of nbtlib.