srhsfsfg
This commit is contained in:
parent
19880f1e8d
commit
45bdbdc354
4 changed files with 64 additions and 14 deletions
15
server/Entities/EntityLiving.js
Normal file
15
server/Entities/EntityLiving.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const Entity = require("./Entity.js");
|
||||
|
||||
class EntityPlayer extends Entity {
|
||||
constructor(x = 0, y = 0, z = 0) {
|
||||
super(x, y, z);
|
||||
|
||||
|
||||
}
|
||||
|
||||
onTick() {
|
||||
super.onTick();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EntityPlayer;
|
13
server/Entities/EntityPlayer.js
Normal file
13
server/Entities/EntityPlayer.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const EntityLiving = require("./EntityLiving.js");
|
||||
|
||||
class EntityPlayer extends EntityLiving {
|
||||
constructor(itemID = 0x00, x = 0, y = 0, z = 0) {
|
||||
super(x, y, z);
|
||||
|
||||
this.motionX = (Math.random() * 0.2 - 0.1);
|
||||
this.motionY = 0.2;
|
||||
this.motionZ = (Math.random() * 0.2 - 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EntityPlayer;
|
|
@ -1,3 +1,10 @@
|
|||
/*
|
||||
===========- bufferStuff.js -===========
|
||||
Created by Holly (tgpethan) (c) 2021
|
||||
Licensed under MIT
|
||||
========================================
|
||||
*/
|
||||
|
||||
module.exports.Writer = class {
|
||||
constructor() {
|
||||
this.buffer = Buffer.alloc(0);
|
||||
|
@ -60,7 +67,8 @@ module.exports.Writer = class {
|
|||
|
||||
writeLong(data = 0) {
|
||||
const buff = Buffer.alloc(8);
|
||||
buff.writeBigInt64BE(BigInt(data), 0);
|
||||
if (data instanceof BigInt) buff.writeBigInt64BE(data, 0);
|
||||
else buff.writeBigInt64BE(BigInt(data), 0);
|
||||
|
||||
this.writeBuffer(buff);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ let idPool = 1;
|
|||
global.fromIDPool = function() {
|
||||
const oldVal = idPool;
|
||||
idPool++;
|
||||
console.log(idPool);
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
|
@ -52,6 +53,7 @@ module.exports.init = function(config) {
|
|||
if (tickCounter % tickRate == 0) {
|
||||
for (let key of netUserKeys) {
|
||||
netUsers[key].socket.write(new PacketMappingTable[NamedPackets.KeepAlive]().writePacket());
|
||||
|
||||
}
|
||||
}
|
||||
// Update Chunks
|
||||
|
@ -82,20 +84,22 @@ module.exports.init = function(config) {
|
|||
|
||||
// Update users
|
||||
for (let key of netUserKeys) {
|
||||
const user = netUsers[netUserKeys];
|
||||
const user = netUsers[key];
|
||||
|
||||
let itemsToRemove = [];
|
||||
for (let i = 0; i < Math.min(user.chunksToSend.getLength(), 128); i++) {
|
||||
const chunkKey = user.chunksToSend.itemKeys[i];
|
||||
itemsToRemove.push(chunkKey);
|
||||
user.socket.write(user.chunksToSend.items[chunkKey]);
|
||||
if (user.loginFinished) {
|
||||
let itemsToRemove = [];
|
||||
for (let i = 0; i < Math.min(user.chunksToSend.getLength(), 128); i++) {
|
||||
const chunkKey = user.chunksToSend.itemKeys[i];
|
||||
itemsToRemove.push(chunkKey);
|
||||
user.socket.write(user.chunksToSend.items[chunkKey]);
|
||||
}
|
||||
|
||||
for (let item of itemsToRemove) {
|
||||
user.chunksToSend.remove(item, false);
|
||||
}
|
||||
|
||||
user.chunksToSend.regenerateIterableArray();
|
||||
}
|
||||
|
||||
for (let item of itemsToRemove) {
|
||||
user.chunksToSend.remove(item, false);
|
||||
}
|
||||
|
||||
user.chunksToSend.regenerateIterableArray();
|
||||
}
|
||||
|
||||
tickCounter++;
|
||||
|
@ -108,7 +112,9 @@ module.exports.connection = async function(socket = new Socket) {
|
|||
socket.on('data', function(chunk) {
|
||||
const reader = new bufferStuff.Reader(chunk);
|
||||
|
||||
switch(reader.readByte()) {
|
||||
const packetID = reader.readByte();
|
||||
|
||||
switch(packetID) {
|
||||
case NamedPackets.KeepAlive:
|
||||
socket.write(new PacketMappingTable[NamedPackets.KeepAlive]().writePacket());
|
||||
break;
|
||||
|
@ -151,6 +157,14 @@ module.exports.connection = async function(socket = new Socket) {
|
|||
|
||||
socket.write(new PacketMappingTable[NamedPackets.Handshake](thisUser.username).writePacket());
|
||||
break;
|
||||
|
||||
case NamedPackets.Player:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log("0x" + packetID.toString(16));
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue