World shape for dimension

This commit is contained in:
2026-11-06 22:49:43 -03:00
parent 7458a2d42a
commit 818ce22dd6
60 changed files with 749 additions and 349 deletions
+15 -11
View File
@@ -4,7 +4,6 @@
import {
AIR,
BREAK_STAGES,
CHUNK_HEIGHT,
CHUNK_SIZE,
FACE_OFFSETS,
Faces,
@@ -71,6 +70,7 @@ import type { Menu } from "./menu.ts";
import { MACHINE_CONN, SavedPlayer, ServerPlayer } from "./player.ts";
import { encode_skin, MAX_SKIN_BYTES, skin_problem } from "./skins.ts";
import { ServerWorld, SPAWN_AREA_CHUNKS, Tile } from "./world.ts";
import type { WorldShape } from "@/common/world_shape.ts";
import { ScheduledTicks } from "./scheduled_ticks.ts";
import type { WorldSave, WorldSource } from "./saves.ts";
import {
@@ -219,7 +219,7 @@ export class GameServer {
this.world = new ServerWorld(saved?.seed ?? default_seed, mods.worldgen);
this.fluids = new FluidFlow({
value_at: (x, y, z) => {
if (y < 0 || y >= CHUNK_HEIGHT) return undefined;
if (!this.world.shape.contains(y)) return undefined;
const loaded = this.world.has_chunk(Math.floor(x / CHUNK_SIZE), Math.floor(z / CHUNK_SIZE));
return loaded ? this.world.get_block_value(x, y, z) : undefined;
},
@@ -720,7 +720,7 @@ export class GameServer {
// a block standing on this one that can't stand on what it is now breaks, like a crop on farmland that was
// dug
if (y + 1 < CHUNK_HEIGHT) {
if (this.world.shape.contains(y + 1)) {
const above = this.world.get_block_info(x, y + 1, z);
if (above && !can_stand_on(above, id)) {
this.destroy_block(x, y + 1, z, player);
@@ -1021,6 +1021,7 @@ export class GameServer {
players: [...this.#players.values()].map((p) => p.player_info()),
entities: this.entities.start_tracking(player),
blocks: this.world.block_table(),
shape: this.world.shape,
spawn: { x: player.x, y: player.y, z: player.z, yaw: player.yaw, pitch: player.pitch },
selected_slot: player.selected_slot,
player_menu: player.inventory_menu.extra.map(({ x, y, icon }) => ({ x, y, ...(icon ? { icon } : {}) })),
@@ -1084,13 +1085,13 @@ export class GameServer {
}
break;
case "break_block":
if (is_block_position(message.x, message.y, message.z)) {
if (is_block_position(this.world.shape, message.x, message.y, message.z)) {
this.#break_block(player, message.x, message.y, message.z);
}
this.#ack(player, message.seq);
break;
case "hit_block":
if (is_block_position(message.x, message.y, message.z)) {
if (is_block_position(this.world.shape, message.x, message.y, message.z)) {
this.#hit_block(player, message.x, message.y, message.z);
}
break;
@@ -1110,7 +1111,9 @@ export class GameServer {
this.#release_using(player);
break;
case "use_block":
if (is_block_position(message.x, message.y, message.z) && faces.includes(message.face)) {
if (
is_block_position(this.world.shape, message.x, message.y, message.z) && faces.includes(message.face)
) {
if (player.using) {
// a client that hadn't heard it's using an item yet: what it guessed the click did, it didn't
this.#correct_use(player, message.x, message.y, message.z, message.face);
@@ -1129,7 +1132,8 @@ export class GameServer {
break;
case "scroll_block":
if (
is_block_position(message.x, message.y, message.z) && faces.includes(message.face) &&
is_block_position(this.world.shape, message.x, message.y, message.z) &&
faces.includes(message.face) &&
is_int(message.amount) && message.amount !== 0
) {
const { x, y, z, face, amount } = message;
@@ -1405,7 +1409,7 @@ export class GameServer {
// place the held block against the face, or into the clicked block if it's replaceable. food that can be planted,
// like a potato on farmland, is planted, and eaten when it can't be
const placeable = held?.block_id !== undefined && ty >= 0 && ty < CHUNK_HEIGHT &&
const placeable = held?.block_id !== undefined && this.world.shape.contains(ty) &&
can_place(
EverythingRegistry.get<BlockRegistry>("blocks", held.block_id),
this.world.get_block_info(tx, ty, tz),
@@ -2247,7 +2251,7 @@ export class GameServer {
}
#correct(player: ServerPlayer, x: number, y: number, z: number) {
if (y < 0 || y >= CHUNK_HEIGHT || !player.chunks.has_block(x, z)) {
if (!this.world.shape.contains(y) || !player.chunks.has_block(x, z)) {
return;
}
// with its states, or the client would show it at its defaults, like a fence that lost its connections
@@ -2482,8 +2486,8 @@ function hit_on_block(hit: unknown): [number, number, number] {
}
// messages are parsed json, so the types in ClientMessage are only what a well behaved client sends
function is_block_position(x: unknown, y: unknown, z: unknown): boolean {
return is_int(x) && is_int(y) && is_int(z) && y >= 0 && y < CHUNK_HEIGHT &&
function is_block_position(shape: WorldShape, x: unknown, y: unknown, z: unknown): boolean {
return is_int(x) && is_int(y) && is_int(z) && shape.contains(y) &&
Math.abs(x) < 30000 * CHUNK_SIZE && Math.abs(z) < 30000 * CHUNK_SIZE;
}