Generate a 2000x2000 default world

Discussion in 'Plugin Development' started by Extremelyd1, Jul 5, 2014.

Thread Status:
Not open for further replies.
  1. Hi,
    At world creation, is it possible to let it generate normal terrain around spawn until it reached a size of 2000x2000, and then generate nothing?
     
  2. Extremelyd1 Well, it's not entirely impossible:
    [​IMG]

    Code:java
    1. package com.droppages.Skepter;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Chunk;
    6. import org.bukkit.Material;
    7. import org.bukkit.World;
    8. import org.bukkit.World.Environment;
    9. import org.bukkit.block.Block;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.world.WorldInitEvent;
    13. import org.bukkit.generator.BlockPopulator;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Main extends JavaPlugin implements Listener {
    17.  
    18. public void onEnable() {
    19. getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. @EventHandler
    23. public void onWorldInit(WorldInitEvent e) {
    24. if (e.getWorld().getEnvironment().equals(Environment.NORMAL))
    25. e.getWorld().getPopulators().add(new LimitedWorldPopulator());
    26. }
    27. }
    28.  
    29. class LimitedWorldPopulator extends BlockPopulator {
    30.  
    31. @Override
    32. public void populate(World world, Random random, Chunk chunk) {
    33. int chunkX = chunk.getX();
    34. int chunkZ = chunk.getZ();
    35.  
    36. for (int x = 0; x < 16; x++) {
    37. for (int z = 0; z < 16; z++) {
    38. int blockX = (chunkX * 16) + x;
    39. int blockZ = (chunkZ * 16) + z;
    40. final int MAX_Y = world.getHighestBlockYAt(blockX, blockZ) + 1;
    41.  
    42. for (int y = 0; y < MAX_Y; y++) {
    43.  
    44. Block block = world.getBlockAt(blockX, y, blockZ);
    45. if(block.getLocation().getBlockX() > 2000 || block.getLocation().getBlockX() < -2000 || block.getLocation().getBlockZ() > 2000 || block.getLocation().getBlockZ() < -2000) {
    46. block.setType(Material.AIR);
    47. }
    48. }
    49. }
    50. }
    51. }
    52. }
    53.  
     
  3. Offline

    RawCode

  4. RawCode Generating the world was lag free - worked normally, but walking over there pretty much crashed my client. After restarting it, everything worked normally.
     
Thread Status:
Not open for further replies.

Share This Page