Death
This commit is contained in:
@@ -117,6 +117,10 @@ export interface BlockComponent<P = any> {
|
||||
// an entity is standing on it, every tick the entity moves, like minecraft's updateEntityAfterFallOn: an item
|
||||
// dropped into a basin going in. items lying still move every tick too
|
||||
on_entity_stand?(block: BlockRef, params: P, entity: EntityRef): void;
|
||||
// an entity's box is in it, every tick the entity moves, like neoforge's entityInside: a block that kills or slows
|
||||
// what walks into it. players' after each move their client sends. any block, whatever its shape, so one that
|
||||
// cares where in it the entity is checks the entity's position
|
||||
on_entity_inside?(block: BlockRef, params: P, entity: EntityRef): void;
|
||||
// what pipes, buckets and other blocks put fluid in and take it out by, reached from face, or from no side in
|
||||
// particular when it's undefined, like neoforge's Capabilities.FluidHandler.BLOCK. undefined when it has none
|
||||
// there. see ServerFluidApi.block_handler
|
||||
@@ -447,6 +451,9 @@ export interface EntityRef {
|
||||
// adds to how fast it's moving, in blocks a second, like minecraft's Entity.push: a fan blowing it along
|
||||
push(x: number, y: number, z: number): void;
|
||||
remove(): void;
|
||||
// like neoforge's Entity.kill: a player or a mob dies, even when invulnerable, and anything else is removed. cause
|
||||
// is for events and the death message, like LivingRef.damage's. mods' entity_damage can still cancel it
|
||||
kill(cause?: string): void;
|
||||
// what an item lying around is, a copy. undefined for every other kind of entity
|
||||
get_item(): ItemStack | undefined;
|
||||
// changes what an item lying around is, like ItemEntity.setItem. undefined or a count of 0 removes it. throws for
|
||||
|
||||
@@ -231,6 +231,19 @@ function overlaps_solid(min: number[], max: number[], is_solid: BlockCollision)
|
||||
return false;
|
||||
}
|
||||
|
||||
// every block the body's box is in, whatever's there, like minecraft's checkInsideBlocks. a box resting exactly on
|
||||
// a face isn't in the block on the other side
|
||||
export function blocks_inside(body: Body, visit: (x: number, y: number, z: number) => void) {
|
||||
const half = body.width / 2;
|
||||
for (let x = Math.floor(body.x - half + EPSILON); x <= Math.floor(body.x + half - EPSILON); x++) {
|
||||
for (let y = Math.floor(body.y + EPSILON); y <= Math.floor(body.y + body.height - EPSILON); y++) {
|
||||
for (let z = Math.floor(body.z - half + EPSILON); z <= Math.floor(body.z + half - EPSILON); z++) {
|
||||
visit(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// in water like minecraft's wasTouchingWater, close enough: its feet or the middle of its box are in fluid
|
||||
export function in_water(body: Body, is_fluid: (x: number, y: number, z: number) => boolean): boolean {
|
||||
const x = Math.floor(body.x);
|
||||
@@ -390,6 +403,7 @@ export const physics = {
|
||||
move_body,
|
||||
back_off_from_edge,
|
||||
box_is_free,
|
||||
blocks_inside,
|
||||
in_water,
|
||||
eyes_in_water,
|
||||
fluid_flow,
|
||||
|
||||
Reference in New Issue
Block a user