Vaguely import every tile
This commit is contained in:
@@ -2,7 +2,7 @@ import type { ClientContext, Color } from "cubi/client";
|
||||
import type { ServerContext } from "cubi/server";
|
||||
import { DOOR, FACILITY_DOOR } from "./shared.ts";
|
||||
import { Alea } from "@paulaboks/rng";
|
||||
import { MAIN_TILE, type Marker, type PlacedTile, plan_interior, tile_type, TILES } from "./interior.ts";
|
||||
import { DOORWAY, MAIN_TILE, type Marker, type PlacedTile, plan_interior, tile_type, TILES } from "./interior.ts";
|
||||
|
||||
export { shared } from "./shared.ts";
|
||||
|
||||
@@ -148,7 +148,7 @@ const INTERIOR_ORIGIN = { x: 0, y: 60, z: 0 };
|
||||
// how likely a doorway between two rooms is to get a door, otherwise it's left open
|
||||
const DOOR_CHANCE = 0.8;
|
||||
const INTERIOR_DOOR = "dangerous_business:factory_door";
|
||||
const DOORWAY_WALL = "dangerous_business:sheet_wall";
|
||||
const DOORWAY_WALL = "dangerous_business:concrete_brick_wall";
|
||||
// how likely a vent spot is to get a vent, otherwise it's left empty
|
||||
const VENT_CHANCE = 0.65;
|
||||
const VENT = "dangerous_business:vent";
|
||||
@@ -168,13 +168,12 @@ function generate_interior(ctx: ServerContext, config: InteriorGenerationConfig)
|
||||
ctx.schematics.place(tile, { position, rotation });
|
||||
}
|
||||
for (const { x, y, z, facing, connected } of plan.doorways) {
|
||||
if (!connected) {
|
||||
ctx.world.set_block(x, y, z, DOORWAY_WALL);
|
||||
ctx.world.set_block(x, y + 1, z, DOORWAY_WALL);
|
||||
} else if (rng.next() < DOOR_CHANCE) {
|
||||
const door = connected && rng.next() < DOOR_CHANCE;
|
||||
if (!connected || door) wall_off_doorway(ctx, x, y, z, facing, door);
|
||||
if (door) {
|
||||
ctx.world.set_block(x, y, z, INTERIOR_DOOR, { facing, half: 0 });
|
||||
ctx.world.set_block(x, y + 1, z, INTERIOR_DOOR, { facing, half: 1 });
|
||||
} else {
|
||||
} else if (connected) {
|
||||
ctx.world.set_block(x, y, z, "cubi:air");
|
||||
}
|
||||
}
|
||||
@@ -189,3 +188,18 @@ function generate_interior(ctx: ServerContext, config: InteriorGenerationConfig)
|
||||
}
|
||||
interior_tiles = plan.tiles;
|
||||
}
|
||||
|
||||
// fills the opening a doorway is in, 3 wide and 4 tall like lethal3's or 1 by 2, leaving the doorway itself when a
|
||||
// door goes there. only air and the doorway are filled, so the wall around a smaller opening stays as it is
|
||||
function wall_off_doorway(ctx: ServerContext, x: number, y: number, z: number, facing: number, door: boolean) {
|
||||
// along the wall
|
||||
const [step_x, step_z] = facing % 2 === 0 ? [1, 0] : [0, 1];
|
||||
for (let side = -1; side <= 1; side++) {
|
||||
for (let up = 0; up < 4; up++) {
|
||||
if (door && side === 0 && up < 2) continue;
|
||||
const [at_x, at_y, at_z] = [x + side * step_x, y + up, z + side * step_z];
|
||||
const id = ctx.world.get_block(at_x, at_y, at_z);
|
||||
if (id === "cubi:air" || id === DOORWAY) ctx.world.set_block(at_x, at_y, at_z, DOORWAY_WALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user