Fluid rendering in graphics

This commit is contained in:
2026-10-28 11:49:56 -03:00
parent 8fc08ab41e
commit bcd0690ef5
7 changed files with 59 additions and 20 deletions
+8
View File
@@ -9,6 +9,7 @@ import { get_sprite_region } from "$/client/sprites.ts";
import type { ItemEntity } from "$/client/entity/item_entity.ts";
import { contained_fluid, type ItemData, ItemStack } from "$/common/inventory.ts";
import type { FluidVariant } from "$/common/mod_api/shared.ts";
import type { FluidJson } from "$/common/mod_data.ts";
import { light_color, push_vertex, Texture } from "$/client/renderer/mod.ts";
import {
bake_model,
@@ -404,6 +405,13 @@ export function fluid_rgb(fluid: FluidVariant): Vec3 {
return color_rgb(tint_without_biome(fluid_rules.color(fluid) as TintColor));
}
// a fluid's texture and its color by its rules, for drawing it in a box or a slot. throws for a fluid no mod defines
export function fluid_look(fluid: FluidVariant): { texture: string; tint: Vec3 } {
const json = EverythingRegistry.get<FluidJson>("fluids", fluid?.id);
if (!json) throw new Error(`there's no fluid ${fluid?.id}`);
return { texture: json.texture ?? "engine:missing", tint: fluid_rgb(structuredClone(fluid)) };
}
// where a model's uv in pixels (0-16) is in the atlas. the atlas's border around each sprite (see ATLAS_BORDER) keeps
// lookups that round past its edge on its own pixels
export function sprite_u(atlas: Texture, region: SpriteRegion, pixels: number) {