// Handles the emittion of BUD to neighboring blocks public void EmitBlockUpdate(BUDCode type, int x, int y, int z, int tickOffset, ChunkLoader_Server cl) { CastCoord thisPos = new CastCoord(new Vector3(x, y, z)); CastCoord[] neighbors = { thisPos.Add(1, 0, 0), thisPos.Add(-1, 0, 0), thisPos.Add(0, 1, 0), thisPos.Add(0, -1, 0), thisPos.Add(0, 0, 1), thisPos.Add(0, 0, -1) }; int[] facings = { 2, 0, 4, 5, 1, 3 }; int blockCode; int faceCounter = 0; foreach (CastCoord c in neighbors) { blockCode = cl.chunks[c.GetChunkPos()].data.GetCell(c.blockX, c.blockY, c.blockZ); cl.budscheduler.ScheduleBUD(new BUDSignal(type, c.GetWorldX(), c.GetWorldY(), c.GetWorldZ(), thisPos.GetWorldX(), thisPos.GetWorldY(), thisPos.GetWorldZ(), facings[faceCounter]), tickOffset); faceCounter++; } }
// Handles the emittion of BUD to neighboring blocks public void EmitBlockUpdate(string type, int x, int y, int z, int tickOffset, ChunkLoader cl) { CastCoord thisPos = new CastCoord(new Vector3(x, y, z)); CastCoord[] neighbors = { thisPos.Add(1, 0, 0), thisPos.Add(-1, 0, 0), thisPos.Add(0, 1, 0), thisPos.Add(0, -1, 0), thisPos.Add(0, 0, 1), thisPos.Add(0, 0, -1) }; int[] facings = { 2, 0, 4, 5, 1, 3 }; int faceCounter = 0; foreach (CastCoord c in neighbors) { cl.budscheduler.ScheduleBUD(new BUDSignal(type, c.GetWorldX(), c.GetWorldY(), c.GetWorldZ(), thisPos.GetWorldX(), thisPos.GetWorldY(), thisPos.GetWorldZ(), facings[faceCounter]), tickOffset); faceCounter++; } }
// Handles the emittion of BUD to neighboring blocks public void EmitBlockUpdate(BUDCode type, int x, int y, int z, int tickOffset, ChunkLoader_Server cl) { CastCoord thisPos = GetCoordinates(x, y, z); BUDSignal cachedBUD; CastCoord[] neighbors = { thisPos.Add(1, 0, 0), thisPos.Add(-1, 0, 0), thisPos.Add(0, 1, 0), thisPos.Add(0, -1, 0), thisPos.Add(0, 0, 1), thisPos.Add(0, 0, -1) }; int[] facings = { 2, 0, 4, 5, 1, 3 }; int faceCounter = 0; foreach (CastCoord c in neighbors) { // Ignores void updates if (c.blockY < 0 || c.blockY > Chunk.chunkDepth - 1) { continue; } cachedBUD = new BUDSignal(type, c.GetWorldX(), c.GetWorldY(), c.GetWorldZ(), thisPos.GetWorldX(), thisPos.GetWorldY(), thisPos.GetWorldZ(), facings[faceCounter]); cl.budscheduler.ScheduleBUD(cachedBUD, tickOffset); faceCounter++; } }
// Gets surrounding on cache private void GetLastSurrounding(CastCoord init) { 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 }
// Returns a filled cache list full of surrounding coords private bool GetSurroundings(CastCoord init, int currentDistance, ChunkLoader_Server 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); }
// Handles the emittion of BUD to neighboring blocks public void EmitDelayedBUD(string type, int x, int y, int z, int minOffset, int maxOffset, ChunkLoader cl) { CastCoord thisPos = new CastCoord(new Vector3(x, y, z)); cache.Clear(); cache.Add(thisPos.Add(1, 0, 0)); cache.Add(thisPos.Add(-1, 0, 0)); cache.Add(thisPos.Add(0, 1, 0)); cache.Add(thisPos.Add(0, -1, 0)); cache.Add(thisPos.Add(0, 0, 1)); cache.Add(thisPos.Add(0, 0, -1)); foreach (CastCoord c in cache) { cl.budscheduler.ScheduleBUD(new BUDSignal(type, c.GetWorldX(), c.GetWorldY(), c.GetWorldZ(), thisPos.GetWorldX(), thisPos.GetWorldY(), thisPos.GetWorldZ(), 0), Random.Range(minOffset, maxOffset)); } }
// 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); }