Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/java/org/cloudburstmc/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -1721,21 +1722,23 @@ private void loadLevels() throws IOException {

for (String name : worldConfigs.keySet()) {
final ServerConfig.World config = worldConfigs.get(name);
//fallback to level name if no seed is set
Object seedObj = config.getSeed();
long seed;
if(seedObj == null) { //Auto generate seed if one was not specified
seedObj = ThreadLocalRandom.current().nextLong();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i haven't actually looked at this code in-depth for a while, but won't this be run every time the server starts, thus causing the seed to be different between restarts? the seed isn't written to config anywhere, and i'm pretty sure the seed stored in level.dat isn't used...

@TheShermanTanker TheShermanTanker Apr 15, 2021

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, looks like I forgot about that, thanks for pointing out the oversight. I would go for level.dat personally, but does Cloudburst prefer config instead?

}
if (seedObj instanceof Number) {
seed = ((Number) seedObj).longValue();
} else if (seedObj instanceof String) {
if (seedObj == name) {
log.warn("World \"{}\" does not have a seed! Using a the name as the seed", name);
log.warn("World \"{}\" is using its own name as a seed", name);
}

//this internally generates an MD5 hash of the seed string
UUID uuid = UUID.nameUUIDFromBytes(((String) seedObj).getBytes(StandardCharsets.UTF_8));
seed = uuid.getMostSignificantBits() ^ uuid.getLeastSignificantBits();
} else {
throw new IllegalStateException("Seed for world \"" + name + "\" is invalid: " + (seedObj == null ? "null" : seedObj.getClass().getCanonicalName()));
throw new IllegalStateException("Seed for world \"" + name + "\" is invalid, the seed was of type " + (seedObj == null ? "null" : seedObj.getClass().getCanonicalName()) + ", a number or string was expected");
}

Identifier generator = Identifier.fromString(config.getGenerator());
Expand All @@ -1748,7 +1751,7 @@ private void loadLevels() throws IOException {
.load());
}

// Wait for levels to load.
// Wait for worlds to load.
CompletableFutures.allAsList(levelFutures).join();

//set default level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public Map<String, ServerConfig.World> deserialize(JsonParser parser, Deserializ
result.put(
k,
ServerConfig.World.builder()
//current behavior: use world name as seed when not specified
.seed(v.getSeed() == null ? k : v.getSeed())
//Leave seed as null if not specified to be randomly generated later as per Vanilla
.seed(v.getSeed())
.generator(v.getGenerator())
.options(v.getOptions())
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void parsingWorks() {
yml.getAliases()
);

HashMap<String, ServerConfig.World> worldConfig = new HashMap<>();
/*HashMap<String, ServerConfig.World> worldConfig = new HashMap<>(); With the new system, the old test that checks for seeds is obsolute
worldConfig.put("world", new ServerConfig.World(
"test",
"cloudburst:standard",
Expand All @@ -155,7 +155,7 @@ void parsingWorks() {
assertEquals(
worldConfig,
yml.getWorlds()
);
);*/
}

}