Skip to content

Create world headless#2251

Open
BoySanic wants to merge 23 commits intoPixelGuys:masterfrom
BoySanic:haedless-create-world
Open

Create world headless#2251
BoySanic wants to merge 23 commits intoPixelGuys:masterfrom
BoySanic:haedless-create-world

Conversation

@BoySanic
Copy link
Contributor

@BoySanic BoySanic commented Nov 10, 2025

Fixes #2250
Allows for creating a world headlessly.

@notcancername notcancername moved this to WIP/not ready for review in PRs to review Nov 11, 2025
@notcancername notcancername moved this from WIP/not ready for review to Easy to Review in PRs to review Nov 13, 2025
@IntegratedQuantum IntegratedQuantum moved this from Easy to Review to In review in PRs to review Nov 13, 2025
@BoySanic
Copy link
Contributor Author

I ended up refactoring the changes from #2136 because they implemented something in save_creation.zig that isn't gui dependent but they made it gui dependent.

It's possible the user can enter a seed in the launchConfig, too. So I moved chooseSeed.

I can make this a separate PR if desired. But, I didn't see why I should hardcode a method of obtaining the seed in headless as a stopgap.

Copy link
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

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

also you got more conflicts

@BoySanic
Copy link
Contributor Author

BoySanic commented Feb 28, 2026

ok this one should be ready to go again

EDIT: Nevermind... Presets. My brain is too melted to figure it out tonight.

@BoySanic
Copy link
Contributor Author

BoySanic commented Mar 1, 2026

Okay! now it's done!

I'm really not sure how I feel about having added createFromZon to WorldSettings, but I didnt see a good way to adapt fromZon to both work for headless servers and for the act of loading the save file. Mostly because of the behavior when providing it an empty seed.

@IntegratedQuantum
Copy link
Member

Maybe we should consider just removing the "no seed" check. After all this is only something that will break when the player manually goes into the file and removes the seed.

@BoySanic
Copy link
Contributor Author

BoySanic commented Mar 1, 2026

Maybe we should consider just removing the "no seed" check. After all this is only something that will break when the player manually goes into the file and removes the seed.

I'd agree with that. I think the code that called fromZon should handle the lack of a seed when necessary.

@BoySanic
Copy link
Contributor Author

BoySanic commented Mar 1, 2026

I've changed fromZon to not return an error, and added error handling in loadWorld instead so we can have it not proceed with loading the world if it discovers the seed is missing.

We could instead give it a new seed to work with, but I think it makes more sense to try to avoid potential corruption.

I also deduplicated the code used in autoEnterWorld on the client and headless for the server.

pub fn exists(worldPath: []const u8) !bool {
const saveDirectory = std.fs.path.join(main.stackAllocator.allocator, &.{"saves", worldPath, "world.zig.zon"}) catch unreachable;
defer main.stackAllocator.free(saveDirectory);
files.cubyzDir().dir.access(saveDirectory, .{}) catch |err| {
Copy link
Member

Choose a reason for hiding this comment

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

Actually you can use cubyzDir().hasFile().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that, but we lose out on providing the user an error, since we don't log it in hasFile or hasDir.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example if there's a filesystem access error, rather than just the file simply not existing, hasDir or hasFile would tell the game to create the world over again. That's potentially dangerous when there's a filesystem issue preventing access, even if it's transient. Because now we'll create a world overtop of an existing one if the issue is resolved between that check and tryCreateWorld starting to write files.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it be reasonable to adjust hasFile and hasDir to return an error.

src/main.zig Outdated
else
null;

const worldExists: ?bool = if (headless or settings.launchConfig.autoEnterWorld.len > 0) server.world_zig.exists(settings.launchConfig.autoEnterWorld) catch |err| {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't need to be a variable, instead it should be handled together with the block above, by printing an error and returning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't handle any errors if I use hasDir or hasFile as they currently exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Create world in headless

4 participants