first working stuff
This commit is contained in:
@@ -103,13 +103,20 @@ window.WorldRenderer = class {
|
|||||||
renderChunks(cameraChunkX, cameraChunkZ) {
|
renderChunks(cameraChunkX, cameraChunkZ) {
|
||||||
let world = this.minecraft.world;
|
let world = this.minecraft.world;
|
||||||
|
|
||||||
for (let [index, chunk] of world.chunks) {
|
let renderDistance = WorldRenderer.RENDER_DISTANCE;
|
||||||
|
|
||||||
|
for (let x = -renderDistance; x <= renderDistance; x++) {
|
||||||
|
for (let z = -renderDistance; z <= renderDistance; z++) {
|
||||||
|
world.getChunkAt(cameraChunkX + x, cameraChunkZ + z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let [index, chunk] of world.chunks) {
|
||||||
let distanceX = Math.abs(cameraChunkX - chunk.x);
|
let distanceX = Math.abs(cameraChunkX - chunk.x);
|
||||||
let distanceZ = Math.abs(cameraChunkZ - chunk.z);
|
let distanceZ = Math.abs(cameraChunkZ - chunk.z);
|
||||||
|
|
||||||
// Is in render distance check
|
// Is in render distance check
|
||||||
if (distanceX < WorldRenderer.RENDER_DISTANCE && distanceZ < WorldRenderer.RENDER_DISTANCE) {
|
if (distanceX < renderDistance && distanceZ < renderDistance) {
|
||||||
// Make chunk visible
|
// Make chunk visible
|
||||||
chunk.group.visible = true;
|
chunk.group.visible = true;
|
||||||
|
|
||||||
@@ -152,20 +159,6 @@ window.WorldRenderer = class {
|
|||||||
if (this.chunkSectionUpdateQueue.length !== 0) {
|
if (this.chunkSectionUpdateQueue.length !== 0) {
|
||||||
let chunkSection = this.chunkSectionUpdateQueue.shift();
|
let chunkSection = this.chunkSectionUpdateQueue.shift();
|
||||||
if (chunkSection != null) {
|
if (chunkSection != null) {
|
||||||
// Load chunk
|
|
||||||
let chunk = chunkSection.chunk;
|
|
||||||
if (!chunk.isLoaded()) {
|
|
||||||
world.loadChunk(chunk);
|
|
||||||
|
|
||||||
// Rebuild neighbor chunks to update transparent blocks
|
|
||||||
for (let relX = -1; relX <= 1; relX++) {
|
|
||||||
for (let relZ = -1; relZ <= 1; relZ++) {
|
|
||||||
let neighborChunk = world.getChunkAt(chunk.x + relX, chunk.z + relZ);
|
|
||||||
neighborChunk.queueForRebuild();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild chunk
|
// Rebuild chunk
|
||||||
chunkSection.rebuild(this);
|
chunkSection.rebuild(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,9 @@ window.Chunk = class {
|
|||||||
|
|
||||||
// Create height map
|
// Create height map
|
||||||
this.heightMap = [];
|
this.heightMap = [];
|
||||||
this.initHeightMapAndLight();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initHeightMapAndLight() {
|
generateSkylightMap() {
|
||||||
let highest = World.TOTAL_HEIGHT;
|
let highest = World.TOTAL_HEIGHT;
|
||||||
for (let x = 0; x < 16; x++) {
|
for (let x = 0; x < 16; x++) {
|
||||||
for (let z = 0; z < 16; z++) {
|
for (let z = 0; z < 16; z++) {
|
||||||
@@ -160,6 +159,10 @@ window.Chunk = class {
|
|||||||
|
|
||||||
this.getSection(y >> 4).setBlockAt(x, y & 15, z, byte0);
|
this.getSection(y >> 4).setBlockAt(x, y & 15, z, byte0);
|
||||||
|
|
||||||
|
if (!this.loaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//if (k1 !== 0 && !this.worldObj.multiplayerWorld) {
|
//if (k1 !== 0 && !this.worldObj.multiplayerWorld) {
|
||||||
//Block.blocksList[k1].onBlockRemoval(this.world, l1, j, i2);
|
//Block.blocksList[k1].onBlockRemoval(this.world, l1, j, i2);
|
||||||
//}
|
//}
|
||||||
@@ -222,10 +225,6 @@ window.Chunk = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
|
||||||
this.loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
isLoaded() {
|
isLoaded() {
|
||||||
return this.loaded;
|
return this.loaded;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,20 +20,34 @@ window.World = class {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadChunk(chunk) {
|
getChunkAt(x, z) {
|
||||||
// Load chunk
|
let index = x + (z << 16);
|
||||||
chunk.load();
|
let chunk = this.chunks.get(index);
|
||||||
|
if (typeof chunk === 'undefined') {
|
||||||
|
let chunk = new Chunk(this, x, z);
|
||||||
|
|
||||||
// Generate new chunk
|
// Generate new chunk
|
||||||
this.generator.generateChunk(chunk);
|
this.generator.generateChunk(chunk);
|
||||||
|
|
||||||
// Populate chunk
|
// Init
|
||||||
this.generator.populateChunk(chunk.x, chunk.z);
|
chunk.generateSkylightMap();
|
||||||
|
|
||||||
|
// Register
|
||||||
|
chunk.loaded = true;
|
||||||
|
this.chunks.set(index, chunk);
|
||||||
|
this.group.add(chunk.group);
|
||||||
|
|
||||||
|
// Populate chunk
|
||||||
|
this.generator.populateChunk(chunk.x, chunk.z);
|
||||||
|
}
|
||||||
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
getChunkAtBlock(x, y, z) {
|
getChunkAtBlock(x, y, z) {
|
||||||
let chunk = this.getChunkAt(x >> 4, z >> 4);
|
if (!this.blockExists(x, y, z)) {
|
||||||
return y < 0 || y > World.TOTAL_HEIGHT ? null : chunk.getSection(y >> 4);
|
return null;
|
||||||
|
}
|
||||||
|
return this.getChunkAt(x >> 4, z >> 4).getSection(y >> 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCollisionBoxes(region) {
|
getCollisionBoxes(region) {
|
||||||
@@ -58,6 +72,21 @@ window.World = class {
|
|||||||
return boundingBoxList;
|
return boundingBoxList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateLights() {
|
||||||
|
// Update lights in queue
|
||||||
|
let i = 5000;
|
||||||
|
while (this.lightUpdateQueue.length > 0) {
|
||||||
|
if (i <= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this.lightUpdateQueue.shift().updateBlockLightning(this);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static prev = 0;
|
||||||
|
|
||||||
updateLight(sourceType, x1, y1, z1, x2, y2, z2, notifyNeighbor = true) {
|
updateLight(sourceType, x1, y1, z1, x2, y2, z2, notifyNeighbor = true) {
|
||||||
if (this.lightUpdates >= 50) {
|
if (this.lightUpdates >= 50) {
|
||||||
return;
|
return;
|
||||||
@@ -83,8 +112,13 @@ window.World = class {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (World.prev !== this.lightUpdateQueue.length && this.lightUpdateQueue.length % 100 === 0) {
|
||||||
|
World.prev = this.lightUpdateQueue.length;
|
||||||
|
console.log(this.lightUpdateQueue.length + " in queue");
|
||||||
|
}
|
||||||
|
|
||||||
this.lightUpdateQueue.push(new MetadataChunkBlock(sourceType, x1, y1, z1, x2, y2, z2));
|
this.lightUpdateQueue.push(new MetadataChunkBlock(sourceType, x1, y1, z1, x2, y2, z2));
|
||||||
if (this.lightUpdateQueue.length > 0x186a0) {
|
if (this.lightUpdateQueue.length > 0x186a0) {
|
||||||
this.lightUpdateQueue = [];
|
this.lightUpdateQueue = [];
|
||||||
@@ -124,26 +158,6 @@ window.World = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLights() {
|
|
||||||
if (this.lightUpdateProcesses >= 50) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.lightUpdateProcesses++;
|
|
||||||
|
|
||||||
// Update lights in queue
|
|
||||||
let i = 5000;
|
|
||||||
while (this.lightUpdateQueue.length > 0) {
|
|
||||||
if (i <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
this.lightUpdateQueue.shift().updateBlockLightning(this);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lightUpdateProcesses--;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
getHeightAt(x, z) {
|
getHeightAt(x, z) {
|
||||||
if (!this.chunkExists(x >> 4, z >> 4)) {
|
if (!this.chunkExists(x >> 4, z >> 4)) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -167,7 +181,7 @@ window.World = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSavedLightValue(sourceType, x, y, z) {
|
getSavedLightValue(sourceType, x, y, z) {
|
||||||
if (y < 0) {
|
if (!this.chunkExists(x >> 4, z >> 4)) {
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +190,7 @@ window.World = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLightAt(sourceType, x, y, z, lightLevel) {
|
setLightAt(sourceType, x, y, z, lightLevel) {
|
||||||
if (y < 0) {
|
if (!this.chunkExists(x >> 4, z >> 4)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,16 +229,6 @@ window.World = class {
|
|||||||
return this.getChunkAt(chunkX, chunkZ).getSection(layerY);
|
return this.getChunkAt(chunkX, chunkZ).getSection(layerY);
|
||||||
}
|
}
|
||||||
|
|
||||||
getChunkAt(x, z) {
|
|
||||||
let index = x + (z << 16);
|
|
||||||
let chunk = this.chunks.get(index);
|
|
||||||
if (typeof chunk === 'undefined') {
|
|
||||||
this.chunks.set(index, chunk = new Chunk(this, x, z));
|
|
||||||
this.group.add(chunk.group);
|
|
||||||
}
|
|
||||||
return chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
onBlockChanged(x, y, z) {
|
onBlockChanged(x, y, z) {
|
||||||
this.queueForRebuildInRegion(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1);
|
this.queueForRebuildInRegion(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ window.Block = class {
|
|||||||
// Register block
|
// Register block
|
||||||
Block.blocks.set(id, this);
|
Block.blocks.set(id, this);
|
||||||
Block.lightOpacity[id] = this.isSolid() ? 255 : 0;
|
Block.lightOpacity[id] = this.isSolid() ? 255 : 0;
|
||||||
|
|
||||||
|
Block.lightOpacity[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
getId() {
|
getId() {
|
||||||
|
|||||||
Reference in New Issue
Block a user