Build Buildings before players eyes.

Discussion in 'Plugin Development' started by CrazyGuy3000, Oct 4, 2013.

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

    CrazyGuy3000

    Hey there,
    Ive been playing a small amount of MCCW recently (Minecraft Colony Wars) and there using a custom bukkit plugin to make towers and buildings well BUILD block by block. It looks really cool so I was wondering how you go about doing this.
     
  2. Offline

    Plo124

    CrazyGuy3000 You can do a Bukkit runnable(), and iterate through all the blocks, and place them
     
  3. Offline

    CrazyGuy3000

    Would that require getting the location of each block and then setting it to air?
     
  4. Offline

    Plo124

    CrazyGuy3000
    Air, no
    Getting each location, yes, its a good idea to use a 4 dimension ArrayList, and or a series of HashMaps, and store each block, its co-ords relative to the base block, which you start from, and then the runnable can cycle through them, and place them 1 by 1, which is what I think you want.
     
  5. Offline

    CrazyGuy3000

    Can you show some simple code?
     
  6. Offline

    Plo124

    CrazyGuy3000 Gosh, it will take ages to type. I will do some sudo-code
    Code:
     
     
     
     
    <HashMap Block>
    Block.put(1, Material.STONE);
    Block.put(2, Material.AIR);
    <HashMap X>
    X.put(1, 0);
    X.put(2, 1);
    new Runnable(){
    get block 1, get its x, y and z. Add the main block location to this position, and set that block
    add 1 to the block, so next time it will place the second block
    wait a little bit to place the next block.
     
    }


    The sudo code would create 4 HashMap arrays, each will have the ID of the block, and their X, Y and Z from the main block that triggered the whole thing.
     
  7. Offline

    sgavster

    *follows thread* :p I wanna know the same thing.. Thanks Plo124 for that code xD
     
  8. Offline

    CrazyGuy3000

    Mmm, im working on some code now. If I get something working that looks cool Ill post a video.
     
  9. Offline

    metalhedd

    What you're talking about is actually a pretty complex task, you can't build the entire building in a single tick, so you need to spread it across several ticks using the scheduler in order to avoid any lag... you also have to remember that there are many blocks which require another block to 'attach' to, so you need to sort the blocks in such a way that all the pre-requisite blocks are in place before any dependent blocks are placed. (eg. a torch cant exist without a block beside/under it, to support it.)
    if you intend to allow for arbitrary placement of the building, you need to be capable of rotating the data for each individual block as well. There's also the issue of how you handle "ground-level" and how the building process interacts with existing terrain (ie. does it just replace all non-air blocks, or all non-air block below ground, etc.

    Ive actually already written a plugin that does exactly this: http://dev.bukkit.org/bukkit-plugins/build-in-a-box/ (If you're going to try it, use the latest development build, the current bukkitdev release has a nasty bug :\)

    So far, it's the biggest and most complex plugin I've coded, so I can't recommend attempting it as a 'beginners project.' you'll likely have quite a hard time of it... That being said, you can find the source code for plugin on github: http://github.com/andrepl/BuildInABox/

    It does everything I've described above, and while I don't claim that it's the best example.. it seems to be exactly what you're looking for, feel free to use anything you find useful in the source code, and if you have any specific questions you can send me a pm.
     
    flash1110 and sgavster like this.
  10. Offline

    AGuyWhoSkis

    I have been wondering how to do the same thing for some time. Instead of doing this whole thing by code, you could just use world edit. It's simple; you save the thing you want to "appear" as a schematic. And then you load it with world edit's code. The API for world edit is here; you want to look under worldedit>cuboidclipboard and there you will find all the methods; one of which is "loadschematic" (Note: it is deprecated). Here's a method I found when searching online on how to use it:
    Code:
    public void loadArea(World world, File file, com.sk89q.worldedit.Vector origin) throws DataException, IOException, MaxChangedBlocksException {
        EditSession es = new EditSession(new BukkitWorld(world), 999999999); //Max number of blocks editable
        CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
        cc.paste(es, origin, false);
    }
    Please note I have not the slightest clue how to use worldedit's "Vectors". I have yet to actually get this code working. Also, you have to add worldedit as an external jar in your build path before you can use this method.
     
Thread Status:
Not open for further replies.

Share This Page