diff --git a/server/enums/Packet.ts b/server/enums/Packet.ts index cca3454..a743e1d 100644 --- a/server/enums/Packet.ts +++ b/server/enums/Packet.ts @@ -22,6 +22,9 @@ export enum Packet { EntityAction = 0x13, NamedEntitySpawn = 0x14, + EntityVelocity = 0x1C, + DestroyEntity = 0x1D, + EntityStatus = 0x26, EntityMetadata = 0x28, diff --git a/server/packets/DestroyEntity.ts b/server/packets/DestroyEntity.ts new file mode 100644 index 0000000..1b772c6 --- /dev/null +++ b/server/packets/DestroyEntity.ts @@ -0,0 +1,25 @@ +import { createWriter, IReader, Endian } from "bufferstuff"; +import { IPacket } from "./IPacket"; +import { Packet } from "../enums/Packet"; + +export class PacketDestroyEntity implements IPacket { + public packetId = Packet.DestroyEntity; + public entityId:number; + + public constructor(entityId?:number) { + if (typeof(entityId) === "number") { + this.entityId = entityId; + } else { + this.entityId = Number.MIN_VALUE; + } + } + + public readData(reader:IReader) { + this.entityId = reader.readInt(); + return this; + } + + public writeData() { + return createWriter(Endian.BE, 5).writeUByte(this.packetId).writeInt(this.entityId).toBuffer(); + } +} \ No newline at end of file diff --git a/server/packets/EntityVelocity.ts b/server/packets/EntityVelocity.ts new file mode 100644 index 0000000..546ad3b --- /dev/null +++ b/server/packets/EntityVelocity.ts @@ -0,0 +1,49 @@ +import { createWriter, IReader, Endian } from "bufferstuff"; +import { IPacket } from "./IPacket"; +import { Packet } from "../enums/Packet"; + +const MOTION_MAX = 3.9; +function maxMotion(value:number) { + if (value < -MOTION_MAX) { + value = -MOTION_MAX; + } else if (value > MOTION_MAX) { + value = MOTION_MAX; + } + + return value; +} + +export class PacketEntityVelocity implements IPacket { + public packetId = Packet.EntityVelocity; + public entityId:number; + public x:number; + public y:number; + public z:number; + + public constructor(entityId?:number, x?:number, y?:number, z?:number) { + if (typeof(entityId) == "number" && typeof(x) === "number" && typeof(y) === "number" && typeof(z) === "number") { + this.entityId = entityId; + this.x = maxMotion(x) * 8000; + this.y = maxMotion(y) * 8000; + this.z = maxMotion(z) * 8000; + } else { + this.entityId = Number.MIN_VALUE; + this.x = Number.MIN_VALUE; + this.y = Number.MIN_VALUE; + this.z = Number.MIN_VALUE; + } + } + + public readData(reader:IReader) { + this.entityId = reader.readInt(); + this.x = reader.readShort() / 8000; + this.y = reader.readShort() / 8000; + this.z = reader.readShort() / 8000; + + return this; + } + + public writeData() { + return createWriter(Endian.BE, 11).writeUByte(this.packetId).writeInt(this.entityId).writeShort(this.x).writeShort(this.y).writeShort(this.z).toBuffer(); + } +} \ No newline at end of file