# Small logic error in Grid.IsVisiblyInLiquid

• Branch: Live Branch Version: Windows Pending

Context

Making a mod that causes items to float in liquid. Just thought you could use a heads up on this logic error.

Note: Just want to be extra clear that this is a bug with the vanilla game, not a mod.

Bug

It's very minor but potentially difficult to find. The issue is with Grid.IsVisiblyInLiquid - at least in the disassembly, we have this snippet if the cell above is not a liquid:

float num2 = Mass[num];
float num3 = (float)(int)pos.y - pos.y;
if (num2 / 1000f <= num3)
{
return true;
}

The problem is when taking the precision out of pos, we're left with a negative number, so this condition becomes impossible to fulfill. I think the purpose of this was to check how much of a fraction the mass of the tile was liquid, and return true if it is below that fraction.

Illustration:

pos.y = 58.918

(float)(int)pos.y - pos.y = (float)(int)58.918 - 58.918 = 58 - 58.918 = -0.918

Sample values logged through a copy of this function in gravity simulation:

y: 178.823, num3: -0.823
y: 173.825, num3: -0.825
y: 173.930, num3: -0.930
y: 173.884, num3: -0.884
y: 173.885, num3: -0.885
y: 230.935, num3: -0.935
y: 173.824, num3: -0.824
y: 58.918, num3: -0.918

Fix

I believe the ideal logic would be

float num3 = pos.y - Mathf.Floor(pos.y);

EDIT: After testing, the comparison should be negated, it should be greater than, not less than or equals, since we want to see if the quantity of water is greater than the position we're checking.

Steps to Reproduce
Call Grid.IsVisiblyInLiquid with debug log line.

Status: Pending

This issue has not been confirmed by a developer yet.

Report Bug

## User Feedback

There are no comments to display.