proper fluid flow

This commit is contained in:
2025-09-27 18:11:12 +02:00
parent 3b97c86d5a
commit eb942371cd
2 changed files with 30 additions and 15 deletions

View File

@@ -34,8 +34,8 @@
// Max render distance, determines how many chunks to send
#define VIEW_DISTANCE 2
// Time between server ticks in microseconds (default = 1s)
#define TIME_BETWEEN_TICKS 1000000
// Time between server ticks in microseconds (default = 0.05s)
#define TIME_BETWEEN_TICKS 50000
// Calculated from TIME_BETWEEN_TICKS
#define TICKS_PER_SECOND ((float)1000000 / TIME_BETWEEN_TICKS)

View File

@@ -1037,6 +1037,20 @@ void handleFluidMovement (short x, uint8_t y, short z, uint8_t fluid, uint8_t bl
// a higher fluid "level" means the fluid has traveled farther
uint8_t level = block - fluid;
uint8_t flow_speed;
uint8_t max_level;
switch (fluid) {
case B_lava:
flow_speed = 30;
max_level = 3;
break;
case B_water:
flow_speed = 5;
max_level = 7;
break;
}
// Query blocks adjacent to this fluid stream
uint8_t adjacent[4] = {
getBlockAt(x + 1, y, z),
@@ -1058,10 +1072,10 @@ void handleFluidMovement (short x, uint8_t y, short z, uint8_t fluid, uint8_t bl
// If not connected, clear this block and recalculate surrounding flow
if (!connected) {
makeBlockChange(x, y, z, B_air);
checkFluidUpdate(x + 1, y, z, adjacent[0]);
checkFluidUpdate(x - 1, y, z, adjacent[1]);
checkFluidUpdate(x, y, z + 1, adjacent[2]);
checkFluidUpdate(x, y, z - 1, adjacent[3]);
deferBlockUpdate(x + 1, y, z, flow_speed);
deferBlockUpdate(x - 1, y, z, flow_speed);
deferBlockUpdate(x, y, z + 1, flow_speed);
deferBlockUpdate(x, y, z - 1, flow_speed);
return;
}
}
@@ -1070,29 +1084,29 @@ void handleFluidMovement (short x, uint8_t y, short z, uint8_t fluid, uint8_t bl
uint8_t block_below = getBlockAt(x, y - 1, z);
if (isReplaceableBlock(block_below)) {
makeBlockChange(x, y - 1, z, fluid);
return handleFluidMovement(x, y - 1, z, fluid, fluid);
deferBlockUpdate(x, y - 1, z, flow_speed);
return;
}
// Stop flowing laterally at the maximum level
if (level == 3 && fluid == B_lava) return;
if (level == 7) return;
if (level == max_level) return;
// Handle lateral water flow, increasing level by 1
if (isReplaceableFluid(adjacent[0], level, fluid)) {
makeBlockChange(x + 1, y, z, block + 1);
handleFluidMovement(x + 1, y, z, fluid, block + 1);
deferBlockUpdate(x + 1, y, z, flow_speed);
}
if (isReplaceableFluid(adjacent[1], level, fluid)) {
makeBlockChange(x - 1, y, z, block + 1);
handleFluidMovement(x - 1, y, z, fluid, block + 1);
deferBlockUpdate(x - 1, y, z, flow_speed);
}
if (isReplaceableFluid(adjacent[2], level, fluid)) {
makeBlockChange(x, y, z + 1, block + 1);
handleFluidMovement(x, y, z + 1, fluid, block + 1);
deferBlockUpdate(x, y, z + 1, flow_speed);
}
if (isReplaceableFluid(adjacent[3], level, fluid)) {
makeBlockChange(x, y, z - 1, block + 1);
handleFluidMovement(x, y, z - 1, fluid, block + 1);
deferBlockUpdate(x, y, z - 1, flow_speed);
}
}
@@ -1156,8 +1170,9 @@ void processBlockUpdate (short x, uint8_t y, short z, uint8_t block) {
makeBlockChange(x, y, z, 0);
makeBlockChange(x, y - 1, z, 0);
makeBlockChange(x, y - 1, z, block);
// update this (now moved) block and the block above next tick
deferBlockUpdate(x, y - 1, z, 0);
// update this now moved block at the sand fall speed
deferBlockUpdate(x, y - 1, z, 15);
// update the block above next tick
deferBlockUpdate(x, y + 1, z, 0);
}
}