[SOLVED] World Seeds

Discussion in 'Plugin Development' started by DrAgonmoray, Jul 13, 2011.

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

    DrAgonmoray

    server.getWorld(String name, World.Environment environment, long seed);

    long values are basically long ints, correct? If this takes a long as it's seed, then how does a plugin like MultiVerse let users generate worlds with specific seeds, with seeds like "Glacier" or other seeds with letters in them.

    :|
     
  2. Offline

    Hretsam

    A word is converted to an long.
    I think it uses something like .hashCode().

    And yes a long is a integer with more room (as an int has a max value)
     
  3. Offline

    DrAgonmoray

    I'll look into it, thanks for the quick response.

    I'm not seeing anything on hashCode(). Hmm
     
  4. Offline

    Hretsam

    make a string (or object)
    and just put .hashCode(); behind it
    like
    "DrAgonmoray".hashCode();
     
  5. Offline

    s1mpl3x

  6. Offline

    DrAgonmoray

    How nice. :)

    ..wat
    I was using a seed finder program to check if my seed generator worked.
    Using my plugin, I generated a map using the seed "404"
    I then generated a map in minecraft with the seed "404"
    The seed finder said that my plugin-generated map had a seed of "51512" and that my minecraft-generated map had a seed of "404"
    What gives? o.o
    PHP:
    long seed = (args.length == 3) ? args[2].hashCode() : new Random().nextLong();
    where seed is the seed I use in server.createWorld(), and args[2] is the seed argument taken from a player command. The command goes like this:
    /createworld TYPE NAME SEED
    and I did /createworld normal fake 404

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

    s1mpl3x

    i think the hashCode() is only used if the input isn't castable to long
     
  8. Offline

    DrAgonmoray

    Oh, that makes sense.

    Edit
    @s1mpl3x I'm totally stumped on how to check if it's castable to long. o.o
     
  9. Offline

    s1mpl3x

    Code:
               try {
                    meh = Long.valueOf(args[2]);
                } catch (NumberFormatException e) {
                    meh = args[2].hashCode();
                }
     
  10. Offline

    DrAgonmoray

    ._. I got nearly that exact same thing like 30 seconds before you posted that :( I found the answer here: http://stackoverflow.com/questions/4664350/how-to-check-if-an-object-is-convertible-to-another-type
    Sorry for wasting your time, and thanks for the help lol. Here's what I ended up with
    PHP:
                    long seed = new Random().nextLong();
                    if (
    args.length == 3) {
                        try {
                            
    seed Long.parseLong(args[2]);
                        } catch (
    NumberFormatException nfe) {
                            
    seed args[2].hashCode();
                        }
                    }
     
Thread Status:
Not open for further replies.

Share This Page