Add "Block" class and replace all usages of id's with static block referances

This commit is contained in:
Holly Stubbs 2021-10-22 11:37:35 +01:00
parent 65852606b3
commit a97f313879
Signed by: tgpholly
GPG Key ID: B8583C4B7D18119E
4 changed files with 176 additions and 85 deletions

86
server/Blocks/Block.js Normal file
View File

@ -0,0 +1,86 @@
class Block {
static blocksList = [];
static blockOpaqueList = [];
static blockOpacity = [];
static blockGrassable = [];
static blockContainer = [];
constructor(blockID = 0) {
this.blockID = blockID;
this.blockHardness = 0;
this.blockResistance = 0;
this.blockName = "";
if (Block.blocksList[blockID] != null) {
throw `[Block] Slot ${blockID} is already occupied by ${Block.blocksList[blockID]} when adding ID:${blockID}`;
} else {
Block.blocksList[blockID] = this;
Block.blockOpaqueList[blockID] = false; // TODO: Block opaque
Block.blockOpacity[blockID] = 0; // TODO: Opacity
Block.blockGrassable[blockID] = false; // TODO: Get if block can be grass'd
Block.blockContainer[blockID] = false; // TODO: Containers
}
}
setHardness(hardness = 0) {
this.blockHardness = hardness;
return this;
}
setBlockUnbreakable() {
this.blockHardness = -1;
return this;
}
setResistance(resistance = 0) {
this.blockHardness = resistance;
return this;
}
setName(name = "") {
this.blockName = name;
return this;
}
static stone = new Block(1).setHardness(1.5).setResistance(10).setName("Stone");
static grass = new Block(2).setHardness(0.6).setName("Grass");
static dirt = new Block(3).setHardness(0.5).setName("Dirt");
static cobblestone = new Block(4).setHardness(2.0).setResistance(10).setName("Cobblestone");
static planks = new Block(5).setHardness(2).setResistance(5).setName("Planks");
static sapling = new Block(6).setName("Sapling");
static bedrock = new Block(7).setBlockUnbreakable().setResistance(6000000).setName("Bedrock");
static waterFlowing = new Block(8).setHardness(100).setName("Flowing Water");
static waterStill = new Block(9).setHardness(100).setName("Still Water");
static lavaMoving = new Block(10).setHardness(1.5).setResistance(10).setName("Flowing Lava");
static lavaStill = new Block(11).setHardness(1.5).setResistance(10).setName("Still Lava");
static sand = new Block(12).setHardness(1.5).setResistance(10).setName("Sand");
static gravel = new Block(13).setHardness(1.5).setResistance(10).setName("Gravel");
static goldOre = new Block(14).setHardness(1.5).setResistance(10).setName("Gold Ore");
static ironOre = new Block(15).setHardness(1.5).setResistance(10).setName("Iron Ore");
static coalOre = new Block(16).setHardness(1.5).setResistance(10).setName("Coal Ore");
static wood = new Block(17).setHardness(1.5).setResistance(10).setName("Wood");
static leaves = new Block(18).setHardness(1.5).setResistance(10).setName("Leaves");
static sponge = new Block(19).setHardness(1.5).setResistance(10).setName("Sponge");
static glass = new Block(20).setHardness(1.5).setResistance(10).setName("Glass");
static lapisOre = new Block(21).setHardness(1.5).setResistance(10).setName("Lapis Ore");
static lapisBlock = new Block(22).setHardness(1.5).setResistance(10).setName("Lapis Block");
static dispenser = new Block(23).setHardness(1.5).setResistance(10).setName("Dispenser");
static sandStone = new Block(24).setHardness(1.5).setResistance(10).setName("Sandstone");
static noteBlock = new Block(25).setHardness(1.5).setResistance(10).setName("Noteblock");
static blockBed = new Block(26).setHardness(1.5).setResistance(10).setName("Bed");
static poweredRail = new Block(27).setHardness(1.5).setResistance(10).setName("Powered Rail");
static detectorRail = new Block(28).setHardness(1.5).setResistance(10).setName("Detector Rail");
static stickyPisonBase = new Block(29).setHardness(1.5).setResistance(10).setName("Sticky Piston Base");
static cobweb = new Block(30).setHardness(4).setName("Cobweb");
static tallGrass = new Block(31).setName("Tall Grass");
static deadBush = new Block(32).setName("Dead Bush");
static pistonBase = new Block(33).setName("Piston Base");
static pistonExtension = new Block(34).setName("Piston Extension");
static wool = new Block(35).setHardness(0.8).setName("Wool");
static pistonMoving = new Block(36).setName("Piston Moving")
static dandilion = new Block(37).setName("Dandilion");
static rose = new Block(38).setName("Rose");
}
module.exports = Block;

