[WE] Saving schematics

Discussion in 'Plugin Development' started by serega6531, Jul 8, 2014.

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

    serega6531

    How can i save schematic usign plugin? I don't have WG or WE selection, i only have min and max point.
     
  2. Offline

    mine-care

    It's a really hard process as far as I know.. The only thing I can think of is looping thru all blocks and registering somehow their location and type (location I mean a relevant not the actual location) but saving to file... Idk

    But you can use the world guard API and or ask sk89 how he did it :)

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

    serega6531

    I tried this:
    Code:java
    1. SchematicFormat.MCEDIT.save(new CuboidClipboard(
    2. max, min, new Vector(0,0,0)), file);
    But empty schematic creating.

    Okay, I used this:
    Code:java
    1. public class Schematic {
    2.  
    3. public static void save(File file, Location from, Location to){
    4. try {
    5. BukkitWorld bw = new BukkitWorld(from.getWorld());
    6. EditSession es = new EditSession(bw, Integer.MAX_VALUE);
    7. CuboidClipboard clipboard = new CuboidClipboard(
    8. vector(to.subtract(from).add(1, 1, 1)),
    9. vector(from),
    10. vector(from.subtract(to))
    11. );
    12. Region region = new CuboidRegion(bw, vector(from), vector(to));
    13. es.setFastMode(true);
    14. clipboard.copy(es);
    15. LocalEntity[] entities = bw.getEntities(region);
    16. for (LocalEntity entity : entities) {
    17. clipboard.storeEntity(entity);
    18. }
    19. SchematicFormat.MCEDIT.save(clipboard, file);
    20. } catch (IOException | DataException e) {
    21. e.printStackTrace();
    22. }
    23. }
    24.  
    25. public static void loadAndPaste(File file, Location loc) throws IOException, DataException{
    26. final CuboidClipboard clipboard = SchematicFormat.MCEDIT.load(file);
    27.  
    28. final Vector size = clipboard.getSize();
    29. final Vector origin = clipboard.getOrigin();
    30. for (int x = -16*3; x < size.getBlockX() + 16*3; x+=16) {
    31. for (int z = -16*3; z < size.getBlockZ() + 16*3; z+=16) {
    32. loc.getWorld().getChunkAt(origin.getBlockX()+x, origin.getBlockZ()+z).load();
    33. }
    34. }
    35.  
    36. EditSession es = new EditSession(new BukkitWorld(loc.getWorld()), Integer.MAX_VALUE);
    37. es.setFastMode(true);
    38. es.enableQueue();
    39. for (int x = 0; x < size.getBlockX(); ++x) {
    40. for (int y = 0; y < size.getBlockY(); ++y) {
    41. for (int z = 0; z < size.getBlockZ(); ++z) {
    42. Vector blockpos = new Vector(x, y, z);
    43. final BaseBlock block = clipboard.getBlock(blockpos);
    44.  
    45. if (block == null) {
    46. continue;
    47. }
    48.  
    49. Bukkit.getScheduler().runTask(TheBridges.instance, new PasteRunnable(blockpos.add(origin), block, es));
    50. }
    51. }
    52. }
    53. try {
    54. es.flushQueue();
    55. } catch (Throwable t) {
    56. t.printStackTrace();
    57. }
    58. try {
    59. clipboard.pasteEntities(origin);
    60. } catch (Throwable t) {
    61. t.printStackTrace();
    62. }
    63. }
    64.  
    65. private static Vector vector(Location loc){
    66. return new Vector(loc.getX(), loc.getY(), loc.getX());
    67. }
    68.  
    69. }
    70.  
    71. class PasteRunnable implements Runnable {
    72.  
    73. Vector pos;
    74. BaseBlock block;
    75. EditSession es;
    76.  
    77. public PasteRunnable(Vector pos, BaseBlock block, EditSession es){
    78. this.pos = pos;
    79. this.block = block;
    80. this.es = es;
    81. }
    82.  
    83. @Override
    84. public void run() {
    85. try {
    86. es.smartSetBlock(pos, block);
    87. } catch (Throwable t) {
    88. t.printStackTrace();
    89. }
    90. }
    91.  
    92. }

    This code creating schematics, but not loading. The world has no changes after pasting schematics.

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

    dsouzamatt

    serega6531 likes this.
  5. Offline

    serega6531

    Thanks, i'll try it.

    Well, looks like it works. dsouzamatt, thank you.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page