diff --git a/console.ts b/console.ts index 904ee53..e7877a8 100644 --- a/console.ts +++ b/console.ts @@ -70,7 +70,7 @@ export class Console { Console.QUEUED_FOR_LOG = ""; Console.logFileWriteStream.write(strRef); } - }, 1000 * 10); + }, 5000); public static printInfo(s:string) : void { log(LogTag.INFO, s); diff --git a/server/MPClient.ts b/server/MPClient.ts index 0518b9d..99e4837 100644 --- a/server/MPClient.ts +++ b/server/MPClient.ts @@ -139,7 +139,7 @@ export class MPClient { // Started digging } else if (packet.status === 2) { if (this.entity.world.getBlockId(this.diggingAt.x, this.diggingAt.y, this.diggingAt.z) != 0) { - this.entity.world.setBlockWithMetadata(0, 0, this.diggingAt.x, this.diggingAt.y, this.diggingAt.z, true); + this.entity.world.setBlockWithNotify(this.diggingAt.x, this.diggingAt.y, this.diggingAt.z, 0); } } } diff --git a/server/World.ts b/server/World.ts index d9778c1..55ef271 100644 --- a/server/World.ts +++ b/server/World.ts @@ -1,6 +1,7 @@ import { FunkyArray } from "../funkyArray"; import { Chunk } from "./Chunk"; import { WorldSaveManager } from "./WorldSaveManager"; +import { Block } from "./blocks/Block"; import { IEntity } from "./entities/IEntity"; import { Player } from "./entities/Player"; //import { FlatGenerator } from "./generators/Flat"; @@ -159,6 +160,32 @@ export class World { } } + public setBlockWithNotify(x:number, y:number, z:number, blockId:number) { + this.setBlock(blockId, x, y, z, true); + this.notifyNeighborBlocksOfChange(x, y, z, blockId); + } + + public setBlockAndMetadataWithNotify(x:number, y:number, z:number, blockId:number, metadata:number) { + this.setBlockWithMetadata(blockId, metadata, x, y, z, true); + this.notifyNeighborBlocksOfChange(x, y, z, blockId); + } + + public notifyNeighborBlocksOfChange(x:number, y:number, z:number, blockId:number) { + this.notifyNeighborBlockOfChange(x - 1, y, z, blockId); + this.notifyNeighborBlockOfChange(x + 1, y, z, blockId); + this.notifyNeighborBlockOfChange(x, y - 1, z, blockId); + this.notifyNeighborBlockOfChange(x, y + 1, z, blockId); + this.notifyNeighborBlockOfChange(x, y, z - 1, blockId); + this.notifyNeighborBlockOfChange(x, y, z + 1, blockId); + } + + private notifyNeighborBlockOfChange(x:number, y:number, z:number, blockId:number) { + const block = Block.blocks[this.getBlockId(x, y, z)]; + if (block != null && block.blockId !== 0) { + block.neighborBlockChange(this, x, y, z, block.blockId); + } + } + public sendToNearbyClients(sentFrom:IEntity, buffer:Buffer) { this.players.forEach(player => { if (sentFrom.entityId !== player.entityId && Math.abs(sentFrom.distanceTo(player)) < World.ENTITY_MAX_SEND_DISTANCE) { diff --git a/server/blocks/Block.ts b/server/blocks/Block.ts index 0d3e594..8deba52 100644 --- a/server/blocks/Block.ts +++ b/server/blocks/Block.ts @@ -1,3 +1,5 @@ +import { World } from "../World"; + export class Block { public readonly blockId:number; public static readonly blocks:Array = new Array(); @@ -37,6 +39,15 @@ export class Block { return this; } + public neighborBlockChange(world:World, x:number, y:number, z:number, blockId:number) { + if (blockId === Block.flowerDandelion.blockId || blockId === Block.flowerRose.blockId || blockId === Block.tallGrass.blockId) { + const block = world.getBlockId(x, y - 1, z); + if (block !== Block.grass.blockId && block !== Block.dirt.blockId) { + world.setBlockWithNotify(x, y, z, 0); + } + } + } + // Define statics here static readonly stone = new Block(1).setBlockName("Stone"); static readonly grass = new Block(2).setBlockName("Grass");