View File

@ -1,3 +1,5 @@
const Block = require("../Blocks/Block.js");
module.exports = function(x = 0, z = 0) {
// Create chunk
let chunk = {};
@ -6,7 +8,7 @@ module.exports = function(x = 0, z = 0) {
for (let x = 0; x < 16; x++) {
chunk[y][x] = {};
for (let z = 0; z < 16; z++) {
chunk[y][x][z] = 0;
chunk[y][x][z] = [0, 0];
}
}
}
@ -17,10 +19,10 @@ module.exports = function(x = 0, z = 0) {
if (y == 64) {
chunk[y][x][z] = 2;
}
else if (y == 63 || y == 62) chunk[y][x][z] = 3;
else if (y == 0) chunk[y][x][z] = 7;
else if (y < 62) chunk[y][x][z] = 1;
else chunk[y][x][z] = 0;
else if (y == 63 || y == 62) chunk[y][x][z][0] = Block.dirt.blockID;
else if (y == 0) chunk[y][x][z][0] = Block.bedrock.blockID;
else if (y < 62) chunk[y][x][z][0] = Block.stone.blockID;
else chunk[y][x][z][0] = 0;
}
}
}

View File

@ -1,4 +1,5 @@
const { perlin2D } = require("./perlin.js");
const Block = require("../Blocks/Block.js");
module.exports = function(cx = 0, cz = 0, seed = 0) {
// Create bare chunk
@ -34,7 +35,7 @@ module.exports = function(cx = 0, cz = 0, seed = 0) {
const layer3 = (layer3_1 + layer3_2) / 2;
const average = Math.floor((layer1 + layer2 + layer3) / 3);
stripTopCoord[x][z] = average;
chunk[average][x][z][0] = 2;
chunk[average][x][z][0] = Block.grass.blockID;
}
}
@ -46,9 +47,9 @@ module.exports = function(cx = 0, cz = 0, seed = 0) {
topM2 = topM1 - 1;
for (let y = stripTopCoord[x][z]; y != -1; y--) {
if (y == topM1 || y == topM2) chunk[y][x][z][0] = 3;
else if (y == 0) chunk[y][x][z][0] = 7;
else if (y < topM2) chunk[y][x][z][0] = 1;
if (y == topM1 || y == topM2) chunk[y][x][z][0] = Block.dirt.blockID;
else if (y == 0) chunk[y][x][z][0] = Block.bedrock.blockID;
else if (y < topM2) chunk[y][x][z][0] = Block.stone.blockID;
}
}
}
@ -57,9 +58,9 @@ module.exports = function(cx = 0, cz = 0, seed = 0) {
for (let y = 0; y < 128; y++) {
for (let x = 0; x < 16; x++) {
for (let z = 0; z < 16; z++) {
if (chunk[y][x][z][0] == 0 && y < 64) chunk[y][x][z][0] = 9;
if (chunk[y][x][z][0] == 0 && y < 64) chunk[y][x][z][0] = Block.waterStill.blockID;
if (y < 127 && y > 0) if (chunk[y][x][z][0] == 9 && chunk[y - 1][x][z][0] == 2) chunk[y - 1][x][z][0] = 3;
if (y < 127 && y > 0) if (chunk[y][x][z][0] == Block.waterStill.blockID && chunk[y - 1][x][z][0] == 2) chunk[y - 1][x][z][0] = Block.dirt.blockID;
//if (x == 0 && z == 0) chunk[y][x][z] = 57;
}
@ -76,14 +77,14 @@ module.exports = function(cx = 0, cz = 0, seed = 0) {
for (let z = 0; z < 16; z++) {
topBlock = stripTopCoord[x][z];
if (chunk[topBlock][x][z][0] == 2) {
if (chunk[topBlock][x][z][0] == Block.grass.blockID) {
if (Math.floor(Math.random() * 5) == 0) {
chunk[topBlock + 1][x][z][0] = 31;
chunk[topBlock + 1][x][z][0] = Block.tallGrass.blockID;
chunk[topBlock + 1][x][z][1] = 1;
} else if (Math.floor(Math.random() * 150) == 0) {
chunk[topBlock + 1][x][z][0] = 38;
chunk[topBlock + 1][x][z][0] = Block.rose.blockID;
} else if (Math.floor(Math.random() * 150) == 0) {
chunk[topBlock + 1][x][z][0] = 37;
chunk[topBlock + 1][x][z][0] = Block.dandilion.blockID;
}
}
@ -91,93 +92,93 @@ module.exports = function(cx = 0, cz = 0, seed = 0) {
if (chunk[topBlock][x][z][0] == 2 && Math.floor(Math.random() * 200) == 0) {
chunk[topBlock][x][z][0] = 3;
// Logs
treeBlocks.push([(chunkX + x), topBlock + 1, (chunkZ + z), 17]);
treeBlocks.push([(chunkX + x), topBlock + 2, (chunkZ + z), 17]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z), 17]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z), 17]);
treeBlocks.push([(chunkX + x), topBlock + 5, (chunkZ + z), 17]);
treeBlocks.push([(chunkX + x), topBlock + 1, (chunkZ + z), Block.wood.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 2, (chunkZ + z), Block.wood.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z), Block.wood.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z), Block.wood.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 5, (chunkZ + z), Block.wood.blockID]);
// Leaves
// Layer 1
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 3, (chunkZ + z) + 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 3, (chunkZ + z) + 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 3, (chunkZ + z) + 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 3, (chunkZ + z) + 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 3, (chunkZ + z) + 2, Block.leaves.blockID]);
// Layer 2
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 4, (chunkZ + z) + 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 4, (chunkZ + z) + 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 2, topBlock + 4, (chunkZ + z) + 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 4, (chunkZ + z) + 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z) - 2, 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z) + 2, 18]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z) - 2, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 2, topBlock + 4, (chunkZ + z) + 2, Block.leaves.blockID]);
// Layer 3
treeBlocks.push([(chunkX + x) - 1, topBlock + 5, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 5, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x), topBlock + 5, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x), topBlock + 5, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 5, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 5, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 5, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 5, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 5, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 5, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 5, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 5, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 5, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 5, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 5, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 5, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 5, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 5, (chunkZ + z) - 1, Block.leaves.blockID]);
// Layer 4
treeBlocks.push([(chunkX + x) - 1, topBlock + 6, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 6, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x), topBlock + 6, (chunkZ + z) - 1, 18]);
treeBlocks.push([(chunkX + x), topBlock + 6, (chunkZ + z) + 1, 18]);
treeBlocks.push([(chunkX + x), topBlock + 6, (chunkZ + z), 18]);
treeBlocks.push([(chunkX + x) - 1, topBlock + 6, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x) + 1, topBlock + 6, (chunkZ + z), Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 6, (chunkZ + z) - 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 6, (chunkZ + z) + 1, Block.leaves.blockID]);
treeBlocks.push([(chunkX + x), topBlock + 6, (chunkZ + z), Block.leaves.blockID]);
}
}
}

