mc-beta-server/server/Entities/EntityPlayer.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-08-15 00:21:41 +01:00
const EntityLiving = require("./EntityLiving.js");
2021-08-24 15:08:48 +01:00
const user = require("../user.js");
const Converter = require("../Converter.js");
const PacketMappingTable = require("../PacketMappingTable.js");
const NamedPackets = require("../NamedPackets.js");
2021-08-15 00:21:41 +01:00
class EntityPlayer extends EntityLiving {
2021-08-24 15:08:48 +01:00
constructor(parent = new user, x = 0, y = 0, z = 0) {
super(parent.id, x, y, z);
this.lastX = 0;
this.lastY = 0;
this.lastZ = 0;
this.absX = 0;
this.absY = 0;
this.absZ = 0;
this.absYaw = 0;
this.absPitch = 0;
this.lastYaw = 0;
this.lastPitch = 0;
this.allPacket = new PacketMappingTable[NamedPackets.EntityTeleport](this.EID, this.x, this.y, this.z, this.absYaw, this.absPitch);
this.allPacket.soup();
this.allPacket.writePacket();
this.parentPlayer = parent;
}
onTick() {
super.onTick();
this.absX = Math.floor(this.x);
this.absY = Math.floor(this.y);
this.absZ = Math.floor(this.z);
this.absYaw = Math.floor(this.yaw);
this.absPitch = Math.floor(this.pitch);
if ((this.absX != this.lastX || this.absY != this.lastY || this.absZ != this.lastZ)) {
// all
this.allPacket.writer.offset = 5;
this.allPacket.writer.writeInt(Converter.toAbsoluteInt(this.x));
this.allPacket.writer.writeInt(Converter.toAbsoluteInt(this.y));
this.allPacket.writer.writeInt(Converter.toAbsoluteInt(this.z));
this.allPacket.writer.writeUByte(Converter.to360Fraction(this.absYaw));
this.allPacket.writer.writeUByte(Converter.to360Fraction(this.absPitch));
global.sendToAllPlayersButSelf(this.EID, this.allPacket.toBuffer());
} else if (this.absYaw != this.lastYaw || this.absPitch != this.lastPitch) {
// look only
global.sendToAllPlayersButSelf(this.EID, new PacketMappingTable[NamedPackets.EntityLook](this.EID, this.absYaw, this.absPitch).writePacket());
}
this.lastYaw = this.absYaw;
this.lastPitch = this.absPitch;
2021-08-15 00:21:41 +01:00
2021-08-24 15:08:48 +01:00
this.lastX = this.absX;
this.lastY = this.absY;
this.lastZ = this.absZ;
2021-08-15 00:21:41 +01:00
}
}
module.exports = EntityPlayer;