RubixDev / rustmatica

A Rust crate for working with Minecraft litematica files
https://crates.io/crates/rustmatica
GNU General Public License v3.0
10 stars 2 forks source link

Loading Litematic Schematic with negative position value causes InvalidValue Error instead successful load #5

Closed HafiTheCat closed 4 months ago

HafiTheCat commented 4 months ago

Actual Behavior

Loading a schematic with negative Position x value in the following way

fn main() {
    let res = rustmatica::Litematic::read_file("Supercharged_contained_shulker_farm.litematic");
    dbg!(res);
}

will result in the following error:

Err(
    NBT(
        Error(
            "invalid value: integer `-31`, expected usize",
        ),
    ),
)

Expected Behavior

Loading a schematic with negative Position x value will result in a successful load of the schematic

Steps to Reproduce the Problem

Load any schematic (or used test file below) that contains a negative Position x value.

Sidenote

I already mentioned this issue on a repo for a similar crate, which can be inspected here: SlopeCraft/mc_schem#1 The individual size values can also be negative, as can be seen by inspecting the attached schematic.

Specifications

Rust specifications

Rustc version: rustc 1.76.0 (07dca489a 2024-02-04) Toolchain: stable-x86_64-unknown-linux-gnu (default)

Schematic specifications

This .litematic was generated by the litematica mod, minecraft version minecraft 1.20.4. Type: LITEMATIC MinecraftDataVersion: 3465 Subversion: 1 Version: 6 Regions: 1

testSchematic.zip

RubixDev commented 4 months ago

Fixed in v0.2.0. This is about all the documentation on the litematica format, which doesn't really specify much, so I just thought it'd always be positive. But you're right. Looking at the code, both the region sizes and positions use BlockPos which can indeed be negative.