mc-beta-server/server/entities/Entity.ts

37 lines
786 B
TypeScript
Raw Normal View History

2023-04-08 20:52:47 +01:00
import { World } from "../World";
import { IEntity } from "./IEntity";
export class Entity implements IEntity {
public static nextEntityId:number = 0;
public entityId:number;
public world:World;
public x:number;
public y:number;
public z:number;
public lastX:number;
public lastY:number;
public lastZ:number;
public constructor(world:World) {
this.entityId = Entity.nextEntityId++;
this.world = world;
this.x = this.y = this.z = this.lastX = this.lastY = this.lastZ = 0;
}
2023-04-09 04:19:10 +01:00
2023-04-10 14:42:14 +01:00
distanceTo(entity:IEntity) {
const dX = entity.x - this.x,
dY = entity.y - this.y,
dZ = entity.z - this.z;
return Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2) + Math.pow(dZ, 2));
}
2023-04-09 04:19:10 +01:00
onTick() {
this.lastX = this.x;
this.lastY = this.y;
this.lastZ = this.z;
}
2023-04-08 20:52:47 +01:00
}