Water flowing
This commit is contained in:
@@ -153,14 +153,46 @@ export interface BlockRegistry {
|
||||
// draws the item a server script gives it (ServerWorld.set_block_item) on top of it, like farmer's delight's
|
||||
// cutting board. surface is the height in pixels it lies on. turned with the variant's y
|
||||
item_display?: { surface: number };
|
||||
// a liquid like water, drawn like luanti's: its top slopes down towards where it flows. see LiquidProperties
|
||||
liquid?: LiquidProperties;
|
||||
|
||||
compiled_states?: CompiledStateDefinition[];
|
||||
}
|
||||
|
||||
// water, and any other block entities pass through and players can place into. what entities swim in, and where
|
||||
// falling doesn't hurt
|
||||
// a liquid's "level" state is 0 for a source, the full block, and 1 to range as it flows away from one, each lower,
|
||||
// like minecraft's. liquids get that state without listing it. their textures are one texture, or { still, flowing }:
|
||||
// still on the top and bottom, flowing on the sides, like luanti's special tiles
|
||||
export interface LiquidProperties {
|
||||
// how many blocks it flows from a source, 1 to 7, like luanti's liquid_range
|
||||
range: number;
|
||||
// ticks between each step it flows, like minecraft's 5 for water and 30 for lava
|
||||
ticks: number;
|
||||
// a spot with two sources beside it and something solid or a source under it becomes a source, like minecraft's
|
||||
// infinite water and luanti's liquid_renewable
|
||||
renewable: boolean;
|
||||
}
|
||||
|
||||
export const LIQUID_LEVEL: BlockStateDefinition = { name: "level", bits: 3, default: 0 };
|
||||
export const MAX_LIQUID_RANGE = 7;
|
||||
// what a liquid that doesn't say has
|
||||
export const LIQUID_DEFAULTS: LiquidProperties = { range: MAX_LIQUID_RANGE, ticks: 5, renewable: true };
|
||||
|
||||
// what entities swim in, and where falling doesn't hurt
|
||||
export function is_liquid_block(block: BlockRegistry | undefined): boolean {
|
||||
return block !== undefined && !block.has_collision && block.replaceable === true;
|
||||
return block?.liquid !== undefined;
|
||||
}
|
||||
|
||||
// a liquid's textures as the top, bottom and sides of a cube, for its item and its particles
|
||||
export function liquid_textures(textures: BlockTextures): { still: string; flowing: string } {
|
||||
if (typeof textures === "string") return { still: textures, flowing: textures };
|
||||
const still = textures.still ?? "engine:missing";
|
||||
return { still, flowing: textures.flowing ?? still };
|
||||
}
|
||||
|
||||
// how high a liquid's surface is in a block of it at this level, 0 to 1, like luanti's flowing levels
|
||||
export function liquid_height(level: number, range: number) {
|
||||
if (level === 0) return 1;
|
||||
return (range - Math.min(level, range) + 0.5) / range;
|
||||
}
|
||||
|
||||
// what a tool is made of, like minecraft's ToolMaterial
|
||||
|
||||
Reference in New Issue
Block a user