Client block random ticks - #3396
Draft
RanPix wants to merge 9 commits into
Draft
Conversation
RanPix
marked this pull request as draft
July 19, 2026 21:16
| pub fn updateRandomTickBlocks(_: *World) void { | ||
| const chunkRadius = settings.visualRandomTickRadius; | ||
| const playerBlockPos: Vec3i = @intFromFloat(@floor(Player.getPosBlocking())); | ||
| const thing: i32 = @intCast(if (@mod(chunkRadius, 2) == 0) @divFloor(chunkRadius, 2) else @divFloor(chunkRadius - 1, 2)); |
Member
There was a problem hiding this comment.
It's not a radius if you half it
|
|
||
| if (chunkMesh) |mesh| { | ||
| for (0..20) |_| { | ||
| const curBlockPos = Vec3i{main.random.nextIntBounded(i32, &main.seed, 32), main.random.nextIntBounded(i32, &main.seed, 32), main.random.nextIntBounded(i32, &main.seed, 32)}; |
Member
There was a problem hiding this comment.
You can create a random BlockPos directly from a u15
| const chunkMesh = main.renderer.mesh_storage.getMesh(.initFromWorldPos(chunkMultiplierPos, 1)); | ||
|
|
||
| if (chunkMesh) |mesh| { | ||
| for (0..20) |_| { |
Member
There was a problem hiding this comment.
Should be configurable
| for (0..20) |_| { | ||
| const curBlockPos = Vec3i{main.random.nextIntBounded(i32, &main.seed, 32), main.random.nextIntBounded(i32, &main.seed, 32), main.random.nextIntBounded(i32, &main.seed, 32)}; | ||
| const block = mesh.chunk.getBlock(curBlockPos[0], curBlockPos[1], curBlockPos[2]); | ||
| const onClientUpdate = block.onClientUpdate(); |
Member
There was a problem hiding this comment.
Suggested change
| const onClientUpdate = block.onClientUpdate(); | |
| const onClientUpdate = block.onClientRandomTick(); |
|
|
||
| self.randomTicksTime += deltaTime; | ||
| const tickrate: f32 = 1.0/20.0; | ||
| if (self.randomTicksTime >= tickrate) { |
Member
There was a problem hiding this comment.
To catch lag spikes, this should be a while loop, below it should subtract the tickRate instead of setting it to 0
Suggested change
| if (self.randomTicksTime >= tickrate) { | |
| while (self.randomTicksTime >= tickrate) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP
allows to create random particles like falling leaves and butterflies from flowers, or even sparkles from glowing stone blocks