Pasting/loading Schematics

Discussion in 'Resources' started by p000ison, Jul 18, 2012.

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


    I know I am grave digging a little bit here, but would you by any chance have a method for saving schematics with world a WorldEdit Selection? Like be able to take what the user has selected and create a new schematic file with it then be able to load it with this awesome class.
  2. Offline


    This class is great, but not too great. It throws an ArrayIndexOutOfBoundsException in the paste method for the variable: blocks[index] which will sometimes be -122 or -117. I did extensive debugging on this because I have to get a working schematic loading and pasting methods. I printed out lots of the data of the iterations through the 3 for loops to many files and even did some more extensive testing that I will explain below.
    So first off, I decided to just throw in a check before it tries to set the blocks id and data that if the id was < 0, don't do it. I printed to a file every time the id was less than 0. it was usually -122, but occasionally there was a -117. I looked for the locations of those blocks, but that was too hard, So I decided to place almost every minecraft block, make a schematic, and try loading that. the below are my results.

    Here is the original schematic pasted perfectly with worldedit:


    Here is the schematic pasted with your class and methods:


    As you can see, there is a fair amount of useful blocks missing. The blocks that are missing are always missing (or return a negative number) regardless of the schematic. The way the bytes in the original NBT file is loaded must have a couple hiccups or imperfections. I hope this debugging will help you fix this problem!
    I may be taking on my own (much less efficient) schematic system, because I really need to be able to save and load selections and I am not having a good time trying to get schematics to load right without executing the world edit command with player.performCommand() >.>

    ok so I decided to take one more good look at the worldedit API and actually try to read the code rather than piecing the classes together like a puzzle to try to use the API, and I found that your load schematic method has some identical parts to worldEdits load method, but was missing a good chunk of it, and usefull parts too. So I copied the parts of World Edits load method that were missing, and added them to your load method, and instead of returning an instance of your schematic class, I used the iterations the worldedit Load method had for adding the blocks to the CuboicClipboard to add set the blocks Id and data. AND THAT WORKED! It took me wayyy to long to get this working >.>

    Fix your loadSchematic method to include all the necessary parts.
  3. Offline


  4. Offline


    Could you send me that library? :)
    Cause I got the same error?
  5. Offline


    Sorry. No longer use it
  6. Offline


    Can somebody else help me with that error? :O
  7. Offline


    Sorry to bump, But pasteSchematic and schematic showed up red on the first line of code and I couldn't figure out why...
    Any help? Thanks :)
    1. public static void pasteSchematic(Location loc, Schematic schematic) {
    2. byte[] blocks = schematic.getBlocks();
    3. byte[] blockData = schematic.getData();
    5. short length = schematic.getLenght();
    6. short width = schematic.getWidth();
    7. short height = schematic.getHeight();
    9. for (int x = 0; x < width; ++x) {
    10. for (int y = 0; y < height; ++y) {
    11. for (int z = 0; z < length; ++z) {
    12. int index = y * width * length + z * width + x;
    13. Block block = new Location(world2, x + loc.getX(), y + loc.getY(), z + loc.getZ()).getBlock();
    14. block.setTypeIdAndData(blocks[index], blockData[index], true);
    15. }
    16. }
    17. }
    18. }
  8. Offline


    FANTASTICO! This is absoloutly fantastic. Ive been looking for a method like this for about a year. On and off of course but thank you!
  9. (Sorry if I say crap right now, Im mad of failing since a few hours at this)
    Well I hate it to bump again, but I have the same problem as notrodash.
    I already figured out that the problem appears for blocks with a sub-id or however you want to call it (e. g. 130:5 for a enderchest with its rotation). If Im not wrong, the byteArray calculate the '130 / 5' wich returns -126.
    Anyone got a idea to fix this?
  10. Offline


    I managed to solve this by referring to WorldEdit's code. You should be able to extrapolate all the required information from here.
  11. Im really sorry, but I can't figure out how to do this :(
    Can you please give me a code example?
  12. Offline


    i updated the paste method to work with longer block id's:
    1. public static Schematic loadSchematic(File file) throws IOException {
    2. FileInputStream stream = new FileInputStream(file);
    3. NBTInputStream nbtStream = new NBTInputStream(stream);
    5. CompoundTag schematicTag = (CompoundTag) nbtStream.readTag();
    6. if (!schematicTag.getName().equals("Schematic")) {
    7. throw new IllegalArgumentException("Tag \"Schematic\" does not exist or is not first");
    8. }
    10. Map<String, Tag> schematic = schematicTag.getValue();
    11. if (!schematic.containsKey("Blocks")) {
    12. throw new IllegalArgumentException("Schematic file is missing a \"Blocks\" tag");
    13. }
    15. short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
    16. short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
    17. short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
    20. // Get blocks
    21. byte[] blockId = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
    22. byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
    23. byte[] addId = new byte[0];
    24. short[] blocks = new short[blockId.length]; // Have to later combine IDs
    26. // We support 4096 block IDs using the same method as vanilla Minecraft, where
    27. // the highest 4 bits are stored in a separate byte array.
    28. if (schematic.containsKey("AddBlocks")) {
    29. addId = getChildTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
    30. }
    32. // Combine the AddBlocks data with the first 8-bit block ID
    33. for (int index = 0; index < blockId.length; index++) {
    34. if ((index >> 1) >= addId.length) { // No corresponding AddBlocks index
    35. blocks[index] = (short) (blockId[index] & 0xFF);
    36. } else {
    37. if ((index & 1) == 0) {
    38. blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
    39. } else {
    40. blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
    41. }
    42. }
    43. }
    45. return new Schematic(blocks, blockData, width, length, height);
    46. }
  13. What did you change in the Schematic class
  14. Offline


    I think nothing needs to be changed there.
  15. Offline


    I have a problem... It seems like that the text on signs don't get pasted...
  16. Offline


    @p000ison Mine keeps throwing error after error, and now, I'm not sure how to fix it. It shows an error at loadSchematic. Here's the stack trace:

    [02:55:08 WARN]: Not in GZIP format
    [02:55:08 WARN]: at
    [02:55:08 WARN]: at<init>(GZIPInputStream.
    [02:55:08 WARN]: at<init>(GZIPInputStream.
    [02:55:08 WARN]: at org.jnbt.NBTInputStream.<init>(
    [02:55:08 WARN]: at
    [02:55:08 WARN]: at
    [02:55:08 WARN]: at org.bukkit.command.PluginCommand.execute(PluginComman
    [02:55:08 WARN]: at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    [02:55:08 WARN]: at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCo
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.PlayerConnection.handleC
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.PlayerConnection.a(Playe
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(Packe
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.NetworkManager.a(Network
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.ServerConnection.c(Sourc
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.MinecraftServer.v(Minecr
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.DedicatedServer.v(Dedica
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.MinecraftServer.u(Minecr
    [02:55:08 WARN]: at
    [02:55:08 WARN]: at net.minecraft.server.v1_7_R3.ThreadServerApplication.
  17. Offline


    @p000ison Please I can't get anything else to work so far.
  18. Offline


    Seems like your schematic-file isn't the right format.
    Try to make a new one with WE in it's standard schematic format.
    (the code form this post runs fine with my plugin's)
  19. Offline

    Hex_27 I figured out the worldedit solution. It worked fine on the same schematic...
  20. Offline

    Tommy Raids

    Last edited: Jan 18, 2015
  21. Offline


    My code says there is something wrong with extending Tag?
  22. Offline


        private short width;
        private short length;
        private short height;
    Are all shorts. What if I want go copy something that's really really big? >:)
  23. Offline


    Well, I highly doubt you would need to save a Schematic larger than 32767 * 32767 * 32767
    At least you would most likely crash your Server with that anyway...
    The_BloodHound likes this.
  24. Offline


    The_BloodHound likes this.
  25. Offline


    @p000ison This is my error ... Anyone can help me ?? Is it urgent

     [14:55:18] [thread Server / WARN]: Não em formato GZIP
    [14:55:18] [thread Server / WARN]: em (origem desconhecida)
    [14:55:18] [thread Server / WARN]:. Em <o init> (origem desconhecida)
    [14:55:18] [thread Server / WARN]:. Em <o init> (origem desconhecida)
    [14:55:18] [thread Server / WARN]:. Em org.jnbt.NBTInputStream <o init> (
    [14:55:18] [thread Server / WARN]: em me.mauro.eventos.Schematic.loadSchematic (
    [14:55:18] [thread Server / WARN]: em me.mauro.SmallHG.Main.onEnable (
    [14:55:18] [thread Server / WARN]: em (
    [14:55:18] [thread Server / WARN]: em (
    [14:55:18] [thread Server / WARN]: em org.bukkit.plugin.SimplePluginManager.enablePlugin (
    [14:55:18] [thread Server / WARN]: em org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin (
    [14:55:18] [thread Server / WARN]: em org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins (
    [14:55:18] [thread Server / WARN]: em net.minecraft.server.v1_7_R4.MinecraftServer.n (
    [14:55:18] [thread Server / WARN]: em net.minecraft.server.v1_7_R4.MinecraftServer.g (
    [14:55:18] [thread Server / WARN]: em net.minecraft.server.v1_7_R4.MinecraftServer.a (
    [14:55:18] [thread Server / WARN]: em net.minecraft.server.v1_7_R4.DedicatedServer.init (
    [14:55:18] [thread Server / WARN]: em (
    [14:55:18] [thread Server / WARN]: em (SourceFile: 628)
  26. @M4UR0
    It would have been nice if you translated the error to english instead of portuguese or whatever language.
    From my experience, I think it says Not in GZIP format. Go to the loadSchematic method and change:
    NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(stream));
    NBTInputStream nbtStream = new NBTInputStream(stream);
  27. Offline


    @megamichiel Continued with an error
    @megamichiel please help me

    [20:22:27] [Server thread/ERROR]: Error occurred while enabling SmallHG v1.0 (Is it up to date?)
        at org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers.getBlock( ~[craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers.getBlock( ~[craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.block.CraftBlock.getNMSBlock( ~[craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.block.CraftBlock.setTypeIdAndData( ~[craftbukkit.jar:git-Spigot-1649]
        at me.mauro.eventos.Schematic.pasteSchematic( ~[?:?]
        at me.mauro.SmallHG.Main.onEnable( ~[?:?]
        at ~[craftbukkit.jar:git-Spigot-1649]
        at [craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin( [craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin( [craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins( [craftbukkit.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.n( [craftbukkit.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.g( [craftbukkit.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.a( [craftbukkit.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.DedicatedServer.init( [craftbukkit.jar:git-Spigot-1649]
        at [craftbukkit.jar:git-Spigot-1649]
        at [craftbukkit.jar:git-Spigot-1649]
    Last edited: Dec 22, 2015
  28. Offline

    Go Hard

    For everyone having trouble loading the schematic file with this error
    Code: Not in GZIP format
    You need to put your schematic file in gzip format. How do you do that? You need do download a zip archive software that supports gzip format. I use 7zip. If you don't have it just install it. After its installed and you have your schematic file ready here is how to put it in a gzip. Locate your schematic file. Right click the file. You should see "7-Zip". Hover over it and find where it says "Add to archive" and click it
    Picture 1 (open)

    Now locate where is says "Archive format". Click the drop down box and click "gzip"​
    Picture 2 (open)

    You can change the file name to anything you was but make sure the Archive format is on gzip and the file name ends with .gz. For instance my schematic file name is "g_arrow.schematic.gz" I could change it to "g_arrow.gz" to make things easier. That's it! Just leave all the other settings alone. Click OK and it will create your gzip formatted schematic file. Now when you want to load that schematic make sure you end it with .gz like so
    loadSchematic(new File("plugins/SCHEMATICPATH/g_arrow.gz"))
    Hope this helped!​
  29. Offline


    Very usefull libary! But i have a problem with this, everything works with pasting and loading. But my schematic.gz files are not pasting everything. It seems it doenst support all blocks and data. If i have 159 (Stained Clay) with some colors in the schematic, it gives me this error:

    28.02 11:13:48 [Server] ERROR null
    28.02 11:13:48 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'plak' in plugin SchemPlakFunctie v1.0
    28.02 11:13:48 [Server] INFO at org.bukkit.command.PluginCommand.execute( ~[craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch( ~[craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand( ~[craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand( [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at net.minecraft.server.v1_8_R1.PlayerConnection.a( [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at java.util.concurrent.Executors$ [?:1.8.0_66]
    28.02 11:13:48 [Server] INFO at [?:1.8.0_66]
    28.02 11:13:48 [Server] INFO at net.minecraft.server.v1_8_R1.MinecraftServer.z( [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at net.minecraft.server.v1_8_R1.DedicatedServer.z( [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at net.minecraft.server.v1_8_R1.MinecraftServer.y( [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at [craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at [?:1.8.0_66]
    28.02 11:13:48 [Server] INFO Caused by: java.lang.NullPointerException
    28.02 11:13:48 [Server] INFO at org.bukkit.craftbukkit.v1_8_R1.util.CraftMagicNumbers.getBlock( ~[craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at org.bukkit.craftbukkit.v1_8_R1.util.CraftMagicNumbers.getBlock( ~[craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at org.bukkit.craftbukkit.v1_8_R1.block.CraftBlock.getNMSBlock( ~[craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at org.bukkit.craftbukkit.v1_8_R1.block.CraftBlock.setTypeIdAndData( ~[craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO at troller.PAsteload.pasteSchematic( ~[?:?]
    28.02 11:13:48 [Server] INFO at troller.Main.onCommand( ~[?:?]
    28.02 11:13:48 [Server] INFO at org.bukkit.command.PluginCommand.execute( ~[craftbukkit25.jar:git-Bukkit-1092acb]
    28.02 11:13:48 [Server] INFO ... 14 more
    Line 39 from the Paste/Load method are:
    block.setTypeIdAndData(blocks[index], blockData[index], true);
    He only paste dirt, stone or blocks with no data. I hope you can help me out ;)
  30. Offline


    Can I please have all the correct Imports?

    I keep getting errors, and for some Things you can import from JBNT and WE
Thread Status:
Not open for further replies.

Share This Page