Jump to content

[1.10] Trying to read schematic files {SOLVED}


bongotezz

Recommended Posts

Hello

 

I'm new to modding. Been learning a lot but I hit a roadblock. I can't seem to read information from schematic files. I want to make structures but not if i have to code it one block at a time. I want to be able to automate it. All of the code examples i've found don't appear to work. It might just be my lack of knowledge. Can anyone provide me with assistance?

 

Thank you in advance

 

Bongo

Link to comment
Share on other sites

JNBT is a library that allows you to read them. i've been able to read, length,width,height, the array of block IDs, and the array of meta data IDs. I'm still trying to figure out entities and tileentities. I'm kind of lost on those. Here's the code example i found to use with JNBT.

 

 

import java.io.File;

import java.io.FileInputStream;

import java.util.List;

import java.util.Map;

import org.jnbt.ByteArrayTag;

import org.jnbt.CompoundTag;

import org.jnbt.ListTag;

import org.jnbt.NBTInputStream;

import org.jnbt.ShortTag;

import org.jnbt.Tag;

 

public class HelloWorld {

 

    private static Tag getChildTag(Map<String, Tag> items, String key, Class<? extends Tag> expected) {

        Tag tag = items.get(key);

        return tag;

    }

 

    public static void main(String[] args) {

        try {

            File f = new File("Small Temple.schematic");

            FileInputStream fis = new FileInputStream(f);

            NBTInputStream nbt = new NBTInputStream(fis);

            CompoundTag backuptag = (CompoundTag) nbt.readTag();

            Map<String, Tag> tagCollection = backuptag.getValue();

 

            short width = (Short)getChildTag(tagCollection, "Width", ShortTag.class).getValue();

            short height = (Short) getChildTag(tagCollection, "Height", ShortTag.class).getValue();

            short length = (Short) getChildTag(tagCollection, "Length", ShortTag.class).getValue();

 

            byte[] blocks = (byte[]) getChildTag(tagCollection, "Blocks", ByteArrayTag.class).getValue();

            byte[] data = (byte[]) getChildTag(tagCollection, "Data", ByteArrayTag.class).getValue();

 

            List entities = (List) getChildTag(tagCollection, "Entities", ListTag.class).getValue();

            List tileentities = (List) getChildTag(tagCollection, "TileEntities", ListTag.class).getValue();

            nbt.close();

            fis.close();

            System.out.println(entities);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

 

}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.