/* * Calls load_grid around () {x: 0, z: 0}, and attempts to find a suitable * spawn position. */ void world::prepare_spawn (int diameter, bool calc_spawn_point) { this->load_grid (chunk_pos (this->spawn_pos), diameter); if (calc_spawn_point) { block_pos best {0, 0, 0}; int cx, cz, x, z; short h; for (cx = 0; cx <= 2; ++cx) for (cz = 0; cz <= 2; ++cz) { chunk *ch = this->load_chunk (cx, cz); for (x = 0; x < 16; ++x) for (z = 0; z < 16; ++z) { h = ch->get_height (x, z); if (ch->get_id (x, h - 1, z) != 0 && ((h + 1) > best.y)) best.set ((cx * 16) + x, h + 1, (cz * 16) + z); } } this->spawn_pos = best; } }
Block WorldCache::getBlock(const mc::BlockPos& pos, const mc::Chunk* chunk, int get) { // this can happen when we check for the bottom block shadow edges if (pos.y < 0) return Block(); mc::ChunkPos chunk_pos(pos); const mc::Chunk* mychunk = chunk; if (chunk == nullptr || chunk_pos != chunk->getPos()) mychunk = getChunk(chunk_pos); // chunk may be nullptr if (mychunk == nullptr) { return Block(); // otherwise get all required block data } else { mc::LocalBlockPos local(pos); Block block; if (get & GET_ID) block.id = mychunk->getBlockID(local); if (get & GET_DATA) block.data = mychunk->getBlockData(local); if (get & GET_BIOME) block.biome = mychunk->getBiomeAt(local); if (get & GET_BLOCK_LIGHT) block.block_light = mychunk->getBlockLight(local); if (get & GET_SKY_LIGHT) block.sky_light = mychunk->getSkyLight(local); return block; } }
Biome TileRenderer::getBiomeOfBlock(const mc::BlockPos& pos, const mc::Chunk* chunk) { // return default biome if we don't want to render different biomes if (!render_biomes) return getBiome(DEFAULT_BIOME); uint8_t biome_id = chunk->getBiomeAt(mc::LocalBlockPos(pos)); Biome biome = getBiome(biome_id); int count = 1; // get average biome data to make smooth edges between // different biomes for (int dx = -1; dx <= 1; dx++) for (int dz = -1; dz <= 1; dz++) { if (dx == 0 && dz == 0) continue; mc::BlockPos other = pos + mc::BlockPos(dx, dz, 0); mc::ChunkPos chunk_pos(other); uint8_t other_id = chunk->getBiomeAt(mc::LocalBlockPos(other)); if (chunk_pos != chunk->getPos()) { mc::Chunk* other_chunk = state.world->getChunk(chunk_pos); if (other_chunk == nullptr) continue; other_id = other_chunk->getBiomeAt(mc::LocalBlockPos(other)); } biome += getBiome(other_id); count++; } biome /= count; return biome; }