code cleanup

This commit is contained in:
Holly Stubbs 2021-08-21 09:38:25 +01:00
parent 3d24527e50
commit ad550a8e7b
5 changed files with 12 additions and 5 deletions

View file

@ -1,3 +1,7 @@
module.exports.toAbsoluteInt = function(float = 0.0) { module.exports.toAbsoluteInt = function(float = 0.0) {
return Math.round(float * 32.0); return Math.round(float * 32.0);
} }
module.exports.to360Fraction = function(float = 0.0) {
return Math.floor((float / 360) * 256);
}

View file

@ -1,9 +1,11 @@
const Entity = require("./Entity.js"); const Entity = require("./Entity.js");
class EntityItem extends Entity { class EntityItem extends Entity {
constructor(itemID = 0x00, x = 0, y = 0, z = 0) { constructor(itemStack, x = 0, y = 0, z = 0) {
super(global.fromIDPool(), x, y, z); super(global.fromIDPool(), x, y, z);
this.itemStack = itemStack;
this.motionX = (Math.random() * 0.2 - 0.1); this.motionX = (Math.random() * 0.2 - 0.1);
this.motionY = 0.2; this.motionY = 0.2;
this.motionZ = (Math.random() * 0.2 - 0.1); this.motionZ = (Math.random() * 0.2 - 0.1);

View file

@ -10,8 +10,8 @@ class Packet20NamedEntitySpawn extends Packet {
this.absX = Converter.toAbsoluteInt(x); this.absX = Converter.toAbsoluteInt(x);
this.absY = Converter.toAbsoluteInt(y); this.absY = Converter.toAbsoluteInt(y);
this.absZ = Converter.toAbsoluteInt(z); this.absZ = Converter.toAbsoluteInt(z);
this.packedYaw = 0; // TODO: Add rotation. this.packedYaw = Converter.to360Fraction(yaw);
this.packedPitch = 0; this.packedPitch = Converter.to360Fraction(pitch);
this.currentItem = currentItem; this.currentItem = currentItem;
} }

View file

@ -11,7 +11,7 @@ class Packet4TimeUpdate extends Packet {
} }
writePacket(EID = 0) { writePacket() {
super.writePacket(); super.writePacket();
this.writer.writeLong(this.time); this.writer.writeLong(this.time);

View file

@ -22,9 +22,10 @@ module.exports = class {
this.threadPool.push([false, worker]); this.threadPool.push([false, worker]);
const myID = i; const myID = i;
worker.on("message", (data) => { worker.on("message", (data) => {
let user;
switch (data[0]) { switch (data[0]) {
case "chunk": case "chunk":
const user = global.getUserByKey(data[2]); user = global.getUserByKey(data[2]);
user.chunksToSend.add(Buffer.from(data[1])); user.chunksToSend.add(Buffer.from(data[1]));
this.toRemove.push(data[1]); this.toRemove.push(data[1]);
this.threadPool[myID][0] = false; this.threadPool[myID][0] = false;