Code Monkey home page Code Monkey logo

rustmatica's Introduction

rustmatica

Crates.io

A rust crate for working with Minecraft litematica files.

Overview

The two main types of this crate are [Litematic] and [Region]. See their documentation for more info.

The examples directory contains a few basic examples for how to use this crate.

Usage with [mcdata]

rustmatica is tightly coupled with [mcdata] and makes use of its traits for block states, entities, and block entities. By default, schematics will use [mcdata]s "generic" types which store most of their data using [fastnbt::Value]s.

use rustmatica::Litematic;
use mcdata::util::UVec3;

// type must be declared explicitly for Rust to use the default generics
let schem: Litematic = Litematic::read_file("test_files/axolotl.litematic")?;

// block has type `mcdata::GenericBlockState`
let block = schem.regions[0].get_block(UVec3::new(1, 0, 1));
assert_eq!(block.name, "minecraft:water");
// properties aren't typed
assert_eq!(block.properties["level"], "0");
# Ok::<(), rustmatica::Error>(())

But [mcdata] also offers more concrete types when enabling certain cargo features. To use these, add a custom dependency on [mcdata] similar to this:

mcdata = { version = "<version>", features = ["latest", "block-states"] }

Then you can use the mcdata::latest::BlockState type instead:

use rustmatica::Litematic;
use mcdata::{util::UVec3, latest::BlockState};
use bounded_integer::BoundedU8;

let schem: Litematic<BlockState> = Litematic::read_file("test_files/axolotl.litematic")?;

// block has type `BlockState`
let block = schem.regions[0].get_block(UVec3::new(1, 0, 1));
assert_eq!(block, &BlockState::Water {
    level: BoundedU8::new(0).unwrap(),
});
# Ok::<(), rustmatica::Error>(())

rustmatica's People

Contributors

newtykip avatar rubixdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ateijelo newtykip

rustmatica's Issues

Add support for many versions of Minecraft

Create versions of the DataExtractor for various versions of Minecraft so that we can provide feature flags that provide all of the relevant blocks for a given version of Minecraft - also update the litematica schematic where relevant if necessary.

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.