public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { corners.Clear(); MTBPlantData data = MTBPlantDataManager.Instance.getData((int)_decorationType); int[] trunktemp = data.leafWidth; int treeCrownWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.chunkHeight; int treeHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.leafWidth; int treeCrownDepth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.leafHeight; int treeCrownHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; int startLeaveHeight = data.leafOffset; if (!CheckCanGenerator(x, y, z, chunk, treeHeight, treeCrownWidth, treeCrownDepth, startLeaveHeight)) { return(false); } CreateTree(x, y, z, chunk, treeHeight, treeCrownWidth, treeCrownHeight, treeCrownDepth, startLeaveHeight, random); return(true); }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { if (chunk.GetBlock(x, y, z, true).BlockType == BlockType.Air) { setBlock(chunk, x, y, z, GetDecoration()); return(true); } return(false); }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { int treeHeight = random.Range(5, 8); int treeWidth = treeHeight / 2 - 1; if (!CheckCanGenerator(x, y, z, chunk, treeHeight, treeWidth)) { return(false); } CreateTree(x, y, z, chunk, treeHeight, treeWidth, random); return(true); }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { int treeTrunkWidth = 2; int treeTrunkHeight = random.Range(5, 10); int treeHalfLeaveWidth = random.Range(2, 5); int treeLeaveHeight = random.Range(2, 5); int treeLeaveOffset = 0; if (!CheckCanGenerator(x, y, z, chunk, treeTrunkWidth, treeTrunkHeight, treeHalfLeaveWidth, treeLeaveHeight, treeLeaveOffset)) { return(false); } return(CreateTree(x, y, z, chunk, treeTrunkWidth, treeTrunkHeight, treeHalfLeaveWidth, treeLeaveHeight, treeLeaveOffset, random));; }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { if (chunk.GetBlock(x, y, z).BlockType != BlockType.Air || chunk.GetBlock(x, y + 1, z).BlockType != BlockType.Air) { return(false); } if (random.Range(0, 2) < 1) { setBlock(chunk, x, y, z, new Block(BlockType.Block_87, 1)); setBlock(chunk, x, y + 1, z, new Block(BlockType.Block_87, 2)); } else { setBlock(chunk, x, y, z, new Block(BlockType.Block_87, 3)); setBlock(chunk, x, y + 1, z, new Block(BlockType.Block_87, 4)); } return(true); }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { int height = random.Range(3, 8); int width = 2; for (int cx = 0; cx < width; cx++) { for (int cz = 0; cz < width; cz++) { if (chunk.GetBlock(cx + x, y - 1, cz + z).BlockType == BlockType.Air) { return(false); } } } for (int cy = y; cy < y + height; cy++) { for (int cx = 0; cx < width; cx++) { for (int cz = 0; cz < width; cz++) { if (chunk.GetBlock(x + cx, cy, z + cz).BlockType != BlockType.Air) { return(false); } } } } for (int cy = y; cy < y + height; cy++) { for (int cx = 0; cx < width; cx++) { for (int cz = 0; cz < width; cz++) { if (chunk.GetBlock(x + cx, cy, z + cz).BlockType == BlockType.Air) { setBlock(chunk, x + cx, cy, z + cz, new Block(BlockType.Block_31)); } } } } return(true); }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { // int height = random.Range(1,3); // int i = 0; // for (i = 0; i < height; i++) { // if(chunk.GetBlock(x,y + i,z,true).BlockType != BlockType.Air) // { // break; // } // } // if(i == height) // { // for (i = 0; i < height; i++) { // chunk.SetBlock(x,y + i,z,new Block(BlockType.Block_50)); // } // return true; // } // return false; Vector3[] posData = totalData[random.Range(0, totalData.Length)][random.Range(0, 4)]; for (int i = 0; i < posData.Length; i++) { if (chunk.GetBlock(x + (int)posData[i].x, y + (int)posData[i].y, z + (int)posData[i].z).BlockType != BlockType.Air) { return(false); } if (posData[i].y == 0) { if (chunk.GetBlock(x + (int)posData[i].x, y + (int)posData[i].y - 1, z + (int)posData[i].z).BlockType == BlockType.Air) { return(false); } } } for (int i = 0; i < posData.Length; i++) { chunk.SetBlock(x + (int)posData[i].x, y + (int)posData[i].y, z + (int)posData[i].z, new Block(BlockType.Block_50)); } return(false); }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { int treeTrunkWidth = random.Range(1, 3); int treeTrunkHeight = random.Range(2, 5); for (int cx = x; cx < x + treeTrunkWidth; cx++) { for (int cz = z; cz < z + treeTrunkWidth; cz++) { if (chunk.GetBlock(cx, y - 1, cz).BlockType == BlockType.Air) { return(false); } } } for (int cy = y; cy < y + treeTrunkHeight; cy++) { for (int cx = x; cx < x + treeTrunkWidth; cx++) { for (int cz = z; cz < z + treeTrunkWidth; cz++) { if (chunk.GetBlock(cx, cy, cz).BlockType != BlockType.Air) { return(false); } } } } for (int cy = y; cy < y + treeTrunkHeight; cy++) { for (int cx = x; cx < x + treeTrunkWidth; cx++) { for (int cz = z; cz < z + treeTrunkWidth; cz++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_19, 6)); } } } return(true); }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { MTBPlantData data = MTBPlantDataManager.Instance.getData((int)_decorationType); int[] trunktemp = data.chunkWidth; int treeTrunkWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.chunkHeight; int treeTrunkHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.leafWidth; int treeLeaveWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.leafHeight; int treeLeaveHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; int treeLeaveOffset = data.leafOffset; if (!CheckCanGenerator(x, y, z, chunk, treeTrunkWidth, treeTrunkHeight, treeLeaveWidth, treeLeaveHeight, treeLeaveOffset)) { return(false); } return(CreateTree(x, y, z, chunk, treeTrunkWidth, treeTrunkHeight, treeLeaveWidth, treeLeaveHeight, treeLeaveOffset, random)); }
private void CreateTree(Chunk chunk, IMTBRandom random, int trunkRemoveLevel, int leaveRemoveLevel, int treeTrunkStartHeight, int treeTrunkNextHeight, int treeLeaveStartHeight, int treeLeaveNextHeight, int trunkWidthStartX, int trunkWidthStartZ, int trunkWidthNextX, int trunkWidthNextZ, int leaveWidthStartX, int leaveWidthStartZ, int leaveWidthNextX, int leaveWidthNextZ) { int leaveWidthOffset = 0; for (int cy = treeLeaveStartHeight; cy < treeLeaveNextHeight; cy++) { int startX = leaveWidthStartX + leaveWidthOffset; int nextX = leaveWidthNextX - leaveWidthOffset; int startZ = leaveWidthStartZ + leaveWidthOffset; int nextZ = leaveWidthNextZ - leaveWidthOffset; int removeLevel = leaveRemoveLevel - leaveWidthOffset; for (int cx = startX; cx <= nextX; cx++) { for (int cz = startZ; cz <= nextZ; cz++) { if (Math.Abs(cx - startX) + Math.Abs(cz - startZ) <= removeLevel) { continue; } if (Math.Abs(cx - startX) + Math.Abs(cz - nextZ) <= removeLevel) { continue; } if (Math.Abs(cx - nextX) + Math.Abs(cz - startZ) <= removeLevel) { continue; } if (Math.Abs(cx - nextX) + Math.Abs(cz - nextZ) <= removeLevel) { continue; } setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_41, 4)); } } leaveWidthOffset++; } for (int cy = treeTrunkStartHeight; cy < treeTrunkNextHeight; cy++) { for (int cx = trunkWidthStartX; cx <= trunkWidthNextX; cx++) { for (int cz = trunkWidthStartZ; cz <= trunkWidthNextZ; cz++) { bool isSide = (cx == trunkWidthStartX || cx == trunkWidthNextX || cz == trunkWidthStartZ || cz == trunkWidthNextZ); bool isEqualLevel = false; bool isGreatLevel = true; int disLevel; disLevel = Math.Abs(cx - trunkWidthStartX) + Math.Abs(cz - trunkWidthStartZ); isEqualLevel |= ((disLevel == trunkRemoveLevel) || (disLevel == trunkRemoveLevel - 1)); isGreatLevel &= (disLevel > trunkRemoveLevel); disLevel = Math.Abs(cx - trunkWidthStartX) + Math.Abs(cz - trunkWidthNextZ); isEqualLevel |= ((disLevel == trunkRemoveLevel) || (disLevel == trunkRemoveLevel - 1)); isGreatLevel &= (disLevel > trunkRemoveLevel); disLevel = Math.Abs(cx - trunkWidthNextX) + Math.Abs(cz - trunkWidthStartZ); isEqualLevel |= ((disLevel == trunkRemoveLevel) || (disLevel == trunkRemoveLevel - 1)); isGreatLevel &= (disLevel > trunkRemoveLevel); disLevel = Math.Abs(cx - trunkWidthNextX) + Math.Abs(cz - trunkWidthNextZ); isEqualLevel |= ((disLevel == trunkRemoveLevel) || (disLevel == trunkRemoveLevel - 1)); isGreatLevel &= (disLevel > trunkRemoveLevel); if (isEqualLevel || (isSide && isGreatLevel)) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_19, 4)); } } } } }
private void CreateTree(int x, int y, int z, Chunk chunk, int treeHeight, int treeWidth, IMTBRandom random) { int leaveWidth = random.Range(1, 3); for (int cx = x - treeWidth; cx <= x + treeWidth; cx++) { for (int cz = z - treeWidth; cz <= z + treeWidth; cz++) { int xDis = Math.Abs(cx - x); int zDis = Math.Abs(cz - z); int dis = xDis + zDis; int curHeight = treeHeight - dis * 2; int yMaxHeight = y + dis + curHeight; if (xDis <= leaveWidth || zDis <= leaveWidth) { setBlock(chunk, cx, y + treeHeight - 1, cz, new Block(BlockType.Block_45)); } if (curHeight < 2) { continue; } for (int cy = y + dis; cy < yMaxHeight; cy++) { if (cy != yMaxHeight - 1 || dis != 0) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_44)); } } } } }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { int width = random.Range(1, 3); int height = 6; for (int cy = y; cy < y + height; cy++) { for (int cx = -width; cx <= width; cx++) { for (int cz = -width; cz <= width; cz++) { if (chunk.GetBlock(cx, cy, cz).BlockType != BlockType.Air) { return(false); } } } } _spreadQueue.Clear(); setBlock(chunk, x, y, z, new Block(BlockType.Block_11)); _spreadQueue.Enqueue(new WorldPos(x, y, z)); int spreadRate = 10; int heightSpreadRate = 40; int nextX; int nextY; int nextZ; while (_spreadQueue.Count > 0) { WorldPos pos = _spreadQueue.Dequeue(); nextX = pos.x; nextY = pos.y; nextZ = pos.z; nextX -= 1; if (nextX >= x - width && chunk.GetBlock(nextX, nextY, nextZ).BlockType == BlockType.Air) { if (random.Range(0, 100) < spreadRate) { setBlock(chunk, nextX, nextY, nextZ, new Block(BlockType.Block_11)); _spreadQueue.Enqueue(new WorldPos(nextX, nextY, nextZ)); } } nextX = pos.x; nextY = pos.y; nextZ = pos.z; nextX += 1; if (nextX <= x + width && chunk.GetBlock(nextX, nextY, nextZ).BlockType == BlockType.Air) { if (random.Range(0, 100) < spreadRate) { setBlock(chunk, nextX, nextY, nextZ, new Block(BlockType.Block_11)); _spreadQueue.Enqueue(new WorldPos(nextX, nextY, nextZ)); } } nextX = pos.x; nextY = pos.y; nextZ = pos.z; nextY -= 1; if (nextY >= y && chunk.GetBlock(nextX, nextY, nextZ).BlockType == BlockType.Air) { if (random.Range(0, 100) < spreadRate) { setBlock(chunk, nextX, nextY, nextZ, new Block(BlockType.Block_11)); _spreadQueue.Enqueue(new WorldPos(nextX, nextY, nextZ)); } } nextX = pos.x; nextY = pos.y; nextZ = pos.z; nextY += 1; if (nextY < y + height && chunk.GetBlock(nextX, nextY, nextZ).BlockType == BlockType.Air) { if (random.Range(0, 100) < heightSpreadRate) { setBlock(chunk, nextX, nextY, nextZ, new Block(BlockType.Block_11)); _spreadQueue.Enqueue(new WorldPos(nextX, nextY, nextZ)); } } nextX = pos.x; nextY = pos.y; nextZ = pos.z; nextZ -= 1; if (nextZ >= z - width && chunk.GetBlock(nextX, nextY, nextZ).BlockType == BlockType.Air) { if (random.Range(0, 100) < spreadRate) { setBlock(chunk, nextX, nextY, nextZ, new Block(BlockType.Block_11)); _spreadQueue.Enqueue(new WorldPos(nextX, nextY, nextZ)); } } nextX = pos.x; nextY = pos.y; nextZ = pos.z; nextZ += 1; if (nextZ <= z + width && chunk.GetBlock(nextX, nextY, nextZ).BlockType == BlockType.Air) { if (random.Range(0, 100) < 60) { setBlock(chunk, nextX, nextY, nextZ, new Block(BlockType.Block_11)); _spreadQueue.Enqueue(new WorldPos(nextX, nextY, nextZ)); } } } return(true); }
private void CreateTree(int x, int y, int z, Chunk chunk, int treeHeight, int treeCrownWidth, int treeCrownHeight, int treeCrownDepth, int startLeaveHeight, IMTBRandom random) { int crownHeight = y + treeHeight - treeCrownHeight; int endLeaveHeight = y + crownHeight - startLeaveHeight; int realHeight = y + treeHeight; for (int cy = y; cy < realHeight; cy++) { if (cy < crownHeight) { setBlock(chunk, x, cy, z, new Block(BlockType.Block_40)); if (cy <= endLeaveHeight && cy >= startLeaveHeight) { setBlock(chunk, x, cy, z, new Block(BlockType.Block_40)); if (random.Range(0, 3) < 1) { int pos = random.Range(0, 4); switch (pos) { case 0: setBlock(chunk, x + 1, cy, z, new Block(BlockType.Block_41)); break; case 1: setBlock(chunk, x - 1, cy, z, new Block(BlockType.Block_41)); break; case 2: setBlock(chunk, x, cy, z + 1, new Block(BlockType.Block_41)); break; default: setBlock(chunk, x, cy, z - 1, new Block(BlockType.Block_41)); break; } } } continue; } for (int cx = x - treeCrownWidth; cx <= x + treeCrownWidth; cx++) { for (int cz = z - treeCrownDepth; cz <= z + treeCrownDepth; cz++) { if (cx == x && cz == z && cy < realHeight - 1) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_40)); continue; } setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_41)); } } } int unfilledCornerNum = random.Range(2, 8); int halfCrownHeight = Mathf.FloorToInt(treeCrownHeight / 2); for (int i = 0; i < unfilledCornerNum; i++) { int corner = random.Range(0, 8); if (!corners.Contains(corner)) { corners.Add(corner); int cornerWidth = random.Range(1, treeCrownWidth + 1) - 1; int cornerHeight = random.Range(1, halfCrownHeight); int cornerDepth = random.Range(1, treeCrownDepth + 1) - 1; switch (corner) { case 0: for (int cx = x - treeCrownWidth; cx <= x - treeCrownWidth + cornerWidth; cx++) { for (int cz = z + treeCrownDepth - cornerDepth; cz <= z + treeCrownDepth; cz++) { for (int cy = crownHeight + treeCrownHeight - cornerHeight; cy <= crownHeight + treeCrownHeight; cy++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Air)); } } } break; case 1: for (int cx = x + treeCrownWidth - cornerWidth; cx <= x + treeCrownWidth; cx++) { for (int cz = z + treeCrownDepth - cornerDepth; cz <= z + treeCrownDepth; cz++) { for (int cy = crownHeight + treeCrownHeight - cornerHeight; cy <= crownHeight + treeCrownHeight; cy++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Air)); } } } break; case 2: for (int cx = x + treeCrownWidth - cornerWidth; cx <= x + treeCrownWidth; cx++) { for (int cz = z - treeCrownDepth; cz <= z - treeCrownDepth + cornerDepth; cz++) { for (int cy = crownHeight + treeCrownHeight - cornerHeight; cy <= crownHeight + treeCrownHeight; cy++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Air)); } } } break; case 3: for (int cx = x - treeCrownWidth; cx <= x - treeCrownWidth + cornerWidth; cx++) { for (int cz = z - treeCrownDepth; cz <= z - treeCrownDepth + cornerDepth; cz++) { for (int cy = crownHeight + treeCrownHeight - cornerHeight; cy <= crownHeight + treeCrownHeight; cy++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Air)); } } } break; case 4: for (int cx = x - treeCrownWidth; cx <= x - treeCrownWidth + cornerWidth; cx++) { for (int cz = z + treeCrownDepth - cornerDepth; cz <= z + treeCrownDepth; cz++) { for (int cy = crownHeight; cy <= crownHeight + cornerHeight; cy++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Air)); } } } break; case 5: for (int cx = x + treeCrownWidth - cornerWidth; cx <= x + treeCrownWidth; cx++) { for (int cz = z + treeCrownDepth - cornerDepth; cz <= z + treeCrownDepth; cz++) { for (int cy = crownHeight; cy <= crownHeight + cornerHeight; cy++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Air)); } } } break; case 6: for (int cx = x + treeCrownWidth - cornerWidth; cx <= x + treeCrownWidth; cx++) { for (int cz = z - treeCrownDepth; cz <= z - treeCrownDepth + cornerDepth; cz++) { for (int cy = crownHeight; cy <= crownHeight + cornerHeight; cy++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Air)); } } } break; default: for (int cx = x - treeCrownWidth; cx <= x - treeCrownWidth + cornerWidth; cx++) { for (int cz = z - treeCrownDepth; cz <= z - treeCrownDepth + cornerDepth; cz++) { for (int cy = crownHeight; cy <= crownHeight + cornerHeight; cy++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Air)); } } } break; } } } }
private bool CreateTree(int x, int y, int z, Chunk chunk, int treeTrunkWidth, int treeTrunkHeight, int treeHalfLeaveWidth, int treeLeaveHeight, int treeLeaveOffset, IMTBRandom random) { int treeLeaveStartHeight = y + treeTrunkHeight + treeLeaveOffset - 1; int treeTopHeight = treeLeaveStartHeight + treeLeaveHeight; int rate = 10; int nextXWidth = x + treeHalfLeaveWidth; int nextZWidth = z + treeHalfLeaveWidth; int startXWidth = x - treeHalfLeaveWidth; int startZWidth = z - treeHalfLeaveWidth; for (int cy = treeLeaveStartHeight; cy < treeTopHeight; cy++) { for (int cx = startXWidth; cx <= nextXWidth; cx++) { for (int cz = startZWidth; cz <= nextZWidth; cz++) { int dis = Math.Abs(cx - x) + Math.Abs(cz - z); if (random.Range(0, 100) < rate * (dis * 1.5f)) { continue; } setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_41, 5)); } } // for (int cx = startXWidth; cx <= nextXWidth; cx++) { // if(chunk.GetBlock(cx,cy,startZWidth).BlockType == BlockType.Air)continue; // if(random.Range(0,100) < rate)chunk.SetBlock(cx,cy,startZWidth,new Block(BlockType.Air)); // else break; // } // for (int cx = startXWidth; cx <= nextXWidth; cx++) { // if(chunk.GetBlock(cx,cy,nextZWidth).BlockType == BlockType.Air)continue; // if(random.Range(0,100) < rate)chunk.SetBlock(cx,cy,nextZWidth,new Block(BlockType.Air)); // else break; // } // for (int cx = nextXWidth; cx >= startXWidth; cx--) { // if(chunk.GetBlock(cx,cy,startZWidth).BlockType == BlockType.Air)continue; // if(random.Range(0,100) < rate)chunk.SetBlock(cx,cy,startZWidth,new Block(BlockType.Air)); // else break; // } // for (int cx = nextXWidth; cx >= startXWidth; cx--) { // if(chunk.GetBlock(cx,cy,nextZWidth).BlockType == BlockType.Air)continue; // if(random.Range(0,100) < rate)chunk.SetBlock(cx,cy,nextZWidth,new Block(BlockType.Air)); // else break; // } // // for (int cz = startZWidth; cz <= nextZWidth; cz++) { // if(chunk.GetBlock(startXWidth,cy,cz).BlockType == BlockType.Air)continue; // if(random.Range(0,100) < rate)chunk.SetBlock(startXWidth,cy,cz,new Block(BlockType.Air)); // else break; // } // // for (int cz = startZWidth; cz <= nextZWidth; cz++) { // if(chunk.GetBlock(nextXWidth,cy,cz).BlockType == BlockType.Air)continue; // if(random.Range(0,100) < rate)chunk.SetBlock(nextXWidth,cy,cz,new Block(BlockType.Air)); // else break; // } // for (int cz = nextZWidth; cz >= startZWidth; cz--) { // if(chunk.GetBlock(startXWidth,cy,cz).BlockType == BlockType.Air)continue; // if(random.Range(0,100) < rate)chunk.SetBlock(startXWidth,cy,cz,new Block(BlockType.Air)); // else break; // } // for (int cz = nextZWidth; cz >= startZWidth; cz--) { // if(chunk.GetBlock(nextXWidth,cy,cz).BlockType == BlockType.Air)continue; // if(random.Range(0,100) < rate)chunk.SetBlock(nextXWidth,cy,cz,new Block(BlockType.Air)); // else break; // } } for (int cy = y; cy < y + treeTrunkHeight - 1; cy++) { setBlock(chunk, x, cy, z, new Block(BlockType.Block_19, 5)); } return(true); }
public PopulationControlGenerator() { _random = new MTBRandom(); _biomes = new List <int>(20); heightCap = WorldConfig.Instance.heightCap; }
private bool CreateTree(int x, int y, int z, Chunk chunk, int treeTrunkWidth, int treeTrunkHeight, int treeLeaveWidth, int treeLeaveHeight, int treeLeaveOffset, IMTBRandom random) { int treeLeaveStartHeight = y + treeTrunkHeight + treeLeaveOffset - 1; int halfTreeLeaveWidth = treeLeaveWidth / 2; int treeTopHeight = treeLeaveStartHeight + treeLeaveHeight; int leaveWidth = halfTreeLeaveWidth; int baseRate = 15; for (int cy = treeLeaveStartHeight; cy < treeTopHeight; cy++) { int nextXWidth = x + leaveWidth + 1; int nextZWidth = z + leaveWidth + 1; int startXWidth = x - leaveWidth; int startZWidth = z - leaveWidth; for (int cx = startXWidth; cx <= nextXWidth; cx++) { for (int cz = startZWidth; cz <= nextZWidth; cz++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_41, 3)); } } int rate = (int)(baseRate * (1f + ((float)leaveWidth * 2.5f) / halfTreeLeaveWidth)); if (leaveWidth > 0) { for (int cx = startXWidth; cx <= nextXWidth; cx++) { if (chunk.GetBlock(cx, cy, startZWidth).BlockType == BlockType.Air) { continue; } if (random.Range(0, 100) < rate) { setBlock(chunk, cx, cy, startZWidth, new Block(BlockType.Air)); } else { break; } } for (int cx = startXWidth; cx <= nextXWidth; cx++) { if (chunk.GetBlock(cx, cy, nextZWidth).BlockType == BlockType.Air) { continue; } if (random.Range(0, 100) < rate) { setBlock(chunk, cx, cy, nextZWidth, new Block(BlockType.Air)); } else { break; } } for (int cx = nextXWidth; cx >= startXWidth; cx--) { if (chunk.GetBlock(cx, cy, startZWidth).BlockType == BlockType.Air) { continue; } if (random.Range(0, 100) < rate) { setBlock(chunk, cx, cy, startZWidth, new Block(BlockType.Air)); } else { break; } } for (int cx = nextXWidth; cx >= startXWidth; cx--) { if (chunk.GetBlock(cx, cy, nextZWidth).BlockType == BlockType.Air) { continue; } if (random.Range(0, 100) < rate) { setBlock(chunk, cx, cy, nextZWidth, new Block(BlockType.Air)); } else { break; } } for (int cz = startZWidth; cz <= nextZWidth; cz++) { if (chunk.GetBlock(startXWidth, cy, cz).BlockType == BlockType.Air) { continue; } if (random.Range(0, 100) < rate) { setBlock(chunk, startXWidth, cy, cz, new Block(BlockType.Air)); } else { break; } } for (int cz = startZWidth; cz <= nextZWidth; cz++) { if (chunk.GetBlock(nextXWidth, cy, cz).BlockType == BlockType.Air) { continue; } if (random.Range(0, 100) < rate) { setBlock(chunk, nextXWidth, cy, cz, new Block(BlockType.Air)); } else { break; } } for (int cz = nextZWidth; cz >= startZWidth; cz--) { if (chunk.GetBlock(startXWidth, cy, cz).BlockType == BlockType.Air) { continue; } if (random.Range(0, 100) < rate) { setBlock(chunk, startXWidth, cy, cz, new Block(BlockType.Air)); } else { break; } } for (int cz = nextZWidth; cz >= startZWidth; cz--) { if (chunk.GetBlock(nextXWidth, cy, cz).BlockType == BlockType.Air) { continue; } if (random.Range(0, 100) < rate) { setBlock(chunk, nextXWidth, cy, cz, new Block(BlockType.Air)); } else { break; } } } if (random.Range(0, 100) > 20) { leaveWidth--; } if (leaveWidth < 0) { break; } } for (int cy = y; cy < y + treeTrunkHeight - 1; cy++) { for (int cx = x; cx < x + treeTrunkWidth; cx++) { for (int cz = z; cz < z + treeTrunkWidth; cz++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_19, 3)); } } } return(true); }
public PlantManager() { _random = new MTBRandom(); _plantMap = new Dictionary <int, GrowDecoration>(new PlantComparer()); _mapInChunk = new Dictionary <WorldPos, List <GrowDecoration> >(new WorldPosComparer()); }
public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random) { MTBPlantData data = MTBPlantDataManager.Instance.getData((int)_decorationType); int[] trunktemp = data.chunkWidth; int treeTrunkWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.chunkHeight; int treeTrunkHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.leafWidth; int treeLeaveWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; trunktemp = data.leafHeight; int treeLeaveHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0]; int treeLeaveOffset = data.leafOffset; int treeHeight = treeTrunkHeight + treeLeaveHeight + treeLeaveOffset; int treeTrunkStartHeight = y; int treeTrunkNextHeight = y + treeTrunkHeight; int treeLeaveStartHeight = y + treeTrunkHeight + treeLeaveOffset; int treeLeaveNextHeight = treeLeaveStartHeight + treeLeaveHeight; bool isTrunkWidthEvenNum = (treeTrunkWidth % 2 == 0); bool isLeaveWidthEvenNum = (treeLeaveWidth % 2 == 0); //调整树叶宽度 if (isTrunkWidthEvenNum != isLeaveWidthEvenNum) { treeLeaveWidth++; isLeaveWidthEvenNum = !isLeaveWidthEvenNum; } int halfTreeTrunkWidth = treeTrunkWidth / 2; int trunkWidthStartX; int trunkWidthStartZ; int trunkWidthNextX; int trunkWidthNextZ; trunkWidthStartX = x - halfTreeTrunkWidth; trunkWidthStartZ = z - halfTreeTrunkWidth; trunkWidthNextX = x + halfTreeTrunkWidth; trunkWidthNextZ = z + halfTreeTrunkWidth; if (isTrunkWidthEvenNum) { trunkWidthNextX -= 1; trunkWidthNextZ -= 1; } int halfTreeLeaveWidth = treeLeaveWidth / 2; int leaveWidthStartX; int leaveWidthStartZ; int leaveWidthNextX; int leaveWidthNextZ; leaveWidthStartX = x - halfTreeLeaveWidth; leaveWidthStartZ = z - halfTreeLeaveWidth; leaveWidthNextX = x + halfTreeLeaveWidth; leaveWidthNextZ = z + halfTreeLeaveWidth; if (isLeaveWidthEvenNum) { leaveWidthNextX -= 1; leaveWidthNextZ -= 1; } if (!CheckCanGenerator(chunk, treeTrunkStartHeight, treeTrunkNextHeight, treeLeaveStartHeight, treeLeaveNextHeight, trunkWidthStartX, trunkWidthStartZ, trunkWidthNextX, trunkWidthNextZ, leaveWidthStartX, leaveWidthStartZ, leaveWidthNextX, leaveWidthNextZ)) { return(false); } CreateTree(chunk, random, halfTreeTrunkWidth / 2 + 1, halfTreeLeaveWidth / 2, treeTrunkStartHeight, treeTrunkNextHeight, treeLeaveStartHeight, treeLeaveNextHeight, trunkWidthStartX, trunkWidthStartZ, trunkWidthNextX, trunkWidthNextZ, leaveWidthStartX, leaveWidthStartZ, leaveWidthNextX, leaveWidthNextZ); return(true); }
private bool CreateTree(int x, int y, int z, Chunk chunk, int treeTrunkWidth, int treeTrunkHeight, int treeHalfLeaveWidth, int treeLeaveHeight, int treeLeaveOffset, IMTBRandom random) { int treeLeaveStartHeight = y + treeTrunkHeight + treeLeaveOffset - 1; int treeTopHeight = treeLeaveStartHeight + treeLeaveHeight; _spreadQueue.Clear(); for (int cx = x; cx < x + treeTrunkWidth; cx++) { for (int cz = z; cz < z + treeTrunkWidth; cz++) { setBlock(chunk, cx, treeLeaveStartHeight, cz, new Block(BlockType.Block_28)); } } setBlock(chunk, x - 1, treeLeaveStartHeight, z, new Block(BlockType.Block_28)); _spreadQueue.Enqueue(new WorldPos(x - 1, treeLeaveStartHeight, z)); setBlock(chunk, x + 1, treeLeaveStartHeight, z - 1, new Block(BlockType.Block_28)); _spreadQueue.Enqueue(new WorldPos(x + 1, treeLeaveStartHeight, z - 1)); setBlock(chunk, x + 2, treeLeaveStartHeight, z + 1, new Block(BlockType.Block_28)); _spreadQueue.Enqueue(new WorldPos(x + 2, treeLeaveStartHeight, z + 1)); setBlock(chunk, x, treeLeaveStartHeight, z + 2, new Block(BlockType.Block_28)); _spreadQueue.Enqueue(new WorldPos(x, treeLeaveStartHeight, z + 2)); int nextX; int nextY; int nextZ; while (_spreadQueue.Count > 0) { WorldPos pos = _spreadQueue.Dequeue(); int spreadNum = random.Range(0, 4); for (int i = 0; i < spreadNum; i++) { int direct = random.Range(0, 6); switch (direct) { case 0: nextX = pos.x - 1; nextY = pos.y; nextZ = pos.z; break; case 1: nextX = pos.x + 1; nextY = pos.y; nextZ = pos.z; break; case 2: nextX = pos.x; nextY = pos.y; nextZ = pos.z - 1; break; case 3: nextX = pos.x; nextY = pos.y; nextZ = pos.z + 1; break; default: nextX = pos.x; nextY = pos.y + 1; nextZ = pos.z; break; } if (nextX < x - treeHalfLeaveWidth || nextX > x + treeHalfLeaveWidth || nextZ < z - treeHalfLeaveWidth || nextZ > z + treeHalfLeaveWidth || nextY >= treeTopHeight || chunk.GetBlock(nextX, nextY, nextZ).BlockType != BlockType.Air) { continue; } // int num = CheckAroundNum(chunk,nextX,nextY,nextZ); // if(num > 2)continue; setBlock(chunk, nextX, nextY, nextZ, new Block(BlockType.Block_28)); _spreadQueue.Enqueue(new WorldPos(nextX, nextY, nextZ)); } } for (int cy = y; cy < y + treeTrunkHeight - 1; cy++) { for (int cx = x; cx < x + treeTrunkWidth; cx++) { for (int cz = z; cz < z + treeTrunkWidth; cz++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_28)); } } } return(true); }
private bool CreateTree(int x, int y, int z, Chunk chunk, int treeTrunkWidth, int treeTrunkHeight, int treeHalfLeaveWidth, int treeLeaveHeight, int treeLeaveOffset, IMTBRandom random) { int treeLeaveStartHeight = y + treeTrunkHeight + treeLeaveOffset - 1; int treeTopHeight = treeLeaveStartHeight + treeLeaveHeight; int startXWidth = x - treeHalfLeaveWidth; int startZWidth = z - treeHalfLeaveWidth; int nextXWidth = x + treeHalfLeaveWidth + 1; int nextZWidth = z + treeHalfLeaveWidth + 1; for (int cy = treeLeaveStartHeight; cy < treeTopHeight; cy++) { for (int cx = startXWidth; cx <= nextXWidth; cx++) { for (int cz = startZWidth; cz <= nextZWidth; cz++) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_41, 7)); } } } int randomNum = random.Range(1, treeHalfLeaveWidth * treeHalfLeaveWidth * 2); int maxHeight = treeTrunkHeight + treeLeaveOffset; if (maxHeight > 1) { for (int i = 0; i < randomNum; i++) { int randX = random.Range(startXWidth, nextXWidth + 1); int randZ = random.Range(startZWidth, nextZWidth + 1); if ((randX < x - 1 || randX > x + 2) || (randZ < z - 1 || randZ > z + 2)) { if (chunk.GetBlock(randX, treeLeaveStartHeight - 1, randZ).BlockType != BlockType.Air) { continue; } int num = random.Range(0, maxHeight - 1); for (int j = 0; j < num; j++) { setBlock(chunk, randX, treeLeaveStartHeight - 1 - j, randZ, new Block(BlockType.Block_41, 7)); } } } } for (int cy = y; cy < y + treeTrunkHeight - 1; cy++) { for (int cx = x; cx < x + treeTrunkWidth; cx++) { for (int cz = z; cz < z + treeTrunkWidth; cz++) { if (y < treeLeaveStartHeight && random.Range(0, 100) < 5) { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_84)); } else { setBlock(chunk, cx, cy, cz, new Block(BlockType.Block_19, 7)); } } } } return(true); }
private bool CreateTree(int x, int y, int z, Chunk chunk, int treeTrunkWidth, int treeTrunkHeight, int treeLeaveWidth, int treeLeaveHeight, int treeLeaveOffset, IMTBRandom random) { int halfTreeLeaveWidth = treeLeaveWidth / 2; int treeLeaveTopY = treeLeaveHeight + treeLeaveOffset + treeTrunkHeight - 1 + y; int treeLeaveStartY = treeLeaveTopY - halfTreeLeaveWidth; _spreadQueue.Clear(); Block curBlock = chunk.GetBlock(x, treeLeaveStartY, z); if (curBlock.BlockType == BlockType.Air) { setBlock(chunk, x, treeLeaveStartY, z, new Block(BlockType.Block_41, 2)); } WorldPos startPos = new WorldPos(x, treeLeaveStartY, z); _spreadQueue.Enqueue(startPos); while (_spreadQueue.Count > 0) { WorldPos pos = _spreadQueue.Dequeue(); TreeLeaveSpread(chunk, pos.x + 1, pos.y, pos.z, _spreadQueue, halfTreeLeaveWidth, treeLeaveTopY, treeLeaveHeight, startPos); TreeLeaveSpread(chunk, pos.x - 1, pos.y, pos.z, _spreadQueue, halfTreeLeaveWidth, treeLeaveTopY, treeLeaveHeight, startPos); TreeLeaveSpread(chunk, pos.x, pos.y + 1, pos.z, _spreadQueue, halfTreeLeaveWidth, treeLeaveTopY, treeLeaveHeight, startPos); TreeLeaveSpread(chunk, pos.x, pos.y - 1, pos.z, _spreadQueue, halfTreeLeaveWidth, treeLeaveTopY, treeLeaveHeight, startPos); TreeLeaveSpread(chunk, pos.x, pos.y, pos.z + 1, _spreadQueue, halfTreeLeaveWidth, treeLeaveTopY, treeLeaveHeight, startPos); TreeLeaveSpread(chunk, pos.x, pos.y, pos.z - 1, _spreadQueue, halfTreeLeaveWidth, treeLeaveTopY, treeLeaveHeight, startPos); } bool hasFaceBlock = random.Range(0, 100) < 50; int faceBlock = random.Range(0, treeTrunkHeight); for (int i = 0; i < treeTrunkHeight; i++) { if (hasFaceBlock && faceBlock == i) { setBlock(chunk, x, y + i, z, new Block(BlockType.Block_75, (byte)random.Range(0, 4)), true); } else { setBlock(chunk, x, y + i, z, new Block(BlockType.Block_19, 2), true); } } return(true); }