Generate Load new Chunks

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

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

    surtic

    Hi all and Thanks for Helping me.

    I make a Plugin wo Player can Create a Hardcore Game and other Players can Join. When the Game Start will the Plugin Create a new World and Generate the World (like WorldBorder /wb fill) that all Chunks are generate.

    But how exactly i can do this? I had not found some mutch wo helping me...

    My StartGameTask
    PHP:
    package ch.nonameweb.bukkit.plugins.hardcore.task;
     
    import org.bukkit.Chunk;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
     
    import ch.nonameweb.bukkit.plugins.hardcore.Game;
    import ch.nonameweb.bukkit.plugins.hardcore.Hardcore;
    import ch.nonameweb.bukkit.plugins.hardcore.Helper;
    import ch.nonameweb.bukkit.plugins.hardcore.manager.LocalManager;
     
    public class 
    StartGameTask extends Task{
     
        private 
    Hardcore plugin;
        private 
    LocalManager local;
        private 
    Game game;
        private 
    World world;
       
        private 
    Integer sidelength;
       
        public 
    StartGameTaskGame game ) {
            
    this.plugin Hardcore.getInstance();
            
    this.local plugin.getLocalManager();
            
    this.game game;
        }
       
        @
    Override
        
    public void run() {
           
            
    world plugin.getServer().getWorldgame.getName().toLowerCase() );
           
            
    game.sendMessageToAllPlayerlocal.getStr("TASK_WORLD_START_GENERATE"));
            
    createAllChuncks();
            
    game.sendMessageToAllPlayer("chunks generatet");
           
            
    game.sendMessageToAllPlayer("start generate wall");
            
    //createWall();
            
    game.sendMessageToAllPlayerlocal.getStr("TASK_WORLD_FINISH_GENERATE"));
           
            
    game.sendMessageToAllPlayerlocal.getStr("TASK_TP_START_PLAYERS"));
            
    //teleportAllPlayerToWorld();
            
    game.sendMessageToAllPlayerlocal.getStr("TASK_TP_FINISH_PLAYERS"));
           
            
    // Set Task to Inaktiv so we can remove this Thread
            
    plugin.getTaskManager().setInaktiv(this);
        }
       
        public 
    void createAllChuncks() {
           
            
    Integer size 0;
           
            if ( 
    game.getSize().equalsIgnoreCase("small") ) {
                
    size plugin.getSettingsManager().getSizeSmall();
            } else if ( 
    game.getSize().equalsIgnoreCase("big") ) {
                
    size plugin.getSettingsManager().getSizeBig();
            } else { 
    // Medium Standard
                
    size plugin.getSettingsManager().getSizeMedium();
            }
           
            
    Integer chunks game.getPlayers().size() * size;
           
            
    sidelength 0;
           
            
    // Nur ungerade Zahlen
            
    for ( int i 1<= 100) {   
               
                if ( ( 
    ) >= chunks) {
                    
    sidelength i;
                    
    101;
                   
                }
               
            }
           
            
    // Chuncks werden geladen nur nur im Plus bereich X+ Z+
            
    for ( int x 1<= (sidelength 2); x++ ) {
                for ( 
    int z 1<= (sidelength 2); z++ ) {
                   
                    
    Helper.log("X " x);
                    
    Helper.log("Z " z);
                   
                    
    world.loadChunk(xztrue);
                   
                }
            }       
           
        }
       
        public 
    void createWall() {
           
            for ( 
    int x 1<=  sidelength 2x++ ) {
               
                
    Helper.log("Wall x" x);
               
                for ( 
    int z 1<= sidelength 2z++ ) {
                   
                    
    Helper.log("Wall z" z);
                   
                    if ( 
    == ) {
                        
    makeChunckToWallworld.getChunkAt(xz) );               
                    } else if ( 
    == sidelength ) {
                        
    makeChunckToWallworld.getChunkAt(xz) );               
                    } else {
                       
                        if ( 
    == ) {
                            
    makeChunckToWallworld.getChunkAt(xz) );                       
                        } else if ( 
    == sidelength 2) {
                            
    makeChunckToWallworld.getChunkAt(xz) );
                        }
                       
                    }
                   
                }
               
            }       
           
        }
       
        public 
    void makeChunckToWallChunk chunk) {
           
            for ( 
    int x 116x++ ) {
               
                
    Helper.log("Block x" x);
               
                for ( 
    int z 116z++ ) {
                   
                    
    Helper.log("Block z" z);
                   
                    for ( 
    int y 1world.getMaxHeight(); y++ ) {
                       
                        
    Helper.log("Block y" y);
                       
                        if ( 
    90 ) {
                            
    chunk.getBlock(xzy).setType(Material.GLASS);
                        } else {
                            
    chunk.getBlock(xzy).setType(Material.OBSIDIAN);
                        }
                                           
                    }
                }           
            }
           
        }
       
        public 
    void teleportAllPlayerToWorld() {
           
            for ( 
    Player player game.getPlayers() ) {
               
                
    int x = (int)Math.floor((Math.random() * sidelength ) + 1);
                
    int z = (int)Math.floor((Math.random() * sidelength ) + 1);
               
                
    Helper.log("X : " x);
                
    Helper.log("Z : " z);
               
                
    Chunk chunk world.getChunkAt(xz);
               
                
    chunk.getX();
                
    chunk.getZ();
                
    int y world.getHighestBlockAt(xz).getY();
               
                
    player.teleport(new Location(worldxyz) );
            }
           
        }
       
       
    }
    But i get an Error on
    Code:
    world.loadChunk(x, z, true);[code]
     
    Is that right that the Chunks have his own Coordinate System Outside and Inside?
     
  2. Offline

    Father Of Time

    You have asked several large questions, there is no one person who will sit down and describe this entire process in detail. What you need to do is break down your problem into smaller pieces and solve the smaller pieces one at a time. For instance:

    1) allowing a player to create a new world by command (seems like a massively bad idea to me)
    2) creating a custom chunk generator
    3) creating a custom chunk populator
    etc.

    Try to start small, get one aspect of your project working, and expand on that framework. Trying to start with the entire project assembled at once and debugging the misbehaving code is a lot harder in my experience.
     
  3. Offline

    surtic

    Father Of Time: No sorry... i dont need to know how i make a Command that is also implementet and works! I dont want a Custom Chunk Generator or Populator!

    I only want to know how i can Generate a Chunk whitout a Player wo traveled over the World.
     
  4. Offline

    Father Of Time

    I see, sorry for the misunderstanding. I believe the following will do what you ask:

    Code:
        World world = //your source world
        Chunk targetchunk = world.getChunkAt( X, Z);
        targetchunk.load( true );
    
    This will force load the target chunk at the target location, and if it has never been loaded before cause it to force generate (what the true arguement does).

    I hope this is what you were looking for, good luck!
     
  5. Offline

    surtic

    No Problem :)

    Is
    Code:
    world.loadChunk(x, z, true)
    not the same?

    I think its a other problem :( how works the coordination system from chunks and the normal for the player? ore is it the same? and i must x * 16 for the chunk load ore teleport?

    sorry but i never read about this...

    update: looks like it dosen't work... the chunk loading is really fast and when i teleport in the new world there must generate the chunks.... :(

    Update : Okey since i update du Dev Version the ChunkLoad works.

    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