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

    Techy4198

    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...
    Code:
    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

    RawCode

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

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

    Techy4198

    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

    RawCode

    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

    Techy4198

    Bump

    RawCode...
    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

    RawCode

    Techy4198
    standby i will post both methods a bit later

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

    Code:java
    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(" ");
    8.  
    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
    22.  
    23. CraftWorld w = (CraftWorld) Bukkit.getServer().getWorlds().get(0);
    24.  
    25. WorldServer ws = w.getHandle();
    26.  
    27. WorldData wd = ws.worldData;
    28.  
    29. long seeda = -1l;
    30. Field f = null;
    31.  
    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. }
    48.  
    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

    Techy4198

    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

    RawCode

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

    Techy4198

    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

    RawCode

    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

    Techy4198

    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

    RawCode

    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

    Techy4198

    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

    RawCode

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

    a bit improved code:

    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.setAccessible(true);
    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

    Techy4198

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

    RawCode

    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