View File

@ -12,6 +12,7 @@ const EntityPlayer = require("./Entities/EntityPlayer.js");
const PacketMappingTable = require("./PacketMappingTable.js");
const NamedPackets = require("./NamedPackets.js");
const Converter = require("./Converter.js");
const Block = require("./Blocks/Block.js");
const Socket = require("net").Socket;
@ -84,7 +85,8 @@ module.exports.init = function(config) {
}
// Do chunk updates
// Don't update if chunk is generating
if (true) {
if (global.chunkManager.queuedBlockUpdates.getLength() > 0) {
console.log("Queue length: " + global.chunkManager.queuedBlockUpdates.getLength())
let itemsToRemove = [];
// Do a max of 128 block updates per tick
for (let i = 0; i < Math.min(global.chunkManager.queuedBlockUpdates.getLength(), 128); i++) {
@ -176,7 +178,7 @@ module.exports.connection = async function(socket = new Socket) {
break;
case NamedPackets.LoginRequest:
socket.write(new PacketMappingTable[NamedPackets.LoginRequest](reader.readInt(), reader.readString(), reader.readLong(), reader.readByte()).writePacket(thisUser.id));
socket.write(new PacketMappingTable[NamedPackets.LoginRequest](reader.readInt(), reader.readString(), global.chunkManager.seed, reader.readByte()).writePacket(thisUser.id));
socket.write(new PacketMappingTable[NamedPackets.SpawnPosition]().writePacket());
for (let x = -3; x < 4; x++) {
@ -188,7 +190,7 @@ module.exports.connection = async function(socket = new Socket) {
// Place a layer of glass under the player so they don't fall n' die
for (let x = 0; x < 16; x++) {
for (let z = 0; z < 16; z++) {
socket.write(new PacketMappingTable[NamedPackets.BlockChange](x, 64, z, 20, 0).writePacket());
socket.write(new PacketMappingTable[NamedPackets.BlockChange](x, 64, z, Block.glass.blockID, 0).writePacket());
}
}