How the heck do I read a .schematic file

Discussion in 'Plugin Development' started by DrAgonmoray, Nov 10, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    DrAgonmoray

    And before you say it: I can't use WorldEdit or any other plugin as a dependancy.
    How can I parse schematic files? D:
     
  2. Offline

    -_Husky_-

    MCedit?!
     
  3. Offline

    DrAgonmoray

    jesus.
    I want to do it via code, hence the reason I posted it in the development section.
     
    Kohle likes this.
  4. Or you could steal WorldEdit's code.
     
  5. Offline

    iffa

    Or you could use WorldEdit's API.
     
  6.  
  7. Offline

    iffa

    I fixed your post, I didn't have anything to say to the OP.
     
  8. Offline

    DrAgonmoray

    no duh. I know how to google.
    Now point me to where that shows me how to load .schematic files in Java.
    And seriously, stop trying to be a smart... Yeah.
    But stealing is badong! (bad and wrong)


    Nevermind, I figured it out.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  9. Offline

    Kohle

    Wanna share how? ;3
     
  10. Offline

    DrAgonmoray

    Code:
    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();
            }
        }
    
    }
    That's what I was using to test. You can get the JNBT library here.

    it's really basic and all it really does is load it, but it works eh?
     
    HON95 and dadaemon like this.
  11. Offline

    undeadmach1ne

    so you build off that lib and the user doesnt need it/not a dependency for your plugin? by 'load' do you mean place in the world or just load into memory for a future method to figure out how to place in the world? sorry for question barrage but i have been tossing an idea around in my head for a plugin that this would really help with, but in my testing i have been using worldedit and i would prefer not to (likely for the same reasons you dont want to). thanks for any further info :)
     
  12. Offline

    DrAgonmoray

    It loads the data into memory.
    And just drag the library into your project (using Eclipse in my case) and it'll work

    Now I think I'm sick, so I'm going to get off and go to sleep. i feel terrible :'(
     
  13. Offline

    undeadmach1ne

    thanks. hope you feel better after a rest. drink lots of water and keep warm (internet mom) :p
     
  14. Offline

    iffa

    Danke schön!

    Now I can add some easy-to-do populators to BananaSpace v2!

    EDIT: If I knew how to use that data.
     
  15. Offline

    DrAgonmoray

    I figured it was rather self-explanatory.
     
  16. Hey there @DrAgonmoray . Wanna say thanks for sharing this with us. Using it with great succes!

    Thanks!
     
  17. Offline

    Deleted user

    Sorry to bump an old thread but thanks for the code to load the schematic but how would you go about pasting said schematic?
     
  18. Bump, for a really simple solution without the extra libraries. Minecraft now has NBT Support ^_^.

    Code:
     
    import java.util.List;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.ArrayList;
    import net.minecraft.server.v1_4_6.*;
     
    public class HelloWorld {
     
     
        public static void main(String[] args) {
            HelloWorld h = new HelloWorld();
            h.init();
            
        }
        public void init(){
            try {
                
                InputStream fis = getClass().getResourceAsStream("medievalhouse.schematic");
                NBTTagCompound nbtdata = NBTCompressedStreamTools.a(fis);;
     
                
                short width = nbtdata.getShort("Width");
                short height = nbtdata.getShort("Height");
                short length = nbtdata.getShort("Length");
     
                byte[] blocks = nbtdata.getByteArray("Blocks");
                byte[] data = nbtdata.getByteArray("Data");
     
                NBTTagList entities = nbtdata.getList("Entities");
                NBTTagList tileentities = nbtdata.getList("TileEntities");
                
                fis.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
     
    }
     
Thread Status:
Not open for further replies.

Share This Page