Engine api
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { eyes_in_water, in_water, move_body } from "$/common/physics.ts";
|
||||
import { physics } from "$/common/physics.ts";
|
||||
import type { ClientLevel } from "../level/client_level.ts";
|
||||
|
||||
// anything that exists in the level and moves, like minecraft's Entity. position is the middle of its feet.
|
||||
@@ -61,12 +61,12 @@ export abstract class Entity {
|
||||
|
||||
// in water, like the server's Entity.in_water
|
||||
get in_water() {
|
||||
return in_water(this, (x, y, z) => this.level.is_liquid(x, y, z));
|
||||
return physics.in_water(this, (x, y, z) => this.level.is_liquid(x, y, z));
|
||||
}
|
||||
|
||||
// its eyes are in water
|
||||
get eyes_in_water() {
|
||||
return 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_liquid(x, y, z));
|
||||
}
|
||||
|
||||
// after moving each tick. full speed is 5 blocks per second, a bit faster than walking
|
||||
@@ -130,7 +130,7 @@ export abstract class Entity {
|
||||
const is_solid = (x: number, y: number, z: number) => this.level.collision_shape(x, y, z);
|
||||
const can_step = this.#air_ticks <= this.step_grace_ticks && this.vy <= 0;
|
||||
const friction = this.horizontal_friction();
|
||||
const collisions = move_body(this, this.gravity, is_solid, this.step_height, can_step);
|
||||
const collisions = physics.move_body(this, this.gravity, is_solid, this.step_height, can_step);
|
||||
this.colliding_x = collisions.x;
|
||||
this.colliding_y = collisions.y;
|
||||
this.colliding_z = collisions.z;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PLAYER_EYE_HEIGHT, PLAYER_HEIGHT, PLAYER_SWIM_EYE_HEIGHT, TICK_DELTA } from "$/common/constants.ts";
|
||||
import { back_off_from_edge, box_is_free } from "$/common/physics.ts";
|
||||
import { physics } from "$/common/physics.ts";
|
||||
import type { Client } from "../client.ts";
|
||||
import { InputManager } from "../input_manager.ts";
|
||||
import { ClientInventories } from "../inventory.ts";
|
||||
@@ -158,7 +158,7 @@ export class LocalPlayer extends Player {
|
||||
// not while jumping, so it can still jump off a ledge
|
||||
if (this.sneaking && this.on_ground && this.vy <= 0) {
|
||||
const is_solid = (x: number, y: number, z: number) => this.level.collision_shape(x, y, z);
|
||||
const [dx, dz] = back_off_from_edge(
|
||||
const [dx, dz] = physics.back_off_from_edge(
|
||||
this,
|
||||
this.vx * TICK_DELTA,
|
||||
this.vz * TICK_DELTA,
|
||||
@@ -195,7 +195,9 @@ export class LocalPlayer extends Player {
|
||||
vy: 0,
|
||||
vz: 0,
|
||||
};
|
||||
if (box_is_free(standing, 0, 0, 0, (x, y, z) => this.level.collision_shape(x, y, z))) this.set_swimming(false);
|
||||
if (physics.box_is_free(standing, 0, 0, 0, (x, y, z) => this.level.collision_shape(x, y, z))) {
|
||||
this.set_swimming(false);
|
||||
}
|
||||
}
|
||||
|
||||
// turns up or down toward where it's looking. not up once its head is out, so it swims along the surface instead
|
||||
@@ -234,7 +236,7 @@ export class LocalPlayer extends Player {
|
||||
const blocked = (x: number, y: number, z: number) =>
|
||||
this.level.is_liquid(x, y, z) || this.level.collision_shape(x, y, z);
|
||||
const dy = from_y - this.y + this.vy * TICK_DELTA + WATER_HOP_HEIGHT;
|
||||
if (box_is_free(this, this.vx * TICK_DELTA, dy, this.vz * TICK_DELTA, blocked)) this.vy = WATER_HOP;
|
||||
if (physics.box_is_free(this, this.vx * TICK_DELTA, dy, this.vz * TICK_DELTA, blocked)) this.vy = WATER_HOP;
|
||||
}
|
||||
|
||||
// how much wider the view is than the fov option, between the last tick and this one
|
||||
|
||||
Reference in New Issue
Block a user