All Blocks in a Chunck to Obsidian

Discussion in 'Plugin Development' started by surtic, Mar 27, 2012.

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

    surtic

    Hello There,

    How can i easy make all Blocks in a Chunck to a Obsidian Block?

    Is this a good ore bad way?

    Code:
    public void makeChunckToWall( Chunk chunck) {
           
            for ( int x = 0; x == 16; x++ ) {
                for ( int z = 0; z == 16; z++ ) {
                    for ( int y = 0; y == world.getMaxHeight(); y++ ) {
                        chunck.getBlock(x, z, y).setType(Material.OBSIDIAN);
                    }
                }           
            }
           
        }
     
  2. Offline

    AmoebaMan

    Well first off you're going to want to change the "equal to" (==) operators to "less than" (<) operators. Perhaps brush up on your java syntax while you're at it.

    Secondly you'll want to make sure that the block you're setting to obsidian is actually a block. Add a test along the lines of (chunk.getBlock(x, y, z).getType().isBlock()). Otherwise you'll just end up with a massive block of obsidian.

    EDIT: Just realized that you're trying to make a wall of obsidian. Disregard that last bit.
     
  3. Offline

    Lolmewn

    This code would also set air to obsidian (Correct me if I'm wrong).
    Check if it's air first, if it's not, make it obby.
     
  4. Offline

    surtic

    AmoebaMan : Yes that "==" was wrong :)

    and i want a big wall but now i make Obsidan and Glas when the Y hight over 90 blocks is.

    Code:
        public void makeChunckToWall( Chunk chunk) {
           
            for ( int x = 1; x < 16; x++ ) {     
         
                for ( int z = 1; z < 16; z++ ) {
                   
                    for ( int y = 1; y < world.getMaxHeight(); y++ ) {
                       
                        if ( y > 90 ) {
                            chunk.getBlock(x, z, y).setType(Material.GLASS);
                        } else {
                            chunk.getBlock(x, z, y).setType(Material.OBSIDIAN);
                        }
                                           
                    }
                }           
            }
           
        }
    But now i had a big Problem with Generating / Load new Chunks.

    Code:
    for ( int x = 1; x <= (sidelength + 2); x++ ) {
                for ( int z = 1; z <= (sidelength + 2); z++ ) {
                   
                    Helper.log("X " + x); // is 1
                    Helper.log("Z " + z); // is 1
                   
                    world.loadChunk(x, z, true);
     
                   
                }
            }    
    Any Idea?
     
  5. Expressing it with the words of bergerkiller : Bukkit's API is very slow here. You have thousands of blocks to set, and Block.setType(...) (or whatever bukkit method you use to set a block) recalculates lighting every time it is called - and sends block updates.

    Technically, the fastest way would be to hook NMS classes and do it your way (leaving out updates to the client as well as lighting updates until you are done) and then do everything manually afterwards. That's some really advanced stuff, though, so I wouldn't at all recommend that for you. Well, bergerkiller has his library to help with that sort of things, I believe. I let him speak for himself though ;)

    If you don't need to perform that operation very often and if you can tolerate that the server will lag out for a while, you can leave it like that - the question is wheter you look for an "easy" or an "efficient" way ;)
     
  6. Offline

    surtic

    Bone008 : So i need this often... player can start a hardcore game with his friends.. then will the plugin generate a new world with his settings.

    but i can make the obsidian wall only 2 - 3 blocks massive thast enought i think.

    aja :) first i look for a easy way and when the most work can i make a efficent way.

    is that right that inside a chunk i have a coordinat system who be x 1 - 16 and z 1 - 16 and y 1 - 255 ?

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

Share This Page