Code Monkey home page Code Monkey logo

schematic4j's Introduction

Schematic4j

Latest version

Java parser for the .schem/.schematic/.litematic Minecraft formats. ๐Ÿ—บ

Supported formats

Format Extension Links
Sponge Schematic .schem Spec: v1 โ€ข v2 โ€ข v3
Litematica .litematic Spec โ€ข Discussion
Schematica .schematic Spec

Installation

Add the following dependency to your build file.

If using Gradle (build.gradle):

repositories {
    mavenCentral()
}

dependencies {
    implementation 'net.sandrohc:schematic4j:1.1.0'
}

If using Maven (pom.xml):

<dependency>
    <groupId>net.sandrohc</groupId>
    <artifactId>schematic4j</artifactId>
    <version>1.1.0</version>
</dependency>

For development builds, please see: https://jitpack.io/#net.sandrohc/schematic4j

Usage

Here are some examples on how to use this library:

// Load schematic from a file.
// Currently supported formats include .schematic, .schem and .litematic.
Schematic schematic = SchematicLoader.load("/path/to/your.schematic"); 

schematic.name();
schematic.width();
schematic.height();
schematic.length();
schematic.block(0, 0, 0).name;
schematic.blocks().collect(Collectors.toList());
schematic.blockEntities().collect(Collectors.toList());
schematic.entities().collect(Collectors.toList());

schematic4j's People

Contributors

ryanlanddev avatar sandrohc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

schematic4j's Issues

SchematicUtil.load switches up blocks, inserts extra blocks

Hello! New to the Minecraft dev scene so bear with me, but I'm pretty bewildered here. :)

I'm working on a side project to try and implement a layer-by-layer blueprint viewer (a la Schematic2Blueprint) that works on .schem Sponge format schematic files, and am using this library as a dependency. With some schematics (I'm using Amulet to export them to .schem, if that makes any difference) it works fine, but with others, weird stuff starts to happen in the block ordering.

Case in point - I set up a big pile of many different block types in my creative world so I could test how my app behaves on all of them:
image

The .schem file itself seems to be fine, because I can re-import it into Amulet or Litematica and all the blocks look correct. However, parsing it with SchematicUtil.load has some weird behavior.

The first level of blocks, for instance:

image

Going from north to south on one vertical Y value (if I understand correctly) should be

Schematic schematic = SchematicUtil.load(path);
int length = schematic.getLength();
int height = schematic.getHeight();
int width = schematic.getWidth();
for (int i = 0; i < height; i++) {
    for (int j = 0; j < length; j++) {
	    for (int k = 0; k < width; k++) {
		    SchematicBlock block = schematic.getBlock(k, i, j);
	    }
    }
}

which is what I am doing in my application. Given the row above, the result I would expect would be

minecraft:stone
minecraft:granite
minecraft:polished_granite
minecraft:diorite
minecraft:polished_diorite
minecraft:andesite
minecraft:polished_andesite
minecraft:deepslate
minecraft:cobbled_deepslate

Instead, what I get is

minecraft:stone
minecraft:granite
minecraft:polished_granite
minecraft:polished_blackstone_brick_stairs
minecraft:grass_block
minecraft:mossy_stone_bricks
minecraft:grass_block
minecraft:yellow_stained_glass
minecraft:grass_block

As you can see, it starts off correct and then kind of goes off the rails from there. The rest of the parsing gives much the same result - some blocks are listed as being where they are supposed to be, while others seem to have been swapped in from wildly different parts of the schematic, or just slotted in at random. (The grass_block is a repeated offender.)

Am I doing something wrong in how I'm using the library? Or is there a sneaky bug lurking around here? I've attached the .schem file in question here: palette-lvl1.zip; please let me know if there's other info that would be helpful! :)

(Thanks very much for this tool, also! Assuming I can figure out what the issue is here, it's been awesome in all other regards. :) )

[Feature Request] Support for serialization to schematic formats.

VoxelSniper used to have a proprietary system for stencils (basically schematics) which no longer works (due to block id's no longer numerical for many a year). In our fork we have refactored this to use schematics using Schematic4J. Creating schematics from an area selection is something that we still have to implement.

We would like to see a way to create a schematic from an input of blocks, entities etc. Perhaps something like a builder pattern.

Is this something you would consider within the scope of Schematic4J?

.litematics and .schematics are not being loaded correctly.

Some schematics don't seem to load properly, while others work just fine. I tested a few schematics, and it seems like .schematics and .litematics don't work while .schems do work.

Examples

TestedSchematics.zip contains the schematics I have tested.

1 and 2 work fine. 1:
image

In 3 and 4, all blocks have suddenly become air. Screenshot of code (offset returns 0,0,0):
image

5 outputs a bugged schematic that somewhat looks like what it should look like, but obviously it is not 100% correct.
image

Hope you can do something with this.

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.