Skip to content

Saplings 2: Engine capabilities - #3813

Open
DellieDelta wants to merge 42 commits into
PixelGuys:masterfrom
DellieDelta:saplings
Open

DellieDelta wants to merge 42 commits into
PixelGuys:masterfrom
DellieDelta:saplings

Conversation

@DellieDelta

Copy link
Copy Markdown
Contributor

Continuation of #2585, thanks @tillpp for your good work!

The goal of this PR is only to give the engine the capabilities for saplings. Discussion is still open in #546, so I'll leave the implementation for a follow-up PR. Before merging I'll also remove the sapling item

@Wunka Wunka moved this to Medium Priority in PRs to review Nov 21, 2026
@DellieDelta DellieDelta mentioned this pull request Nov 21, 2026
Comment thread src/callbacks/block/server/_list.zig Resolved
@IntegratedQuantum IntegratedQuantum moved this from Medium Priority to In review in PRs to review Nov 22, 2026
Comment thread src/blueprint.zig Resolved
Comment thread src/blueprint.zig Resolved
Comment thread src/server/world.zig Resolved
}

fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: ?Neighbor, rotation: sbb.Rotation, chunk: *ServerChunk, seed: *u64) void {
pub fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: ?Neighbor, rotation: sbb.Rotation, chunk: *ServerChunk, seed: *u64) void {

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.

Related to the above comment: This should be a separate function for calling it outside of generation.
e.g. outside of generation, the chunk parameter is unused.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I split it into two functions but there's some code repetition that I had a hard time combining. The problem is that almost all variables defined at the start are needed again at the end, and only the function call in the middle that places the blueprint is different. Maybe you have an idea on how to approach this?

@tillpp

tillpp commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

The Reason my saplings PR never got finished, was because of perfomance Issues.

on a flat world, you can select a large rectangle with the wand, and fill it with saplings all at once and then try running around, after a while you will not be able to pick up/drop items anymore etc.

@DellieDelta

Copy link
Copy Markdown
Contributor Author

I talked with Quantum yesterday about the averageSpawnSeconds attribute, a problem with it is that the average spawn time stays the same even if you change the tickspeed, because the current tickspeed is part of the chance calculation.

We both thought that having an attribute like averageTicksInChunkForSpawn would be better instead to fix this, but a problem with it is that it's harder to understand for someone looking at the config. To decide on a value you'd first need to know the amount of updates per second, and the amount of ticks per second, and multiply them together to translate a time to a value.

But at that point you're thinking in time anyway, so I think averageSpawnSeconds is better, if you also pin the tickspeed to the default tickspeed. A nice benefit is that you don't need the current tickspeed anymore at runtime, so you can move all chance calculation to load time.

I was a little worried about ambiguity, because the attribute name doesn't tell you that it's pinned to the default tickspeed. But at the same time, there's already the expectation that changing the tickspeed makes plants grow faster or slower, so I think it's fine. And it's easy enough to figure out by looking at the code

@DellieDelta

DellieDelta commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

The Reason my saplings PR never got finished, was because of perfomance Issues.

on a flat world, you can select a large rectangle with the wand, and fill it with saplings all at once and then try running around, after a while you will not be able to pick up/drop items anymore etc.

From what I saw the issue was with performance spikes, but that got fixed throughout the PR. I tested it, but block dropping/picking up is only a little slower if you make a very big sapling field with a selection wand. So should be fine

@DellieDelta

Copy link
Copy Markdown
Contributor Author

Looks like the network holds up as well with a lower MTU and a very big sapling field, with the maxMtu set to 1500 I get this:

Screenshot_2026-12-03_18-27-06

Sorry for the hard to read text haha

@DellieDelta

Copy link
Copy Markdown
Contributor Author

I implemented what I talked about in #3813 (comment)

Comment thread src/blueprint.zig
};

pub fn paste(self: Blueprint, pos: Vec3i, flags: PasteFlags) void {
pub fn paste(self: Blueprint, pos: Vec3i, flags: PasteFlags, mode: PasteMode) void {

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.

Why not merge the PasteMode into the PasteFlags struct?
If you make it a packed struct, you can also keep the switch case and elevate the entire struct to comptime.

Also in my opinion the name Flags for option structs is kind of misleading, as flags usually only allow bool parameters.

const childRotation = blueprintRotation.getChildRotation(seed, child.rotation, childBlock.direction());
_placeSbb(self, child, pastePosition + childBlock.pos(), childBlock.direction(), childRotation, worldPos, seed);
}
}

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.

Instead of duplicating this function, could this also be a comptime parameter?


result.spawnChancePerBlockTick = averageSecondsPerBlockTick/averageSpawnSeconds;
if (result.spawnChancePerBlockTick > 1) {
std.log.err("spawnChancePerBlockTick is over 100% for spawn_structure event. Increase averageSpawnSeconds to be at least {}", .{averageSecondsPerBlockTick});

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.

That you calculate a chance here is an implementation detail that the addon creator shouldn't need to know about, please reword the error without it.

Instead maybe mention that it's bound by the default tick speed.

};

const tickedBlocksInChunkPerSecond = server.world_zig.defaultTickSpeed*server.updatesPerSec;
const blocksInChunk: f32 = 32*32*32;

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.

Please use the proper constant chunk.chunkVolume here as well.

Comment thread src/blocks.zig
pub fn finishBlockCallbacks(zonElements: Assets.ZonHashMap) void {
var i: u16 = 0;
while (i < size) : (i += 1) {
registerCallbacks(i, zonElements.get(_id[i]) orelse continue);

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.

This is now called twice, once in finishBlocks, once here. Looks like you messed up the rebase after 91fc0e0

This branch has not been deployed

No deployments
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.

3 participants