Auto Building home

Discussion in 'Plugin Development' started by PHILLIPS_71, Jun 4, 2013.

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

    PHILLIPS_71

    How would i create a home when a certain block is placed, Could i do it with WorldEdit code?
     
  2. Offline

    chasechocolate

    I would use a .schematic file, I'm sure people out there have methods for getting all the blocks in them. If you want it to look rather sexy, here is a bit of code that will "build" a list of blocks (set the type and play the breaking effect):
    Code:java
    1. public static void regenerateBlocks(List<Block> blocks, final Material type, final byte data, final int blocksPerTime, final long delay){
    2. final List<Block> orderedBlocks = new ArrayList<Block>();
    3.  
    4. orderedBlocks.addAll(blocks);
    5.  
    6. final int size = orderedBlocks.size();
    7.  
    8. if(size > 0){
    9. new BukkitRunnable(){
    10. int index = size - 1;
    11.  
    12. @Override
    13. public void run(){
    14. for(int i = 0; i < blocksPerTime; i++){
    15. if(index >= 0){
    16. final Block block = orderedBlocks.get(index);
    17.  
    18. regenerateBlock(block, type, data);
    19.  
    20. index -= 1;
    21. } else {
    22. this.cancel();
    23. return;
    24. }
    25. }
    26. }
    27. }.runTaskTimer(McMinigames.getInstance(), 0L, delay);
    28. }
    29. }
    30.  
    31. public static void regenerateBlock(Block block, final Material type, final byte data){
    32. final Location loc = block.getLocation();
    33.  
    34. loc.getWorld().playEffect(loc, Effect.STEP_SOUND, type.getId());
    35.  
    36. block.setType(type);
    37. block.setData(data);
    38. }
     
    hawkfalcon and TheGreenGamerHD like this.
  3. Offline

    PHILLIPS_71

    chasechocolate
    Thanks just how do i get the .schematic file to place the block when a player uses the block that will build the home?
     
  4. Offline

    LucasEmanuel

    chasechocolate
    You should add some smoke effects to it as well every time a block is placed to make it look a little better ;)
     
  5. Offline

    NoLiver92

    chasechocolate Ive been looking for something like this for ages!

    Thanks XD

    but what is this:
    McMinigames.getInstance()
     
  6. Offline

    Pink__Slime

  7. Offline

    NoLiver92

    thats what i thought but i wanted to make sure, thanks
     
  8. Offline

    NoLiver92

    i am having to create blocks from their id and data how do i add the location to it to fit this code?
     
  9. Offline

    chasechocolate

    NoLiver92 well if you ever want to set/place the block in the world, your gonna have to know a location.
     
  10. Offline

    NoLiver92

    I know the location but i want to apply the location to the block so it can be used in your code above. as it gets the location from the block. Or is this not possible and Ill have to edit your code to do it?
     
  11. Offline

    MinecraftJoshjr

    LucasEmanuel, I think this might work with the smoke effect

    Code:java
    1. public static void regenerateBlocks(List<Block> blocks, final Material type, final byte data, final int blocksPerTime, final long delay){
    2. final List<Block> orderedBlocks = new ArrayList<Block>();
    3.  
    4. orderedBlocks.addAll(blocks);
    5.  
    6. final int size = orderedBlocks.size();
    7.  
    8. if(size > 0){
    9. new BukkitRunnable(){
    10. int index = size - 1;
    11.  
    12. @Override
    13. public void run(){
    14. for(int i = 0; i < blocksPerTime; i++){
    15. if(index >= 0){
    16. final Block block = orderedBlocks.get(index);
    17.  
    18. regenerateBlock(block, type, data);
    19.  
    20. index -= 1;
    21. } else {
    22. this.cancel();
    23. return;
    24. }
    25. }
    26. }
    27. }.runTaskTimer(McMinigames.getInstance(), 0L, delay);
    28. }
    29. }
    30.  
    31. public static void regenerateBlock(Block block, final Material type, final byte data){
    32. final Location loc = block.getLocation();
    33.  
    34. loc.getWorld().playEffect(loc, Effect.STEP_SOUND, type.getId());
    35. loc.getWorld().playEffect(loc, Effect.SMOKE, 0);
    36.  
    37. block.setType(type);
    38. block.setData(data);
    39. }
    40.  
    41. }
     
Thread Status:
Not open for further replies.

Share This Page