private bool checkIfNeighbourChunksAreGenerated(Vector3Int chunkAddress, GenerateMapNearPlayer generateMapNearPlayer)
 {
     for (int x = chunkAddress.x - 1; x <= chunkAddress.x + 1; x++)
     {
         for (int z = chunkAddress.z - 1; x <= chunkAddress.z + 1; x++)
         {
             var queryChunkAddress = new Vector3Int(x, 0, z);
             if (!generateMapNearPlayer.IsGenerated(queryChunkAddress))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
    public void OnGenerateChunk(Vector3Int chunkAddress, GenerateMapNearPlayer source)
    {
        if (this.modulesThatGrowTrees == null)
        {
            this.prepareModulesThatGrowTrees();
        }

        // First, find a slot for the tree to grow and check if its neighbourhood is completely generated.
        // If nearby blocks are generated, start growing the tree.
        // Otherwise, add the chunk address to chunksWaitingForTrees and generate the tree once all surrounding *chunks*  are generated.
        try {
            this.chunksWaitingForTrees.Remove(chunkAddress);
            Vector3 treePosition = this.getTreePosition(chunkAddress, source.ChunkSize);
            if (this.checkIfNearbySlotsAreBuilt(this.mapBehaviour.GetMapPosition(treePosition), 2))
            {
                this.StartCoroutine(this.PlantTree(treePosition, false));
            }
            else
            {
                this.chunksWaitingForTrees.Add(chunkAddress);
            }
        } catch (NotSuitableForTreeGrowingException) { }

        for (int x = chunkAddress.x - 1; x <= chunkAddress.x + 1; x++)
        {
            for (int z = chunkAddress.z - 1; x <= chunkAddress.z + 1; x++)
            {
                var queryChunkAddress = new Vector3Int(x, 0, z);
                if (this.chunksWaitingForTrees.Contains(queryChunkAddress) && this.checkIfNeighbourChunksAreGenerated(queryChunkAddress, source))
                {
                    try {
                        this.chunksWaitingForTrees.Remove(queryChunkAddress);
                        Vector3 treePosition = this.getTreePosition(queryChunkAddress, source.ChunkSize);
                        this.StartCoroutine(this.PlantTree(treePosition, true));
                    } catch (NotSuitableForTreeGrowingException) { }
                }
            }
        }
    }
Exemple #3
0
 public ChunkEvents(GenerateMapNearPlayer source)
 {
     this.CompletedChunks = new ConcurrentQueue <Vector3Int>();
     this.MapGenerationCallbackReceivers = new List <IMapGenerationCallbackReceiver>();
     this.source = source;
 }