// Fills toDestroy and Safe list // Returns true if all blocks in currentList are connected to a stem // Returns false if all blocks in currentList doesn't connect to a stem or connects to a to-be-destroyed block private int SearchWood(CastCoord init, ChunkLoader cl) { ushort blockCode; ushort state; GetAroundCoords(init, cl); // Filters only Leaf blocks for (int i = 0; i < currentList.Count; i++) { // If it's connected to a marked-to-destroy block if (toDestroy.Contains(currentList[i])) { return(1); } // If it's connected to a safe block if (safeList.Contains(currentList[i])) { return(0); } // If current block is found in initial direction if (validDirections.Contains(currentList[i])) { validDirections.Remove(currentList[i]); } // PANIC if there's too many blocks if (currentList.Count > this.maxAnalysed) { currentList.Clear(); return(2); } blockCode = cl.GetBlock(currentList[i]); state = cl.GetState(currentList[i]); // If it's a spreadable block if (blockCode == this.thisCode && state == 0) { GetAroundCoords(currentList[i], cl); } // Check if it's a root else if (cl.blockBook.CheckSolid(blockCode)) { return(0); } else { currentList.RemoveAt(i); i--; } } return(1); }
// Returns a filled cache list full of surrounding coords private bool GetSurroundings(CastCoord init, int currentDistance, ChunkLoader cl) { // End if (currentDistance == 0) { return(false); } cache.Clear(); cache.Add(init.Add(0, 0, 1)); // North cache.Add(init.Add(0, 0, -1)); // South cache.Add(init.Add(1, 0, 0)); // East cache.Add(init.Add(-1, 0, 0)); // West cache.Add(init.Add(0, 1, 0)); // Up cache.Add(init.Add(0, -1, 0)); // Down // Filters only Leaf blocks foreach (CastCoord c in cache) { if (cl.GetBlock(c) == this.thisCode && cl.GetState(c) == 0) { // If is already in dict if (distances.ContainsKey(c)) { if (distances[c] > currentDistance) { distances[c] = currentDistance; openList.Add(c); } } else { distances.Add(c, currentDistance); openList.Add(c); } } if (cl.GetBlock(c) == this.assignedWoodCode && cl.GetState(c) == 0) { return(true); } } return(false); }
// Check if there's any wood block around this block private bool CheckWoodAround(CastCoord init, ChunkLoader cl) { cache.Clear(); cache.Add(init.Add(0, 0, 1)); // North cache.Add(init.Add(0, 0, -1)); // South cache.Add(init.Add(1, 0, 0)); // East cache.Add(init.Add(-1, 0, 0)); // West cache.Add(init.Add(0, 1, 0)); // Up cache.Add(init.Add(0, -1, 0)); // Down foreach (CastCoord c in cache) { if (cl.GetBlock(c) == this.thisCode && cl.GetState(c) == 0) { return(true); } } return(false); }
// Adds around coords to currentList private void GetAroundCoords(CastCoord pos, ChunkLoader cl) { CastCoord aux; ushort blockCode; aux = pos.Add(0, 0, 1); // N if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(1, 0, 1); // NE if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(1, 0, 0); // E if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(1, 0, -1); // SE if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(0, 0, -1); // S if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(-1, 0, -1); // SW if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(-1, 0, 0); // W if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(-1, 0, 1); // NW if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(0, 1, 0); // UP if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } aux = pos.Add(0, -1, 0); // DOWN if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (!currentList.Contains(aux)) { blockCode = cl.GetBlock(aux); if ((blockCode == this.thisCode && cl.GetState(aux) == 0) || cl.blockBook.CheckSolid(blockCode)) { currentList.Add(aux); } } } }
// Does the Wood check to break unconnected wood blocks from tree private void TreeCheck(CastCoord pos, ChunkLoader cl) { CastCoord aux; validDirections.Clear(); aux = pos.Add(0, 0, 1); // N if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(1, 0, 1); // NE if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(1, 0, 0); // E if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(1, 0, -1); // SE if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(0, 0, -1); // S if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(-1, 0, -1); // SW if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(-1, 0, 0); // W if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(-1, 0, 1); // NW if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(0, 1, 0); // UP if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } aux = pos.Add(0, -1, 0); // DOWN if (cl.chunks.ContainsKey(aux.GetChunkPos())) { if (cl.GetBlock(aux) == this.thisCode && cl.GetState(aux) == 0) { validDirections.Add(aux); } } RunWoodRecursion(cl); }