Add Packets DestroyEntity and EntityVelocity
This commit is contained in:
parent
bb733ff2af
commit
1b2b1a091e
3 changed files with 77 additions and 0 deletions
|
@ -22,6 +22,9 @@ export enum Packet {
|
|||
EntityAction = 0x13,
|
||||
NamedEntitySpawn = 0x14,
|
||||
|
||||
EntityVelocity = 0x1C,
|
||||
DestroyEntity = 0x1D,
|
||||
|
||||
EntityStatus = 0x26,
|
||||
EntityMetadata = 0x28,
|
||||
|
||||
|
|
25
server/packets/DestroyEntity.ts
Normal file
25
server/packets/DestroyEntity.ts
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
49
server/packets/EntityVelocity.ts
Normal file
49
server/packets/EntityVelocity.ts
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue