Pasting/Loading Schematics - Auto Builder

Discussion in 'Plugin Development' started by MCCoding, Jun 13, 2014.

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

    MCCoding

    I have got this class here that builds schematics for me but it's not very efficient, I'm needing it to be able to check all the blocks before they get placed, then if the block is different change it then and not remove then add the block every time it runs.

    Code:java
    1. public class Builder extends BukkitRunnable {
    2.  
    3. private static boolean started = false;
    4. private static Block loc;
    5.  
    6. private static CuboidClipboard build;
    7.  
    8. private static int x = 0;
    9. private static int y = 0;
    10. private static int z = 0;
    11.  
    12. private static final int blocksPerRun = 20;
    13. private static final long period = 1L;
    14.  
    15. private static int xmax;
    16. private static int ymax;
    17. private static int zmax;
    18.  
    19. public Builder(Core plugin) {
    20. try {
    21. //Schematics to load up on startup
    22. build = SchematicFormat.MCEDIT.load(new File("plugins/Clans/schematics/home.schematic"));
    23.  
    24. } catch (IOException e) {
    25. e.printStackTrace();
    26.  
    27. } catch (DataException e) {
    28. e.printStackTrace();
    29. }
    30. runTaskTimer((org.bukkit.plugin.Plugin) plugin, period, period);
    31. }
    32.  
    33. public static void buildSchematic(Block BlockLocation, String schemName) {
    34.  
    35. try {
    36. build = SchematicFormat.MCEDIT.load(new File("plugins/Clans/schematics/" + schemName + ".schematic"));
    37.  
    38. } catch (IOException e) {
    39. e.printStackTrace();
    40.  
    41. } catch (DataException e) {
    42. e.printStackTrace();
    43. }
    44.  
    45. loc = BlockLocation.getRelative(build.getOffset().getBlockX(), 0, build.getOffset().getBlockZ());
    46.  
    47. xmax = build.getWidth() - 1;
    48. ymax = build.getHeight() - 1;
    49. zmax = build.getLength() - 1;
    50.  
    51. x = 0;
    52. y = 0;
    53. z = 0;
    54.  
    55. started = true;
    56. }
    57.  
    58.  
    59. @SuppressWarnings("deprecation")
    60. @Override
    61. public void run() {
    62. if (!started) return;
    63.  
    64. for (int i = 0; i < blocksPerRun; i++)
    65. if (x == xmax && y == ymax && z == zmax) {
    66. started = false;
    67. return;
    68. }
    69.  
    70. if (x == xmax) {
    71. x = 0;
    72. if (z == zmax) {
    73. y++;
    74. z = 0;
    75. } else
    76. z++;
    77.  
    78. } else
    79. x++;
    80.  
    81. BaseBlock b = build.getPoint(new Vector(x, y, z));
    82. Block bb = loc.getRelative(x, y, z);
    83.  
    84. bb.setTypeId(b.getType());
    85. bb.setData((byte) b.getData());
    86. bb.getWorld().playEffect(bb.getLocation(), Effect.STEP_SOUND, bb.getTypeId());
    87.  
    88.  
    89. }
    90. }
     
  2. Offline

    MCCoding

    Anyone that can help me? maybe chasechocolate ?


    Anyone....?

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

    MCCoding

    B-U-M-P!

    Anyone?

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

Share This Page