private void GenerateEntity(Chunk chunk, BiomeConfig biomeConfig) { for (int i = 0; i < biomeConfig.entityParams.Count; i++) { EntityParam entityParam = biomeConfig.entityParams[i]; if (_random.Range(0, 100) < entityParam.productRate) { for (int j = 0; j < entityParam.maxNum; j++) { int x = _random.Range(1, Chunk.chunkWidth - 1); int z = _random.Range(1, Chunk.chunkDepth - 1); if (chunk.GetBiomeId(x, z, true) != biomeConfig.biomeId) { continue; } DispatchEntity(chunk, x, z, entityParam); } } } }
private void DispatchEntity(Chunk chunk, int x, int z, EntityParam entityParam) { int height = entityParam.maxEntityHeight < heightCap ? entityParam.maxEntityHeight : heightCap; for (int y = height - 1; y >= entityParam.minEntityHeight; y--) { BlockType curType = chunk.GetBlock(x, y, z).BlockType; if (curType != BlockType.Air && curType != BlockType.StillWater) { List <CheckCondition> conditions = entityParam.checkConditions; bool canDecorate = CheckConditionMeet(chunk, conditions, x, y, z); //bool lightCondiciont = CheckLightCondition(chunk, entityParam.lightCondition, x, y, z); if (canDecorate) { EntityData data = new EntityData(); data.id = entityParam.entityId; data.type = EntityType.MONSTER; data.pos = new Vector3(chunk.worldPos.x + x, chunk.worldPos.y + y + 1, chunk.worldPos.z + z); chunk.AddEntityData(data); return; } } } }