How do I build stuff with code? (the smart way)

Discussion in 'Plugin Development' started by Baummann, Sep 12, 2011.

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

    Baummann

    I've seen some plugins which can build houses. But when I look at the source the only thing I understand is trainstation.

    Could someone please tell me how it's working?
     
  2. Offline

    TopGear93

    Code:
    Block block = player.getLocation().subtract(0,0,0).getBlock();
    block.setTypeId(***);
    this means a block will spawn at the players feet. if you want to build home with commands and such you need to use this idea, but ALOT of these lines of code to build a home. i might be wrong, doesnt hurt to try.
     
  3. Offline

    Taco

    Give this a shot:

    Only do this if you want to restore the landscape after it's built:Create a new class, this class will store everything destroyed when you build as an object. Then create a method to clear the area before building, this method should also put the blocks changed in an arraylist or something like it. Create another method to build the structure based on the player's location at the time of the object being constructed. After all that, construct a new object, call the clear and build methods, and then store the object in something to associate the player with the object, a hashmap will work great for this.

    If you don't care about not being able to restore the area built upon: Simply create a method to build the structure based on the player's location, the location of course being a parameter passed into the method. This method can be stored in your main class for easy access.
     
  4. Offline

    NeoSilky

    Is there an easy way to mass select an area of blocks? So say, you want to select the area between x+1, z+5 and x+2, z-5? :)
     
  5. Offline

    Taco

    Code:Java
    1. for(int x = -2; x <= 2; x++){
    2. for(int y = -2; y <= 2; y++){
    3. for(int z = -2; z <= 2; z++){
    4. Block block = location.getBlock().getRelative(x,y,z);
    5. }
    6. }
    7. }


    Something like that. Replace the 2 with whatever you want your radius to be. That was coded off the top of my head, so it may need a slight bit of tweaking.
     
Thread Status:
Not open for further replies.

Share This Page