Is there a way to modify a World's seed?

Discussion in 'Plugin Development' started by imjake9, Jun 10, 2012.

  1. Offline

    imjake9

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I was wondering if there was a way to modify a world's seed. Obviously, this would not effect old chunks, but I only need it to affect new ones.

    I'd like to be able to do this because I'm creating a plugin that will be used for a very specific type of survival minigame server. It will use the standard Minecraft chunk generator, but I've created a BlockPopulator to create a "fenced in" area out of bedrock. The problem is, I want the terrain to change every game, so I think the simplest way would be to change the world's seed and regenerate the chunks. I know that such a method would take a bit of time to do, but that is not a problem in my case.

    Unfortunately, as far as I can tell, Bukkit provides no methods for actually modifying a World's seed. The only method I could think of would be deleting the world and generating a new one, but this causes a lot of problems that seem unnecessary when a simple seed modification would be sufficient.

    Does anyone know if this is possible?
  2. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME

    This post has been edited 1 time. It was last edited by r0306 Jun 10, 2012.
  3. Offline

    imjake9

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  4. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @imjake9
    It might be in the world's metadata. Try searching that up.
  5. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @imjake9 The seed is stored here: https://github.com/Bukkit/CraftBukk...n/java/net/minecraft/server/WorldData.java#L7 - It's private and there doesn't seem to be a setSeed, so you have to use reflections:
    Code:java
    1. World world = theBukkitWorld;
    2. long newSeed = theNewSeed;
    3.  
    4. net.minectaft.server.WorldData data = ((CraftWorld)world).getHandle().worldData;
    5. Field f = data.getClass().getDeclaredField("seed");
    6. f.setAccessible(true);
    7. f.setLong(worldData, newSeed);
    8. f.setAccessible(false);
    9.  
    10. world.save();

    This post has been edited 3 times. It was last edited by V10lator Jun 10, 2012.
  6. Offline

    caldabeast

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Something that has been bothering me, why is that called using reflections?
  7. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  8. Offline

    imjake9

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Aha, that's a clever trick! Thanks a lot!
  9. Offline

    Phoenixfire27

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Sorry to be a noob, but how would i use this code to change the seed? i know little or nothing about programming or the way minecraft is programmed, but i have an issue which can be fixed by changing my server seed. can you help me use this to change it?
  10. Online

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @V10lator wait, you can edit private fields? :confused: What is this sorcery!
  11. Offline

    Cirno

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Suddenly, Bukkit staff decides to troll us and make it final.
  12. Offline

    Icyene

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME

    This post has been edited 1 time. It was last edited by Icyene Jul 23, 2012.
    imjake9 likes this.
  13. Online

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  14. Offline

    Icyene

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Your a hacker, Harry. A hacker...
    iTidez and imjake9 like this.
  15. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Simply copy&paste it? :confused:
    Code:java
    1. World world = theBukkitWorld; //theBukkitWorld is the World object.
    2. long newSeed = theNewSeed; //theNewSeed is the new seed you want to have.
    3.  
    4. net.minectaft.server.WorldData data = ((CraftWorld)world).getHandle().worldData; //Now we get the WorldData (notch code)
    5. Field f = data.getClass().getDeclaredField("seed"); //We get the private field named seed...
    6. f.setAccessible(true); //...set it accessitble so we can modify it...
    7. f.setLong(worldData, newSeed); //...and set the new seed to it.
    8. f.setAccessible(false); //Then we set if non-accessible again.
    9.  
    10. world.save(); //And finally we save the world with he new seed.

    But as other stated bukkit seems to have changed the codes. I didn't look at them but maybe the code won't work anymore.
  16. Offline

    JRArocks

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @V10lator
    Thank you very much! Reflections is awesome!

Share This Page