Water phyisics
This commit is contained in:
@@ -8,7 +8,7 @@ import { TICKS_PER_SECOND } from "$/common/constants.ts";
|
||||
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 Collisions, physics } from "$/common/physics.ts";
|
||||
import { type Collisions, type LiquidInCell, physics } from "$/common/physics.ts";
|
||||
import type { EntityData, EntityEvent, EntityInfo } from "$/common/protocol.ts";
|
||||
import type { ServerPlayer } from "../player.ts";
|
||||
|
||||
@@ -67,6 +67,8 @@ export interface EntityLevel {
|
||||
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;
|
||||
get_block_info(x: number, y: number, z: number): BlockRegistry | undefined;
|
||||
add_entity(entity: Entity): void;
|
||||
get_entity(id: string): Entity | undefined;
|
||||
@@ -229,6 +231,14 @@ export abstract class Entity {
|
||||
this.fall_distance = 0;
|
||||
this.fire = 0;
|
||||
}
|
||||
if (this.pushed_by_liquid) {
|
||||
physics.push_by_liquid(
|
||||
this,
|
||||
(x, y, z) => this.level.liquid_at(x, y, z),
|
||||
(x, y, z) => this.level.collision_shape(x, y, z),
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
if (this.fire > 0) {
|
||||
if (this.fire_immune) {
|
||||
@@ -246,6 +256,11 @@ export abstract class Entity {
|
||||
}
|
||||
}
|
||||
|
||||
// flowing liquid pushes it along, like minecraft's isPushedByFluid
|
||||
get pushed_by_liquid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
update_in_water() {
|
||||
this.in_water = physics.in_water(this, (x, y, z) => this.level.is_liquid(x, y, z));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user