3D biomes
This commit is contained in:
@@ -7,7 +7,7 @@ import { assert, assertEquals } from "@std/assert";
|
||||
import { CHUNK_AREA } from "@/common/constants.ts";
|
||||
import { decode_level_chunk, encode_level_chunk, is_within_view } from "@/common/chunk_streaming.ts";
|
||||
import { PROTOCOL_VERSION } from "@/common/protocol.ts";
|
||||
import { ChunkColumn, section_index, to_flat } from "@/common/section.ts";
|
||||
import { BIOME_CELL_HEIGHT, ChunkColumn, section_index, to_flat } from "@/common/section.ts";
|
||||
import { WorldShape } from "@/common/world_shape.ts";
|
||||
import { sent_block, test_game } from "./helpers.ts";
|
||||
|
||||
@@ -22,22 +22,31 @@ Deno.test("a chunk comes back as it was encoded, whatever its sections hold", ()
|
||||
blocks[2 * section + i] = i % 16;
|
||||
blocks[3 * section + i] = (i % 300) | ((i % 7) << 16);
|
||||
}
|
||||
const biomes = Array.from({ length: CHUNK_AREA }, (_, i) => i < 100 ? "bworld:plains" : "bworld:desert");
|
||||
const shape = new WorldShape({ min_y: -64, max_y: 320, sky_light: true });
|
||||
// two biomes across, and a third in the cells from the 40th up
|
||||
const biomes = Array.from(
|
||||
{ length: shape.volume / BIOME_CELL_HEIGHT },
|
||||
(_, i) => i >= 40 * CHUNK_AREA ? "test:caves" : i % CHUNK_AREA < 100 ? "bworld:plains" : "bworld:desert",
|
||||
);
|
||||
|
||||
const decoded = decode_level_chunk(encode_level_chunk(ChunkColumn.from_flat(-3, 70000, shape, blocks, biomes)));
|
||||
const column = ChunkColumn.from_flat(-3, 70000, shape, blocks, biomes);
|
||||
const decoded = decode_level_chunk(encode_level_chunk(column));
|
||||
assertEquals(decoded.x, -3);
|
||||
assertEquals(decoded.z, 70000);
|
||||
assertEquals(to_flat(decoded.sections), blocks);
|
||||
assertEquals(decoded.sections.map((section) => section.blocks === null).indexOf(false), 1, "uniform ones stay so");
|
||||
assertEquals(decoded.biomes, biomes);
|
||||
assertEquals(decoded.biomes, column.biomes);
|
||||
const back = new ChunkColumn(-3, 70000, shape, decoded.sections, decoded.biomes);
|
||||
assertEquals(back.biome_at(-48 + 3, 95, 70000 * 16 + 2), "bworld:plains");
|
||||
assertEquals(back.biome_at(-48 + 3, 96, 70000 * 16 + 2), "test:caves");
|
||||
|
||||
// one biome, and the receiver's numbering
|
||||
const one = decode_level_chunk(
|
||||
encode_level_chunk(ChunkColumn.from_flat(0, 0, shape, blocks, biomes.map(() => "bworld:plains"))),
|
||||
encode_level_chunk(ChunkColumn.from_flat(0, 0, shape, blocks, new Array(CHUNK_AREA).fill("bworld:plains"))),
|
||||
(value) => value === 7 ? 70 : value,
|
||||
);
|
||||
assertEquals(one.biomes, biomes.map(() => "bworld:plains"));
|
||||
assertEquals(one.biomes.palette, ["bworld:plains"]);
|
||||
assertEquals(one.biomes.sections, new Array(24).fill(0));
|
||||
assertEquals(one.sections[0].value, 70);
|
||||
assertEquals(one.sections[1].get(0), 1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user