fix old test
This commit is contained in:
@@ -11,7 +11,7 @@ import { DEFAULT_SHAPE, WorldShape } from "@/common/world_shape.ts";
|
||||
import { biome_in, ChunkColumn, column_biomes, section_index, to_flat } from "@/common/section.ts";
|
||||
import { Writer } from "@/common/bytes.ts";
|
||||
|
||||
// a chunk at the height of the base game's dimension, which the test worlds play
|
||||
// a chunk 0 to 256 high, or of another shape
|
||||
function chunk_data(seed: number, palette_size = 3, shape = DEFAULT_SHAPE): Required<ChunkBlocks> {
|
||||
const palette: [string, number][] = [];
|
||||
for (let i = 0; i < palette_size; i++) palette.push([`test:block_${i}`, i % 5]);
|
||||
@@ -30,10 +30,11 @@ function set_saved_block(chunk: ChunkBlocks, x: number, y: number, z: number, in
|
||||
chunk.sections[(y - chunk.min_y) >> 4].set(section_index(x, y, z), index);
|
||||
}
|
||||
|
||||
// a chunk as formats 1 and 2 saved it, 0 to 256 high and big-endian. format 1 had no biomes, and a bit per block after
|
||||
// the blocks instead, for whether world generation made it
|
||||
// a chunk's part from 0 to 256 as formats 1 and 2 saved it, big-endian. format 1 had no biomes, and a bit per block
|
||||
// after the blocks instead, for whether world generation made it
|
||||
function old_format(format: 1 | 2, chunk: ChunkBlocks) {
|
||||
const flat = to_flat(chunk.sections);
|
||||
const bottom = -chunk.min_y >> 4;
|
||||
const flat = to_flat(chunk.sections.slice(bottom, bottom + 16));
|
||||
const wide = chunk.palette.length > 256;
|
||||
const bytes: number[] = [format, ...u32(chunk.palette.length)];
|
||||
for (const [id, state] of chunk.palette) bytes.push(...string(id), state >> 8, state & 255);
|
||||
@@ -44,7 +45,7 @@ function old_format(format: 1 | 2, chunk: ChunkBlocks) {
|
||||
// each column's biome at the bottom
|
||||
const columns = Array.from(
|
||||
{ length: CHUNK_AREA },
|
||||
(_, i) => biome_in(chunk.biomes!, DEFAULT_SHAPE, i, 0, i >> 4),
|
||||
(_, i) => biome_in(chunk.biomes!, shape_of(chunk), i, 0, i >> 4),
|
||||
);
|
||||
const biome_palette = [...new Set(columns)];
|
||||
bytes.push(biome_palette.length, ...biome_palette.flatMap(string));
|
||||
@@ -52,6 +53,8 @@ function old_format(format: 1 | 2, chunk: ChunkBlocks) {
|
||||
}
|
||||
return Uint8Array.from(bytes);
|
||||
}
|
||||
const shape_of = (chunk: ChunkBlocks) =>
|
||||
new WorldShape({ min_y: chunk.min_y, max_y: chunk.min_y + chunk.sections.length * 16, sky_light: true });
|
||||
const u32 = (value: number) => [value >>> 24, (value >> 16) & 255, (value >> 8) & 255, value & 255];
|
||||
const string = (text: string) => [text.length, ...new TextEncoder().encode(text)];
|
||||
|
||||
@@ -160,7 +163,7 @@ Deno.test("every chunk generated is saved whole, and saved again only when it ch
|
||||
const chunk = decode_chunk(saved.chunks.find((c) => c.x === 0 && c.z === 0)!.data);
|
||||
assertEquals(saved_block(chunk, 3, 120, 5), ["bworld:stone", 0]);
|
||||
assert(saved_block(chunk, 3, 10, 5)[0] !== AIR_ID);
|
||||
assertEquals(biome_in(chunk.biomes!, DEFAULT_SHAPE, 3, 120, 5), game.world.biome_at(3, 120, 5));
|
||||
assertEquals(biome_in(chunk.biomes!, game.world.shape, 3, 120, 5), game.world.biome_at(3, 120, 5));
|
||||
const untouched = decode_chunk(saved.chunks.find((c) => c.x === 5 && c.z === 5)!.data);
|
||||
assertEquals(
|
||||
Uint32Array.from(to_flat(untouched.sections), (block) => {
|
||||
@@ -216,7 +219,7 @@ Deno.test("chunks saved before they had biomes get them from generation, and are
|
||||
at_0_0.data = old_format(1, decode_chunk(at_0_0.data));
|
||||
const { game } = await test_game("mods", saved);
|
||||
assertEquals(game.world.get_block_id(3, 121, 5), "bworld:stone");
|
||||
assertEquals(game.world.biome_at(3, 120, 5), biome_in(biomes, DEFAULT_SHAPE, 3, 120, 5));
|
||||
assertEquals(game.world.biome_at(3, 120, 5), biome_in(biomes, game.world.shape, 3, 120, 5));
|
||||
const again = game.save().chunks.find((c) => c.x === 0 && c.z === 0)!;
|
||||
assertEquals(decode_chunk(again.data).biomes, biomes);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user