Rename all "liquid" mentions to "fluid"
This commit is contained in:
@@ -12,7 +12,7 @@ import type { BlockRegistry } from "$/common/everything_registry.ts";
|
||||
import type { ItemStack } from "$/common/inventory.ts";
|
||||
import type { Shape } from "$/common/block_shapes.ts";
|
||||
import type { Season } from "$/common/worldgen/biomes.ts";
|
||||
import { type Collisions, type LiquidInCell, physics } from "$/common/physics.ts";
|
||||
import { type Collisions, type FluidInCell, physics } from "$/common/physics.ts";
|
||||
import type { EntityData, EntityEvent, EntityInfo } from "$/common/protocol.ts";
|
||||
import type { ServerPlayer } from "../player.ts";
|
||||
|
||||
@@ -70,9 +70,9 @@ export interface EntityLevel {
|
||||
// what it bumps into at a block, see common/physics.ts
|
||||
collision_shape(x: number, y: number, z: number): boolean | Shape;
|
||||
// water, and other blocks you're in instead of on
|
||||
is_liquid(x: number, y: number, z: number): boolean;
|
||||
// the liquid there and how high it is, for liquids pushing things along
|
||||
liquid_at(x: number, y: number, z: number): LiquidInCell | undefined;
|
||||
is_fluid(x: number, y: number, z: number): boolean;
|
||||
// the fluid there and how high it is, for fluids pushing things along
|
||||
fluid_at(x: number, y: number, z: number): FluidInCell | undefined;
|
||||
get_block_info(x: number, y: number, z: number): BlockRegistry | undefined;
|
||||
// the column's biome, like "bworld:plains"
|
||||
biome_at(x: number, z: number): string;
|
||||
@@ -241,10 +241,10 @@ export abstract class Entity {
|
||||
this.fall_distance = 0;
|
||||
this.fire = 0;
|
||||
}
|
||||
if (this.pushed_by_liquid) {
|
||||
physics.push_by_liquid(
|
||||
if (this.pushed_by_fluid) {
|
||||
physics.push_by_fluid(
|
||||
this,
|
||||
(x, y, z) => this.level.liquid_at(x, y, z),
|
||||
(x, y, z) => this.level.fluid_at(x, y, z),
|
||||
(x, y, z) => this.level.collision_shape(x, y, z),
|
||||
false,
|
||||
);
|
||||
@@ -266,18 +266,18 @@ export abstract class Entity {
|
||||
}
|
||||
}
|
||||
|
||||
// flowing liquid pushes it along, like minecraft's isPushedByFluid
|
||||
get pushed_by_liquid() {
|
||||
// flowing fluid pushes it along, like minecraft's isPushedByFluid
|
||||
get pushed_by_fluid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
update_in_water() {
|
||||
this.in_water = physics.in_water(this, (x, y, z) => this.level.is_liquid(x, y, z));
|
||||
this.in_water = physics.in_water(this, (x, y, z) => this.level.is_fluid(x, y, z));
|
||||
}
|
||||
|
||||
// its eyes are in water, so it can't breathe
|
||||
get eyes_in_water() {
|
||||
return physics.eyes_in_water(this, this.eye_height, (x, y, z) => this.level.is_liquid(x, y, z));
|
||||
return physics.eyes_in_water(this, this.eye_height, (x, y, z) => this.level.is_fluid(x, y, z));
|
||||
}
|
||||
|
||||
// falls and moves by its velocity for one tick (see move_body), and counts how far it fell. returns what it hit
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// when those move or change, and forgets them when they leave it
|
||||
import { CHUNK_SIZE } from "$/common/constants.ts";
|
||||
import { is_within_view } from "$/common/chunk_streaming.ts";
|
||||
import { liquid_block, liquid_in_cell } from "$/common/utils.ts";
|
||||
import { fluid_block, fluid_in_cell } from "$/common/utils.ts";
|
||||
import { biome_season } from "$/common/worldgen/biomes.ts";
|
||||
import type { ItemStack } from "$/common/inventory.ts";
|
||||
import type { EntityEvent, EntityInfo, ServerMessage } from "$/common/protocol.ts";
|
||||
@@ -99,9 +99,9 @@ export class EntityManager implements EntityLevel {
|
||||
return this.#host.world.collision_shape(x, y, z);
|
||||
}
|
||||
|
||||
is_liquid(x: number, y: number, z: number) {
|
||||
is_fluid(x: number, y: number, z: number) {
|
||||
const world = this.#host.world;
|
||||
return liquid_block(world.get_block_value(x, y, z), world.get_block_info(x, y, z)) !== undefined;
|
||||
return fluid_block(world.get_block_value(x, y, z), world.get_block_info(x, y, z)) !== undefined;
|
||||
}
|
||||
|
||||
get_block_info(x: number, y: number, z: number) {
|
||||
@@ -116,9 +116,9 @@ export class EntityManager implements EntityLevel {
|
||||
return biome_season(this.biome_at(x, z), this.#host.world.time);
|
||||
}
|
||||
|
||||
liquid_at(x: number, y: number, z: number) {
|
||||
fluid_at(x: number, y: number, z: number) {
|
||||
const world = this.#host.world;
|
||||
return liquid_in_cell(world.get_block_value(x, y, z), world.get_block_info(x, y, z));
|
||||
return fluid_in_cell(world.get_block_value(x, y, z), world.get_block_info(x, y, z));
|
||||
}
|
||||
|
||||
nearest_player(x: number, y: number, z: number, max_distance: number): ServerPlayer | undefined {
|
||||
|
||||
@@ -363,7 +363,7 @@ function is_alive(target: LivingEntity) {
|
||||
// undefined when the tries all fail
|
||||
export function random_stand_position(mob: Mob, range: number, vertical: number, tries = 10) {
|
||||
const level = mob.level;
|
||||
const free = (x: number, y: number, z: number) => !level.has_collision(x, y, z) && !level.is_liquid(x, y, z);
|
||||
const free = (x: number, y: number, z: number) => !level.has_collision(x, y, z) && !level.is_fluid(x, y, z);
|
||||
for (let i = 0; i < tries; i++) {
|
||||
const x = Math.floor(mob.x + (mob.random() * 2 - 1) * range);
|
||||
const z = Math.floor(mob.z + (mob.random() * 2 - 1) * range);
|
||||
|
||||
@@ -89,7 +89,7 @@ export class ItemEntity extends Entity {
|
||||
// like minecraft's ItemEntity.tick, gravity goes on its speed before it moves, not along the way like
|
||||
// move_body's. the floating numbers are made for that: an item bobbing up out of the water drops straight back
|
||||
// in, instead of hanging above it a tick longer and falling twice as fast
|
||||
if (physics.liquid_depth(this, (x, y, z) => level.liquid_at(x, y, z)) > FLOAT_DEPTH) {
|
||||
if (physics.fluid_depth(this, (x, y, z) => level.fluid_at(x, y, z)) > FLOAT_DEPTH) {
|
||||
this.vx *= WATER_DRAG;
|
||||
this.vz *= WATER_DRAG;
|
||||
if (this.vy < FLOAT_SPEED) this.vy += FLOAT_ACCELERATION;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// liquids flowing, like minecraft's FlowingFluid: a change next to a liquid gets the cells around it looked at again
|
||||
// after the liquid's ticks, and each works out what it should be from its neighbors (see next_level). that changes
|
||||
// fluids flowing, like minecraft's FlowingFluid: a change next to a fluid gets the cells around it looked at again
|
||||
// after the fluid's ticks, and each works out what it should be from its neighbors (see next_level). that changes
|
||||
// more cells, and so it spreads one block a step, and drains away the same way once its source is gone
|
||||
import { AIR, CHUNK_HEIGHT, ID_MASK } from "$/common/constants.ts";
|
||||
import type { BlockRegistry } from "$/common/everything_registry.ts";
|
||||
import { AIR_ID } from "$/common/protocol.ts";
|
||||
import { get_state_value, liquid_block, set_state_value } from "$/common/utils.ts";
|
||||
import { fluid_block, get_state_value, set_state_value } from "$/common/utils.ts";
|
||||
|
||||
// what the flow needs of the world
|
||||
export interface LiquidWorld {
|
||||
// undefined where the chunk isn't loaded, so liquid stops at the edge of the world instead of making new chunks
|
||||
export interface FluidWorld {
|
||||
// undefined where the chunk isn't loaded, so fluid stops at the edge of the world instead of making new chunks
|
||||
value_at(x: number, y: number, z: number): number | undefined;
|
||||
// by numeric id
|
||||
block(nid: number): BlockRegistry | undefined;
|
||||
@@ -26,8 +26,8 @@ const MAX_PER_TICK = 4096;
|
||||
const HORIZONTAL = [[1, 0], [-1, 0], [0, 1], [0, -1]];
|
||||
const NEIGHBORS = [[0, 0, 0], [0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0], [0, 0, 1], [0, 0, -1]];
|
||||
|
||||
// a liquid in a cell: which, and its level
|
||||
interface Liquid {
|
||||
// a fluid in a cell: which, and its level
|
||||
interface Fluid {
|
||||
nid: number;
|
||||
block: BlockRegistry;
|
||||
level: number;
|
||||
@@ -35,12 +35,12 @@ interface Liquid {
|
||||
|
||||
const key = (x: number, y: number, z: number) => `${x},${y},${z}`;
|
||||
|
||||
export class LiquidFlow {
|
||||
#world: LiquidWorld;
|
||||
export class FluidFlow {
|
||||
#world: FluidWorld;
|
||||
// cells to look at, by key, with the tick they're due
|
||||
#due = new Map<string, { x: number; y: number; z: number; tick: number }>();
|
||||
|
||||
constructor(world: LiquidWorld) {
|
||||
constructor(world: FluidWorld) {
|
||||
this.#world = world;
|
||||
}
|
||||
|
||||
@@ -49,13 +49,13 @@ export class LiquidFlow {
|
||||
return this.#due.size;
|
||||
}
|
||||
|
||||
// a block changed at x y z: if there's liquid there or beside it, it and its neighbors are looked at again after
|
||||
// that liquid's ticks
|
||||
// a block changed at x y z: if there's fluid there or beside it, it and its neighbors are looked at again after
|
||||
// that fluid's ticks
|
||||
changed(x: number, y: number, z: number, now: number) {
|
||||
let ticks = Infinity;
|
||||
for (const [dx, dy, dz] of NEIGHBORS) {
|
||||
const liquid = this.#liquid(x + dx, y + dy, z + dz);
|
||||
if (liquid) ticks = Math.min(ticks, liquid.block.liquid!.ticks);
|
||||
const fluid = this.#fluid(x + dx, y + dy, z + dz);
|
||||
if (fluid) ticks = Math.min(ticks, fluid.block.fluid!.ticks);
|
||||
}
|
||||
if (ticks === Infinity) return;
|
||||
for (const [dx, dy, dz] of NEIGHBORS) {
|
||||
@@ -82,28 +82,28 @@ export class LiquidFlow {
|
||||
const value = this.#world.value_at(x, y, z);
|
||||
if (value === undefined) return;
|
||||
const nid = value & ID_MASK;
|
||||
const here = this.#liquid(x, y, z);
|
||||
const here = this.#fluid(x, y, z);
|
||||
if (here?.level === 0) return;
|
||||
// only air and the liquid's own flowing cells are flowed into
|
||||
// only air and the fluid's own flowing cells are flowed into
|
||||
if (!here && nid !== AIR) return;
|
||||
|
||||
// the liquid that would be here: what's here, or one from above or beside
|
||||
const candidates = here ? [here] : this.#liquids_around(x, y, z);
|
||||
for (const liquid of candidates) {
|
||||
const level = this.next_level(liquid, x, y, z);
|
||||
// the fluid that would be here: what's here, or one from above or beside
|
||||
const candidates = here ? [here] : this.#fluids_around(x, y, z);
|
||||
for (const fluid of candidates) {
|
||||
const level = this.next_level(fluid, x, y, z);
|
||||
if (level === undefined) continue;
|
||||
if (!here || here.level !== level) this.#set(liquid.block, x, y, z, level);
|
||||
if (!here || here.level !== level) this.#set(fluid.block, x, y, z, level);
|
||||
return;
|
||||
}
|
||||
if (here) this.#world.set_block(x, y, z, AIR_ID, 0);
|
||||
}
|
||||
|
||||
// what level the liquid would be at x y z, from the cells around it, or undefined for none there
|
||||
next_level(liquid: Liquid, x: number, y: number, z: number): number | undefined {
|
||||
const props = liquid.block.liquid!;
|
||||
// what level the fluid would be at x y z, from the cells around it, or undefined for none there
|
||||
next_level(fluid: Fluid, x: number, y: number, z: number): number | undefined {
|
||||
const props = fluid.block.fluid!;
|
||||
const same = (cx: number, cy: number, cz: number) => {
|
||||
const other = this.#liquid(cx, cy, cz);
|
||||
return other?.nid === liquid.nid ? other : undefined;
|
||||
const other = this.#fluid(cx, cy, cz);
|
||||
return other?.nid === fluid.nid ? other : undefined;
|
||||
};
|
||||
|
||||
// two sources beside it over something solid or a source make another, like minecraft's infinite water
|
||||
@@ -114,7 +114,7 @@ export class LiquidFlow {
|
||||
if (sources >= 2 && (below_block?.has_collision || same(x, y - 1, z)?.level === 0)) return 0;
|
||||
}
|
||||
|
||||
// falling, with more of it above. it's drawn full whatever its level, see liquid_mesh.ts
|
||||
// falling, with more of it above. it's drawn full whatever its level, see fluid_mesh.ts
|
||||
if (same(x, y + 1, z)) return 1;
|
||||
|
||||
let lowest = Infinity;
|
||||
@@ -123,7 +123,7 @@ export class LiquidFlow {
|
||||
const nz = z + dz;
|
||||
const neighbor = same(nx, y, nz);
|
||||
if (!neighbor || !this.#spreads_sideways(neighbor, nx, y, nz)) continue;
|
||||
// falling liquid spreads like a source once it lands
|
||||
// falling fluid spreads like a source once it lands
|
||||
const level = same(nx, y + 1, nz) ? 0 : neighbor.level;
|
||||
lowest = Math.min(lowest, level);
|
||||
}
|
||||
@@ -131,36 +131,36 @@ export class LiquidFlow {
|
||||
return level <= props.range ? level : undefined;
|
||||
}
|
||||
|
||||
// sources spread sideways, and flowing liquid that can't fall any further. over air or more of itself it falls
|
||||
// sources spread sideways, and flowing fluid that can't fall any further. over air or more of itself it falls
|
||||
// instead, like minecraft's isWaterHole
|
||||
#spreads_sideways(liquid: Liquid, x: number, y: number, z: number) {
|
||||
if (liquid.level === 0) return true;
|
||||
#spreads_sideways(fluid: Fluid, x: number, y: number, z: number) {
|
||||
if (fluid.level === 0) return true;
|
||||
const below = this.#world.value_at(x, y - 1, z);
|
||||
if (below === undefined) return false;
|
||||
const nid = below & ID_MASK;
|
||||
return nid !== AIR && nid !== liquid.nid;
|
||||
return nid !== AIR && nid !== fluid.nid;
|
||||
}
|
||||
|
||||
// the liquids above and beside x y z that could flow into it, above first
|
||||
#liquids_around(x: number, y: number, z: number): Liquid[] {
|
||||
const found: Liquid[] = [];
|
||||
// the fluids above and beside x y z that could flow into it, above first
|
||||
#fluids_around(x: number, y: number, z: number): Fluid[] {
|
||||
const found: Fluid[] = [];
|
||||
for (const [dx, dy, dz] of [[0, 1, 0], ...HORIZONTAL.map(([dx, dz]) => [dx, 0, dz])]) {
|
||||
const liquid = this.#liquid(x + dx, y + dy, z + dz);
|
||||
if (liquid && !found.some((other) => other.nid === liquid.nid)) found.push(liquid);
|
||||
const fluid = this.#fluid(x + dx, y + dy, z + dz);
|
||||
if (fluid && !found.some((other) => other.nid === fluid.nid)) found.push(fluid);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
#liquid(x: number, y: number, z: number): Liquid | undefined {
|
||||
#fluid(x: number, y: number, z: number): Fluid | undefined {
|
||||
if (y < 0 || y >= CHUNK_HEIGHT) return undefined;
|
||||
const value = this.#world.value_at(x, y, z);
|
||||
if (value === undefined) return undefined;
|
||||
const nid = value & ID_MASK;
|
||||
const block = this.#world.block(nid);
|
||||
if (block?.liquid) return { nid, block, level: get_state_value(value, block, "level")! };
|
||||
// a waterlogged block is a source of its liquid that never flows away, like minecraft's
|
||||
const liquid = liquid_block(value, block);
|
||||
return liquid && { nid: this.#world.nid(liquid.id), block: liquid, level: 0 };
|
||||
if (block?.fluid) return { nid, block, level: get_state_value(value, block, "level")! };
|
||||
// a waterlogged block is a source of its fluid that never flows away, like minecraft's
|
||||
const fluid = fluid_block(value, block);
|
||||
return fluid && { nid: this.#world.nid(fluid.id), block: fluid, level: 0 };
|
||||
}
|
||||
|
||||
#set(block: BlockRegistry, x: number, y: number, z: number, level: number) {
|
||||
+22
-22
@@ -15,7 +15,7 @@ import {
|
||||
TICKS_PER_SECOND,
|
||||
} from "$/common/constants.ts";
|
||||
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { LiquidFlow } from "./liquids.ts";
|
||||
import { FluidFlow } from "./fluids.ts";
|
||||
import { Container, ItemData, ItemStack } from "$/common/inventory.ts";
|
||||
import {
|
||||
AIR_ID,
|
||||
@@ -38,8 +38,8 @@ import {
|
||||
can_stand_on,
|
||||
chunk_key,
|
||||
display_name,
|
||||
fluid_block,
|
||||
is_waterlogged,
|
||||
liquid_block,
|
||||
placement_target,
|
||||
set_state_value,
|
||||
waterlog_placement,
|
||||
@@ -182,8 +182,8 @@ export class GameServer {
|
||||
recipes: RecipeBook;
|
||||
// monsters spawning on their own near players, see natural_spawner.ts
|
||||
spawner: NaturalSpawner;
|
||||
// water and other liquids flowing, see liquids.ts
|
||||
liquids: LiquidFlow;
|
||||
// water and other fluids flowing, see fluids.ts
|
||||
fluids: FluidFlow;
|
||||
// minecraft's doMobSpawning game rule. tests turn it off so nothing turns up they didn't put there
|
||||
do_mob_spawning = true;
|
||||
// what runs tick(), for /tps. tests call tick() themselves
|
||||
@@ -215,7 +215,7 @@ export class GameServer {
|
||||
);
|
||||
}
|
||||
this.world = new ServerWorld(saved?.seed ?? default_seed, mods.worldgen);
|
||||
this.liquids = new LiquidFlow({
|
||||
this.fluids = new FluidFlow({
|
||||
value_at: (x, y, z) => {
|
||||
if (y < 0 || y >= CHUNK_HEIGHT) return undefined;
|
||||
const loaded = this.world.has_chunk(Math.floor(x / CHUNK_SIZE), Math.floor(z / CHUNK_SIZE));
|
||||
@@ -280,7 +280,7 @@ export class GameServer {
|
||||
|
||||
// players without the chunk get the block with it when they do, like minecraft
|
||||
this.world.on_block_change = (x, y, z, id, state) => {
|
||||
this.liquids.changed(x, y, z, this.#tick);
|
||||
this.fluids.changed(x, y, z, this.#tick);
|
||||
const data = JSON.stringify(
|
||||
(state
|
||||
? { type: "set_block", x, y, z, id, state }
|
||||
@@ -384,7 +384,7 @@ export class GameServer {
|
||||
}
|
||||
|
||||
this.#new_days();
|
||||
this.liquids.tick(this.#tick);
|
||||
this.fluids.tick(this.#tick);
|
||||
this.#tick_vitals();
|
||||
for (const player of this.#players.values()) this.#tick_using(player);
|
||||
this.#tick_entities();
|
||||
@@ -805,9 +805,9 @@ export class GameServer {
|
||||
: drops && info.drop_table
|
||||
? [new ItemStack(info.drop_table)]
|
||||
: [];
|
||||
// a waterlogged block leaves its liquid behind, a source
|
||||
const liquid = is_waterlogged(value, info) ? liquid_block(value, info) : undefined;
|
||||
this.set_block(x, y, z, liquid?.id ?? AIR_ID, player);
|
||||
// a waterlogged block leaves its fluid behind, a source
|
||||
const fluid = is_waterlogged(value, info) ? fluid_block(value, info) : undefined;
|
||||
this.set_block(x, y, z, fluid?.id ?? AIR_ID, player);
|
||||
if (!how.collect) { for (const stack of loot) this.pop_item(x, y, z, stack); }
|
||||
return loot;
|
||||
}
|
||||
@@ -1323,8 +1323,8 @@ export class GameServer {
|
||||
const value = this.world.get_block_value(x, y, z);
|
||||
const held_slot = player.inventory.get_slot(player.selected_slot);
|
||||
const held = EverythingRegistry.get<ItemRegistry>("items", held_slot.type_id ?? "");
|
||||
// an item aimed at liquids, like a bucket, uses the liquid in a waterlogged block instead of the block
|
||||
const used = (held?.targets_liquids && liquid_block(value, info)) || info;
|
||||
// an item aimed at fluids, like a bucket, uses the fluid in a waterlogged block instead of the block
|
||||
const used = (held?.targets_fluids && fluid_block(value, info)) || info;
|
||||
const block = this.mods.block_ref(x, y, z, used.id);
|
||||
const interact = { player: player_api, block, item: player_api.held_item };
|
||||
const before_interact = { ...interact, cancel: false };
|
||||
@@ -1364,7 +1364,7 @@ export class GameServer {
|
||||
return;
|
||||
}
|
||||
|
||||
// placing a liquid, like a water bucket, into a block that can hold it fills it, like minecraft's
|
||||
// placing a fluid, like a water bucket, into a block that can hold it fills it, like minecraft's
|
||||
if (held?.block_id && info.waterloggable === held.block_id && !is_waterlogged(value, info)) {
|
||||
this.#waterlog(player, x, y, z, face, hit);
|
||||
return;
|
||||
@@ -1399,7 +1399,7 @@ export class GameServer {
|
||||
this.#correct(player, tx, ty, tz);
|
||||
return;
|
||||
}
|
||||
// put into a source of the liquid it can hold, it holds it
|
||||
// put into a source of the fluid it can hold, it holds it
|
||||
const placed_value = waterlog_placement(
|
||||
ruled_value,
|
||||
placing,
|
||||
@@ -1420,7 +1420,7 @@ export class GameServer {
|
||||
this.mods.after.block_place.emit(place);
|
||||
}
|
||||
|
||||
// the held liquid poured into the block at x y z, which can hold it. it's placing the liquid as far as mods can tell,
|
||||
// the held fluid poured into the block at x y z, which can hold it. it's placing the fluid as far as mods can tell,
|
||||
// so a bucket empties like it does placing water anywhere else
|
||||
#waterlog(player: ServerPlayer, x: number, y: number, z: number, face: Faces, hit: number[]) {
|
||||
const held_slot = player.inventory.get_slot(player.selected_slot);
|
||||
@@ -1984,19 +1984,19 @@ export class GameServer {
|
||||
}
|
||||
|
||||
const vitals = player.vitals;
|
||||
const in_liquid = this.#in_liquid(x, y, z);
|
||||
const in_fluid = this.#in_fluid(x, y, z);
|
||||
const sprinting = horizontal / (ticks * TICK_DELTA) > SPRINT_SPEED;
|
||||
if (in_liquid) {
|
||||
if (in_fluid) {
|
||||
vitals.add_exhaustion(EXHAUSTION.swim_per_block * (horizontal + Math.abs(dy)));
|
||||
player.fall_distance = 0;
|
||||
} else if (sprinting) {
|
||||
vitals.add_exhaustion(EXHAUSTION.sprint_per_block * horizontal);
|
||||
}
|
||||
if (dy > 0 && !in_liquid && this.#on_ground(player.x, player.y, player.z)) {
|
||||
if (dy > 0 && !in_fluid && this.#on_ground(player.x, player.y, player.z)) {
|
||||
vitals.add_exhaustion(sprinting ? EXHAUSTION.sprint_jump : EXHAUSTION.jump);
|
||||
}
|
||||
|
||||
if (dy < 0 && !in_liquid) {
|
||||
if (dy < 0 && !in_fluid) {
|
||||
player.fall_distance -= dy;
|
||||
}
|
||||
if (player.on_ground) {
|
||||
@@ -2024,10 +2024,10 @@ export class GameServer {
|
||||
return !physics.box_is_free(under_feet, 0, 0, 0, (bx, by, bz) => this.world.collision_shape(bx, by, bz));
|
||||
}
|
||||
|
||||
// in liquid, a waterlogged block's too
|
||||
#in_liquid(x: number, y: number, z: number) {
|
||||
// in fluid, a waterlogged block's too
|
||||
#in_fluid(x: number, y: number, z: number) {
|
||||
const [bx, by, bz] = [Math.floor(x), Math.floor(y), Math.floor(z)];
|
||||
return liquid_block(this.world.get_block_value(bx, by, bz), this.world.get_block_info(bx, by, bz)) !==
|
||||
return fluid_block(this.world.get_block_value(bx, by, bz), this.world.get_block_info(bx, by, bz)) !==
|
||||
undefined;
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -3,9 +3,9 @@
|
||||
|
||||
// runs mods' server scripts: builds each one's ServerContext and keeps what they register.
|
||||
// see docs/modding/. parts not built yet throw when used, saying so
|
||||
import { BlockRegistry, EverythingRegistry, ItemRegistry, liquid_height } from "$/common/everything_registry.ts";
|
||||
import { BlockRegistry, EverythingRegistry, fluid_height, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { Container as EngineContainer, ItemStack as EngineItemStack } from "$/common/inventory.ts";
|
||||
import { block_states, get_state_value, is_waterlogged, liquid_block, set_state_value } from "$/common/utils.ts";
|
||||
import { block_states, fluid_block, get_state_value, is_waterlogged, set_state_value } from "$/common/utils.ts";
|
||||
import { LootTables } from "./loot.ts";
|
||||
import { collision_shape_at, covers_face, is_solid, raycast_blocks, type Shape } from "$/common/block_shapes.ts";
|
||||
import { AIR, CHUNK_SIZE, faces, ID_MASK } from "$/common/constants.ts";
|
||||
@@ -803,9 +803,9 @@ export class ModRuntime {
|
||||
return entity_ref(entity);
|
||||
},
|
||||
raycast: (from, to, options) => {
|
||||
const liquids = options?.liquids ?? "none";
|
||||
if (!["none", "source_only", "any"].includes(liquids)) {
|
||||
throw new Error(`liquids must be "none", "source_only" or "any", not ${liquids}`);
|
||||
const fluids = options?.fluids ?? "none";
|
||||
if (!["none", "source_only", "any"].includes(fluids)) {
|
||||
throw new Error(`fluids must be "none", "source_only" or "any", not ${fluids}`);
|
||||
}
|
||||
const origin = [from.x, from.y, from.z];
|
||||
const length = Math.hypot(to.x - from.x, to.y - from.y, to.z - from.z);
|
||||
@@ -817,15 +817,15 @@ export class ModRuntime {
|
||||
origin,
|
||||
direction,
|
||||
length,
|
||||
(x, y, z) => raycast_shape(world, x, y, z, liquids),
|
||||
(x, y, z) => raycast_shape(world, x, y, z, fluids),
|
||||
);
|
||||
if (!hit) return undefined;
|
||||
// what was hit in a waterlogged block with liquids on is its liquid, see raycast_shape
|
||||
// what was hit in a waterlogged block with fluids on is its fluid, see raycast_shape
|
||||
const value = world.get_block_value(hit.x, hit.y, hit.z);
|
||||
const block = world.get_block_info(hit.x, hit.y, hit.z);
|
||||
const liquid = liquids === "none" ? undefined : liquid_block(value, block);
|
||||
const fluid = fluids === "none" ? undefined : fluid_block(value, block);
|
||||
return {
|
||||
id: liquid?.id ?? world.get_block_id(hit.x, hit.y, hit.z),
|
||||
id: fluid?.id ?? world.get_block_id(hit.x, hit.y, hit.z),
|
||||
x: hit.x,
|
||||
y: hit.y,
|
||||
z: hit.z,
|
||||
@@ -837,12 +837,12 @@ export class ModRuntime {
|
||||
},
|
||||
};
|
||||
},
|
||||
liquid_flow: (x, y, z) => {
|
||||
const [fx, fy, fz] = physics.liquid_flow(
|
||||
fluid_flow: (x, y, z) => {
|
||||
const [fx, fy, fz] = physics.fluid_flow(
|
||||
Math.floor(x),
|
||||
Math.floor(y),
|
||||
Math.floor(z),
|
||||
(x, y, z) => game().entities.liquid_at(x, y, z),
|
||||
(x, y, z) => game().entities.fluid_at(x, y, z),
|
||||
(x, y, z) => game().world.collision_shape(x, y, z),
|
||||
);
|
||||
// without any -0
|
||||
@@ -1315,27 +1315,27 @@ function container_api(game: GameServer, id: string, container: EngineContainer)
|
||||
return api;
|
||||
}
|
||||
|
||||
// what ServerWorld.raycast hits in a block: what entities bump into, and liquids up to their surface when it's
|
||||
// what ServerWorld.raycast hits in a block: what entities bump into, and fluids up to their surface when it's
|
||||
// looking for them
|
||||
function raycast_shape(
|
||||
world: GameServer["world"],
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
liquids: "none" | "source_only" | "any",
|
||||
fluids: "none" | "source_only" | "any",
|
||||
): Shape | undefined {
|
||||
const value = world.get_block_value(x, y, z);
|
||||
const nid = value & ID_MASK;
|
||||
if (nid === AIR) return undefined;
|
||||
const block = EverythingRegistry.get_by_id<BlockRegistry>("blocks", nid);
|
||||
if (!block) return undefined;
|
||||
if (block.liquid) {
|
||||
if (block.fluid) {
|
||||
const level = get_state_value(value, block, "level") ?? 0;
|
||||
if (liquids === "none" || (liquids === "source_only" && level !== 0)) return undefined;
|
||||
return [[0, 0, 0, 1, liquid_height(level, block.liquid.range), 1]];
|
||||
if (fluids === "none" || (fluids === "source_only" && level !== 0)) return undefined;
|
||||
return [[0, 0, 0, 1, fluid_height(level, block.fluid.range), 1]];
|
||||
}
|
||||
// the source in a waterlogged block covers the block, like minecraft's fluid clip
|
||||
if (liquids !== "none" && is_waterlogged(value, block)) return [[0, 0, 0, 1, 1, 1]];
|
||||
if (fluids !== "none" && is_waterlogged(value, block)) return [[0, 0, 0, 1, 1, 1]];
|
||||
const shape = collision_shape_at(block, value);
|
||||
return shape.length > 0 ? shape : undefined;
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ function has_room(entities: EntityManager, mob: Mob) {
|
||||
for (let x = Math.floor(mob.x - half); x < mob.x + half; x++) {
|
||||
for (let y = Math.floor(mob.y); y < mob.y + mob.height; y++) {
|
||||
for (let z = Math.floor(mob.z - half); z < mob.z + half; z++) {
|
||||
if (entities.has_collision(x, y, z) || entities.is_liquid(x, y, z)) return false;
|
||||
if (entities.has_collision(x, y, z) || entities.is_fluid(x, y, z)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,8 +147,8 @@ export class ServerPlayer extends LivingEntity {
|
||||
|
||||
// their client moves them, this only burns, falls out of the world and counts effects and hurt time down. while
|
||||
// knocked back it moves them like a mob that isn't walking anywhere, landing hands them back to their client
|
||||
// its client moves it, liquids included, see LocalPlayer
|
||||
override get pushed_by_liquid() {
|
||||
// its client moves it, fluids included, see LocalPlayer
|
||||
override get pushed_by_fluid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user