Regenerate a chunk with a different seed to the rest of the world?

Discussion in 'Plugin Development' started by Techy4198, Dec 18, 2013.

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


    just wondering if this is possible, as I want to make a quick tool which will make each chunk of a world completely random and separate from the rest of the world. to do this I need to know if there is a way to change the seed of a world to something random while storing the original seed, regenerate a chunk, then repeat for all the chunks that have been generated in that world so far, then set the seed back to default afterwards. possible?

    edit: goshdangit. just realised there isn't even a method to get an array/list of all the generated chunks in the world -_- so I guess I'm gonna have to change my command to require a radius in chunks from 0,0...

    edit 2: some hope... found this under ChunkGenerator...
    generate(World world, Random random, int x, int z)
    how do check if a chunk exists? is it just if(chunk != null) ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 5, 2016
  2. Offline


    you can test your code self without any problems, why asking?

    regenerating chunks with arbitrary seed impossible without NMS.
  3. Offline


    RawCode I'm asking because I have loads of plugins on my server and it takes ages to reload it each time I modify a few numbers. I never said I wanted to do it without nms...
  4. Offline


    you can setup testing server without lots of plugins to test your code...

    to generate chunk with different seed you need to:

    lock main thread, lock world object and halt worldgeneration and chunkloading, in other case some chunks inside different threads will generate with wrong seed or fail to generate
    change world seed
    regenerate chunk
    change world seed back

    also you can write your own implementation of chunkprovider.

    on my server, i generate chunk at remote random coordinates and copy it to selected location, this will provide valid chunk for current seed by different location
  5. Offline



    any code examples? I have no idea how to change the world seed (which I did mention) or how to lock threads...

    edit: actually, how about you show me your 'moving chunks around' code?
  6. Offline


    standby i will post both methods a bit later

    This is tested on 172 bukkit code that allow to regenerate any given chunk with any given seed, dev version.

    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
    3. {
    4. //First, we extract our data from chat event
    5. //we want X and Z and seed
    6. System.out.println("TT");
    7. String[] data = event.getMessage().split(" ");
    9. //filter invalid input and NPE
    10. if (data == null) return;
    11. if (data.length == 0) return;
    12. //if (data.length != 2) return;
    13. System.out.println(data.length);
    14. //bulkcheck params
    15. try{
    16. Integer.parseInt(data[0]);
    17. Integer.parseInt(data[1]);
    18. Long.parseLong(data[2]);
    19. }catch(Throwable t){return;}
    20. System.out.println("TT3");
    21. //will work for overworld only
    23. CraftWorld w = (CraftWorld) Bukkit.getServer().getWorlds().get(0);
    25. WorldServer ws = w.getHandle();
    27. WorldData wd = ws.worldData;
    29. long seeda = -1l;
    30. Field f = null;
    32. try{
    33. f = wd.getClass().getDeclaredField("seed");
    34. f.setAccessible(true);
    35. seeda = f.getLong(wd);
    36. System.out.println("TT5");
    37. }catch(Throwable t){t.printStackTrace();}
    38. System.out.println("TT6");
    39. synchronized(w)
    40. {
    41. try{
    42. f.setLong(wd, Long.parseLong(data[2]));
    43. w.regenerateChunk(Integer.parseInt(data[0]), Integer.parseInt(data[1]));
    44. f.setLong(wd, seeda);
    45. System.out.println("REGEN");
    46. }catch(Throwable t){t.printStackTrace();}
    47. }
    49. }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 5, 2016
  7. Offline


    ok I used that (modified a bit), but it doesn't seem to change the seed. it does, however, make structures and trees generate all cut-off. perhaps I'm regenerating the chunks in the wrong order?

    RawCode seems to go very slowly now... something to do with the synchronized(w) line... what exactly does that do?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 5, 2016
  8. Offline


    it does not change seed, it regenerate chunk for seed you given.
  9. Offline


    RawCode I mean I am inputting a completely random seed for each chunk but it still just generates the same.

    also you haven't answered my question about the synchronized(w) line

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 5, 2016
  10. Offline


    if you want completely new chunks, additional step - replacing ChunkProviderGenerate required (it store noise map and biome table pregenerated by world seed).

    just like replacing seed, store old chunk provider, create and set new, then change back.

    sync block here does not allow other threads to change worldobject (atleast expected to do so)
  11. Offline


    1. the sync thing makes my server grind to a complete halt after performing on anything over 20 chunks...
    2. why do you change the seed of the chunk back anyway?
    3. I did say originally that I want completely new chunks...
    4. what code do I need to use to replace the chunkprovider thingy?
  12. Offline


    i did exactly what you asked, cant understand why you asking me about why i restore seed back when you asked for it.
  13. Offline


    RawCode sorry about the restoring seed thing, I was half asleep when I typed the op. can u possibly also answer my other 3 points?
  14. Offline


    sync block added just in case, to not allow other chunks to generate before seed is set back.

    a bit improved code:

    long seeda = new Random().nextLong();
    CraftWorld w = (CraftWorld) Bukkit.getServer().getWorlds().get(0);
    WorldServer ws = w.getHandle();
    WorldData wd = ws.worldData;
    Field f = wd.getClass().getDeclaredField("seed");
    f.setLong(wd, seeda);
    ChunkProviderServer tx = (ChunkProviderServer) ws.chunkProvider;
    tx.chunkProvider = new NormalChunkGenerator(ws, seeda);
    It failed to change chunks that generated outside initial spawn area for no reason, can't debug without mcp for 172 soo i can't tell why it failed, you can play with it a bit.
  15. Offline


    RawCode that looks like only half the code.
  16. Offline


    i removed sync block and exception handling, this code inside chunkpopulateevent will cause map generation to be a bit "chunky" but wont reset biome map.
Thread Status:
Not open for further replies.

Share This Page