-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed config seed #516
base: main
Are you sure you want to change the base?
Fixed config seed #516
Conversation
feather/server/src/main.rs
Outdated
@@ -64,7 +70,11 @@ fn init_world_source(game: &mut Game, config: &Config) { | |||
// world otherwise. This is a placeholder: | |||
// we don't have proper world generation yet. | |||
|
|||
let seed = 42; // FIXME: load from the level file | |||
let seed = config.world.seed.parse().unwrap_or_else(|_| { | |||
let mut hasher = DefaultHasher::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use the following hash algorithm s[0]*31^(n-1) + s[1]*31^(n-2) + … + s[n-1]
which is javas String.hashCode()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my implementation from #487: https://github.com/Iaiao/feather/blob/210fed57a4f54681c35d9d49956b1ced8f78c8fb/feather/server/src/main.rs#L95-L101
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my implementation from #487: https://github.com/Iaiao/feather/blob/210fed57a4f54681c35d9d49956b1ced8f78c8fb/feather/server/src/main.rs#L95-L101
Wouldn't it be useless for me to continue if you have already implemented this feature in your own fork?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a few tests, to make sure that the code behave as javas String.hashCode()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my implementation from #487: https://github.com/Iaiao/feather/blob/210fed57a4f54681c35d9d49956b1ced8f78c8fb/feather/server/src/main.rs#L95-L101
Wouldn't it be useless for me to continue if you have already implemented this feature in your own fork?
My implementation doesn't have any tests and won't be merged soon (because it requires all vanilla commands to be implemented), so I think it wouldn't be useless to implement it in a separate pr.
@@ -364,6 +364,18 @@ impl BiomeGenerator for StaticBiomeGenerator { | |||
} | |||
} | |||
|
|||
pub fn seed_from_string(s: &str) -> u64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should maybe be an i64, such that negative seeds also work as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere in feather seeds are defined by u64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it should be parsed as i64
and then cast to u64
. I thin that's how vanilla Minecraft works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be i64
everywhere and only be casted when passing it to RNGs, it would be more convenient for feather or plugin developers who expect -104019040
seed to be negative, and for end users that expect /seed (or seed value in logs / crash reports) to be the same as in config.toml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the above comment, @ELginas do you want to make this change or should I merge this? We can then create a new issue to change the seed type from u64
to i64
.
TITLE - Replace
Status
Description
Removed hardcoded seed in main.rs and replaced it with seed from config file.
Related issues
Leave empty if none
Checklist
cargo fmt
,cargo clippy --all-targets
,cargo build --release
andcargo test
and fixed any generated errors!Note: if you locally don't get any errors, but GitHub Actions fails (especially at
clippy
) you might want to check your rust toolchain version. You can then feel free to fix these warnings/errors in your PR.