Skip to content

Client block random ticks - #3396

Draft
RanPix wants to merge 9 commits into
PixelGuys:masterfrom
RanPix:torchParticles
Draft

Client block random ticks#3396
RanPix wants to merge 9 commits into
PixelGuys:masterfrom
RanPix:torchParticles

Conversation

@RanPix

@RanPix RanPix commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

WIP

allows to create random particles like falling leaves and butterflies from flowers, or even sparkles from glowing stone blocks

  • adds a setting for random tick simulation radius (the setting is broken currently tho)
  • so far has a callback for torch fire for you to test

@RanPix
RanPix marked this pull request as draft July 19, 2026 21:16
Comment thread src/game.zig
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));

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.

It's not a radius if you half it

Comment thread src/game.zig

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)};

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.

You can create a random BlockPos directly from a u15

Comment thread src/game.zig
const chunkMesh = main.renderer.mesh_storage.getMesh(.initFromWorldPos(chunkMultiplierPos, 1));

if (chunkMesh) |mesh| {
for (0..20) |_| {

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.

Should be configurable

Comment thread src/game.zig
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();

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.

Suggested change
const onClientUpdate = block.onClientUpdate();
const onClientUpdate = block.onClientRandomTick();

Comment thread src/game.zig

self.randomTicksTime += deltaTime;
const tickrate: f32 = 1.0/20.0;
if (self.randomTicksTime >= tickrate) {

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.

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) {

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants