Compare commits
3
Commits
9f637e6afb
...
3202c18ab5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3202c18ab5 | ||
|
|
a4fec0681f | ||
|
|
043c526c9c |
@@ -59,6 +59,14 @@ const WATER_HOP = 0.36 / TICK_DELTA;
|
|||||||
const SWIM_DRAG = 0.9;
|
const SWIM_DRAG = 0.9;
|
||||||
// and it turns up or down toward where it's looking, this much of the way each tick, like minecraft's Player.travel
|
// and it turns up or down toward where it's looking, this much of the way each tick, like minecraft's Player.travel
|
||||||
const SWIM_STEER = 0.06;
|
const SWIM_STEER = 0.06;
|
||||||
|
// flying, see /fly, like minecraft's creative flight: the keys add 0.05 blocks a tick and it keeps 0.91 of its speed,
|
||||||
|
// settling at 11 blocks a second, twice that sprinting. there's no gravity, jump and sneak push it up and down 0.15
|
||||||
|
// blocks a tick, and it keeps 0.6 of that each tick, rising and sinking 7.5 blocks a second
|
||||||
|
const FLY_ACCELERATION = 0.05 / TICK_DELTA;
|
||||||
|
const FLY_FRICTION = 0.91;
|
||||||
|
const FLY_SPRINT_SPEED = 2;
|
||||||
|
const FLY_VERTICAL = 0.15 / TICK_DELTA;
|
||||||
|
const FLY_VERTICAL_DRAG = 0.6;
|
||||||
// on land, the entity's own
|
// on land, the entity's own
|
||||||
const LAND_GRAVITY = -32;
|
const LAND_GRAVITY = -32;
|
||||||
const LAND_DRAG = 0.98;
|
const LAND_DRAG = 0.98;
|
||||||
@@ -103,6 +111,8 @@ export class LocalPlayer extends Player {
|
|||||||
sneaking = false;
|
sneaking = false;
|
||||||
// stays on after letting go of the key, see #update_sprinting
|
// stays on after letting go of the key, see #update_sprinting
|
||||||
sprinting = false;
|
sprinting = false;
|
||||||
|
// what the server says, see /fly
|
||||||
|
flying = false;
|
||||||
#fov_scale = 1;
|
#fov_scale = 1;
|
||||||
#prev_fov_scale = 1;
|
#prev_fov_scale = 1;
|
||||||
#prev_eye_height = PLAYER_EYE_HEIGHT;
|
#prev_eye_height = PLAYER_EYE_HEIGHT;
|
||||||
@@ -123,15 +133,16 @@ export class LocalPlayer extends Player {
|
|||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
for (const effect of this.effects) if (effect.duration > 0) effect.duration -= 1;
|
for (const effect of this.effects) if (effect.duration > 0) effect.duration -= 1;
|
||||||
this.#in_water = this.in_water;
|
// flying ignores water
|
||||||
|
this.#in_water = !this.flying && this.in_water;
|
||||||
const was_swimming = this.swimming;
|
const was_swimming = this.swimming;
|
||||||
const input = this.client.screen ? NO_INPUT : this.#read_input();
|
const input = this.client.screen ? NO_INPUT : this.#read_input();
|
||||||
this.#apply_input(input);
|
this.#apply_input(input);
|
||||||
// after sprinting is, so letting go stands it up the same tick
|
// after sprinting is, so letting go stands it up the same tick
|
||||||
this.#update_swimming();
|
this.#update_swimming();
|
||||||
// out of the water but still in the short box, under something low, it falls like on land
|
// out of the water but still in the short box, under something low, it falls like on land
|
||||||
this.gravity = !this.#in_water ? LAND_GRAVITY : this.swimming ? 0 : WATER_GRAVITY;
|
this.gravity = this.flying ? 0 : !this.#in_water ? LAND_GRAVITY : this.swimming ? 0 : WATER_GRAVITY;
|
||||||
this.drag = this.#in_water ? WATER_DRAG : LAND_DRAG;
|
this.drag = this.flying ? FLY_VERTICAL_DRAG : this.#in_water ? WATER_DRAG : LAND_DRAG;
|
||||||
if (this.swimming && this.#in_water) this.#steer(input);
|
if (this.swimming && this.#in_water) this.#steer(input);
|
||||||
this.#prev_eye_height = this.eye_height;
|
this.#prev_eye_height = this.eye_height;
|
||||||
const eye_height = this.swimming
|
const eye_height = this.swimming
|
||||||
@@ -170,7 +181,7 @@ export class LocalPlayer extends Player {
|
|||||||
// the surface too. it only stands back up where there's room, until then it stays in the short box
|
// the surface too. it only stands back up where there's room, until then it stays in the short box
|
||||||
#update_swimming() {
|
#update_swimming() {
|
||||||
if (!this.swimming) {
|
if (!this.swimming) {
|
||||||
if (this.sprinting && this.eyes_in_water) this.set_swimming(true);
|
if (this.sprinting && this.eyes_in_water && !this.flying) this.set_swimming(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.sprinting && this.#in_water) return;
|
if (this.sprinting && this.#in_water) return;
|
||||||
@@ -211,6 +222,7 @@ export class LocalPlayer extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override horizontal_friction() {
|
override horizontal_friction() {
|
||||||
|
if (this.flying) return FLY_FRICTION;
|
||||||
if (this.#in_water) return this.swimming ? SWIM_DRAG : WATER_DRAG;
|
if (this.#in_water) return this.swimming ? SWIM_DRAG : WATER_DRAG;
|
||||||
return this.on_ground ? GROUND_FRICTION : AIR_FRICTION;
|
return this.on_ground ? GROUND_FRICTION : AIR_FRICTION;
|
||||||
}
|
}
|
||||||
@@ -256,10 +268,18 @@ export class LocalPlayer extends Player {
|
|||||||
input_z /= size;
|
input_z /= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sneaking = input.sneak;
|
// sneaking while flying goes down instead
|
||||||
|
this.sneaking = input.sneak && !this.flying;
|
||||||
const sin = Math.sin(this.yaw);
|
const sin = Math.sin(this.yaw);
|
||||||
const cos = Math.cos(this.yaw);
|
const cos = Math.cos(this.yaw);
|
||||||
this.#update_sprinting(input, sin, cos);
|
this.#update_sprinting(input, sin, cos);
|
||||||
|
if (this.flying) {
|
||||||
|
const acceleration = FLY_ACCELERATION * (this.sprinting ? FLY_SPRINT_SPEED : 1);
|
||||||
|
this.vx += (sin * input_z + cos * input_x) * acceleration;
|
||||||
|
this.vz += (cos * input_z - sin * input_x) * acceleration;
|
||||||
|
this.vy += (Number(input.jump) - Number(input.sneak)) * FLY_VERTICAL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
// sprinting is no faster in water, swimming is
|
// sprinting is no faster in water, swimming is
|
||||||
const acceleration = this.#in_water
|
const acceleration = this.#in_water
|
||||||
? WATER_ACCELERATION * (input.sneak ? SNEAK_SPEED : 1)
|
? WATER_ACCELERATION * (input.sneak ? SNEAK_SPEED : 1)
|
||||||
@@ -291,7 +311,8 @@ export class LocalPlayer extends Player {
|
|||||||
// like minecraft's LocalPlayer.aiStep: the key starts sprinting while moving forward, and it keeps sprinting
|
// like minecraft's LocalPlayer.aiStep: the key starts sprinting while moving forward, and it keeps sprinting
|
||||||
// until it stops moving forward, sneaks, gets hungry or runs into a wall, even after letting go of the key
|
// until it stops moving forward, sneaks, gets hungry or runs into a wall, even after letting go of the key
|
||||||
#update_sprinting(input: MoveInput, sin: number, cos: number) {
|
#update_sprinting(input: MoveInput, sin: number, cos: number) {
|
||||||
const can_sprint = input.z < 0 && !input.sneak && this.food > SPRINT_MIN_FOOD;
|
// like minecraft, flying sprints even hungry, and sneaking to go down doesn't stop it
|
||||||
|
const can_sprint = input.z < 0 && (this.flying || (!input.sneak && this.food > SPRINT_MIN_FOOD));
|
||||||
// how far it's looking into what it hit in the last move, the way it's facing is -sin, -cos
|
// how far it's looking into what it hit in the last move, the way it's facing is -sin, -cos
|
||||||
const into_wall = sin * this.colliding_x + cos * this.colliding_z;
|
const into_wall = sin * this.colliding_x + cos * this.colliding_z;
|
||||||
if (!can_sprint || into_wall > SPRINT_WALL_ANGLE) {
|
if (!can_sprint || into_wall > SPRINT_WALL_ANGLE) {
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import type { KeyCode } from "./input_manager.ts";
|
|||||||
|
|
||||||
// the player's settings, like minecraft's Options and its key mappings
|
// the player's settings, like minecraft's Options and its key mappings
|
||||||
export class Options {
|
export class Options {
|
||||||
render_distance = 6;
|
render_distance = 16;
|
||||||
|
|
||||||
key_forward: KeyCode = "KeyW";
|
key_forward: KeyCode = "KeyW";
|
||||||
key_back: KeyCode = "KeyS";
|
key_back: KeyCode = "KeyS";
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ export class ClientPacketListener {
|
|||||||
case "attack_speed":
|
case "attack_speed":
|
||||||
client.player.attack_speed = message.value;
|
client.player.attack_speed = message.value;
|
||||||
break;
|
break;
|
||||||
|
case "flying":
|
||||||
|
client.player.flying = message.flying;
|
||||||
|
break;
|
||||||
case "effects":
|
case "effects":
|
||||||
client.player.effects = message.effects;
|
client.player.effects = message.effects;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -241,6 +241,8 @@ export type ServerMessage =
|
|||||||
| { type: "vitals"; health: number; max_health: number; food: number; saturation: number; air: number }
|
| { type: "vitals"; health: number; max_health: number; food: number; saturation: number; air: number }
|
||||||
// the player's own attack speed attribute, when it changes, for the attack indicator under the crosshair
|
// the player's own attack speed attribute, when it changes, for the attack indicator under the crosshair
|
||||||
| { type: "attack_speed"; value: number }
|
| { type: "attack_speed"; value: number }
|
||||||
|
// whether the player flies, see /fly, when it changes
|
||||||
|
| { type: "flying"; flying: boolean }
|
||||||
// the player's own effects that show an icon, when they change. duration is in ticks, -1 for forever, and the
|
// the player's own effects that show an icon, when they change. duration is in ticks, -1 for forever, and the
|
||||||
// client counts it down itself, so it isn't sent every tick
|
// client counts it down itself, so it isn't sent every tick
|
||||||
| { type: "effects"; effects: { id: string; amplifier: number; duration: number }[] }
|
| { type: "effects"; effects: { id: string; amplifier: number; duration: number }[] }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// what color each biome tints grass and leaves, as 0xRRGGBB. minecraft's grass and foliage colors, with the terralith
|
// what color each biome tints grass and leaves, as 0xRRGGBB, minecraft's grass and foliage colors. blocks pick them
|
||||||
// style biomes given the ones of the vanilla biome closest to them. blocks pick them with "tint"
|
// with "tint"
|
||||||
export const BIOME_GRASS_COLORS: Record<string, number> = {
|
export const BIOME_GRASS_COLORS: Record<string, number> = {
|
||||||
"bworld:deep_ocean": 0x8eb971,
|
"bworld:deep_ocean": 0x8eb971,
|
||||||
"bworld:deep_frozen_ocean": 0x80b497,
|
"bworld:deep_frozen_ocean": 0x80b497,
|
||||||
@@ -23,17 +23,10 @@ export const BIOME_GRASS_COLORS: Record<string, number> = {
|
|||||||
"bworld:savanna": 0xbfb755,
|
"bworld:savanna": 0xbfb755,
|
||||||
"bworld:jungle": 0x59c93c,
|
"bworld:jungle": 0x59c93c,
|
||||||
"bworld:desert": 0xbfb755,
|
"bworld:desert": 0xbfb755,
|
||||||
"bworld:alpine_highlands": 0x8ab689,
|
|
||||||
"bworld:snowy_slopes": 0x80b497,
|
"bworld:snowy_slopes": 0x80b497,
|
||||||
"bworld:stony_peaks": 0x9abe4b,
|
"bworld:stony_peaks": 0x9abe4b,
|
||||||
"bworld:jagged_peaks": 0x80b497,
|
"bworld:jagged_peaks": 0x80b497,
|
||||||
"bworld:frozen_peaks": 0x80b497,
|
"bworld:frozen_peaks": 0x80b497,
|
||||||
"bworld:yosemite_cliffs": 0x86b783,
|
|
||||||
"bworld:snowy_cliffs": 0x80b497,
|
|
||||||
"bworld:painted_mountains": 0x90814d,
|
|
||||||
"bworld:stony_spires": 0x8ab689,
|
|
||||||
"bworld:shattered_savanna": 0xbfb755,
|
|
||||||
"bworld:skylands": 0x79c05a,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const BIOME_FOLIAGE_COLORS: Record<string, number> = {
|
export const BIOME_FOLIAGE_COLORS: Record<string, number> = {
|
||||||
@@ -59,17 +52,10 @@ export const BIOME_FOLIAGE_COLORS: Record<string, number> = {
|
|||||||
"bworld:savanna": 0xaea42a,
|
"bworld:savanna": 0xaea42a,
|
||||||
"bworld:jungle": 0x30bb0b,
|
"bworld:jungle": 0x30bb0b,
|
||||||
"bworld:desert": 0xaea42a,
|
"bworld:desert": 0xaea42a,
|
||||||
"bworld:alpine_highlands": 0x6da36b,
|
|
||||||
"bworld:snowy_slopes": 0x60a17b,
|
"bworld:snowy_slopes": 0x60a17b,
|
||||||
"bworld:stony_peaks": 0x82ac1e,
|
"bworld:stony_peaks": 0x82ac1e,
|
||||||
"bworld:jagged_peaks": 0x60a17b,
|
"bworld:jagged_peaks": 0x60a17b,
|
||||||
"bworld:frozen_peaks": 0x60a17b,
|
"bworld:frozen_peaks": 0x60a17b,
|
||||||
"bworld:yosemite_cliffs": 0x68a464,
|
|
||||||
"bworld:snowy_cliffs": 0x60a17b,
|
|
||||||
"bworld:painted_mountains": 0x9e814d,
|
|
||||||
"bworld:stony_spires": 0x6da36b,
|
|
||||||
"bworld:shattered_savanna": 0xaea42a,
|
|
||||||
"bworld:skylands": 0x59ae30,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// biomes mods add without a color, and items, which aren't in any biome
|
// biomes mods add without a color, and items, which aren't in any biome
|
||||||
|
|||||||
@@ -26,12 +26,19 @@ export function named_noise_3d(seed: string, name: string): NoiseFunction3D {
|
|||||||
return noise;
|
return noise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// where an octave starts, like the random origin of each of minecraft's ImprovedNoise. simplex noise is 0 at 0 for
|
||||||
|
// every seed, so without it every world would have the same thing at 0, 0
|
||||||
|
function octave_offset(seed: string, name: string): number[] {
|
||||||
|
const random = new Alea(`${seed}_${name}_offset`);
|
||||||
|
return [random.next() * 256, random.next() * 256, random.next() * 256];
|
||||||
|
}
|
||||||
|
|
||||||
// several octaves of simplex noise, like minecraft's NormalNoise: each octave has twice the frequency and half the
|
// several octaves of simplex noise, like minecraft's NormalNoise: each octave has twice the frequency and half the
|
||||||
// strength of the last, times its amplitude. wavelength is the size in blocks of the first octave's features, an
|
// strength of the last, times its amplitude. wavelength is the size in blocks of the first octave's features, an
|
||||||
// amplitude of 0 skips that octave. the result is roughly -1 to 1 but bunched in the middle, see Quantiles for an
|
// amplitude of 0 skips that octave. the result is roughly -1 to 1 but bunched in the middle, see Quantiles for an
|
||||||
// even spread
|
// even spread
|
||||||
export class OctaveNoise2D {
|
export class OctaveNoise2D {
|
||||||
#octaves: { noise: NoiseFunction2D; frequency: number; amplitude: number }[] = [];
|
#octaves: { noise: NoiseFunction2D; frequency: number; amplitude: number; offset: number[] }[] = [];
|
||||||
#total: number;
|
#total: number;
|
||||||
|
|
||||||
constructor(seed: string, name: string, wavelength: number, amplitudes: number[]) {
|
constructor(seed: string, name: string, wavelength: number, amplitudes: number[]) {
|
||||||
@@ -41,6 +48,7 @@ export class OctaveNoise2D {
|
|||||||
noise: named_noise_2d(seed, `${name}_${i}`),
|
noise: named_noise_2d(seed, `${name}_${i}`),
|
||||||
frequency: 2 ** i / wavelength,
|
frequency: 2 ** i / wavelength,
|
||||||
amplitude: amplitude / 2 ** i,
|
amplitude: amplitude / 2 ** i,
|
||||||
|
offset: octave_offset(seed, `${name}_${i}`),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -49,15 +57,15 @@ export class OctaveNoise2D {
|
|||||||
|
|
||||||
sample(x: number, z: number) {
|
sample(x: number, z: number) {
|
||||||
let value = 0;
|
let value = 0;
|
||||||
for (const { noise, frequency, amplitude } of this.#octaves) {
|
for (const { noise, frequency, amplitude, offset } of this.#octaves) {
|
||||||
value += noise(x * frequency, z * frequency) * amplitude;
|
value += noise(x * frequency + offset[0], z * frequency + offset[2]) * amplitude;
|
||||||
}
|
}
|
||||||
return value / this.#total;
|
return value / this.#total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OctaveNoise3D {
|
export class OctaveNoise3D {
|
||||||
#octaves: { noise: NoiseFunction3D; frequency: number; amplitude: number }[] = [];
|
#octaves: { noise: NoiseFunction3D; frequency: number; amplitude: number; offset: number[] }[] = [];
|
||||||
#total: number;
|
#total: number;
|
||||||
// how much slower it changes vertically than horizontally
|
// how much slower it changes vertically than horizontally
|
||||||
#vertical_stretch: number;
|
#vertical_stretch: number;
|
||||||
@@ -69,6 +77,7 @@ export class OctaveNoise3D {
|
|||||||
noise: named_noise_3d(seed, `${name}_${i}`),
|
noise: named_noise_3d(seed, `${name}_${i}`),
|
||||||
frequency: 2 ** i / wavelength,
|
frequency: 2 ** i / wavelength,
|
||||||
amplitude: amplitude / 2 ** i,
|
amplitude: amplitude / 2 ** i,
|
||||||
|
offset: octave_offset(seed, `${name}_${i}`),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -79,8 +88,9 @@ export class OctaveNoise3D {
|
|||||||
sample(x: number, y: number, z: number) {
|
sample(x: number, y: number, z: number) {
|
||||||
let value = 0;
|
let value = 0;
|
||||||
const sy = y / this.#vertical_stretch;
|
const sy = y / this.#vertical_stretch;
|
||||||
for (const { noise, frequency, amplitude } of this.#octaves) {
|
for (const { noise, frequency, amplitude, offset } of this.#octaves) {
|
||||||
value += noise(x * frequency, sy * frequency, z * frequency) * amplitude;
|
value += noise(x * frequency + offset[0], sy * frequency + offset[1], z * frequency + offset[2]) *
|
||||||
|
amplitude;
|
||||||
}
|
}
|
||||||
return value / this.#total;
|
return value / this.#total;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ interface Surface {
|
|||||||
underwater_filler: Palette;
|
underwater_filler: Palette;
|
||||||
// cliffs show bare stone instead of top
|
// cliffs show bare stone instead of top
|
||||||
bare_cliffs: boolean;
|
bare_cliffs: boolean;
|
||||||
// stripes of sand, stone and dirt down the cliffs, like badlands
|
|
||||||
strata?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const GRASSY: Surface = {
|
const GRASSY: Surface = {
|
||||||
@@ -75,7 +73,7 @@ const STONY: Surface = {
|
|||||||
};
|
};
|
||||||
const SEA_FLOOR: Surface = { ...SANDY, filler_depth: 3 };
|
const SEA_FLOOR: Surface = { ...SANDY, filler_depth: 3 };
|
||||||
|
|
||||||
// every biome the overworld has, and its surface. names follow minecraft's and terralith's
|
// every biome the overworld has, and its surface. names follow minecraft's
|
||||||
export const BIOMES: Record<string, Surface> = {
|
export const BIOMES: Record<string, Surface> = {
|
||||||
"bworld:deep_ocean": SEA_FLOOR,
|
"bworld:deep_ocean": SEA_FLOOR,
|
||||||
"bworld:deep_frozen_ocean": SEA_FLOOR,
|
"bworld:deep_frozen_ocean": SEA_FLOOR,
|
||||||
@@ -99,42 +97,33 @@ export const BIOMES: Record<string, Surface> = {
|
|||||||
"bworld:savanna": GRASSY,
|
"bworld:savanna": GRASSY,
|
||||||
"bworld:jungle": GRASSY,
|
"bworld:jungle": GRASSY,
|
||||||
"bworld:desert": SANDY,
|
"bworld:desert": SANDY,
|
||||||
"bworld:alpine_highlands": GRASSY,
|
|
||||||
"bworld:snowy_slopes": SNOWY,
|
"bworld:snowy_slopes": SNOWY,
|
||||||
"bworld:stony_peaks": STONY,
|
"bworld:stony_peaks": STONY,
|
||||||
"bworld:jagged_peaks": { ...STONY, top: "snow" },
|
"bworld:jagged_peaks": { ...STONY, top: "snow" },
|
||||||
"bworld:frozen_peaks": { ...SNOWY, filler: "stone" },
|
"bworld:frozen_peaks": { ...SNOWY, filler: "stone" },
|
||||||
"bworld:yosemite_cliffs": GRASSY,
|
|
||||||
"bworld:snowy_cliffs": SNOWY,
|
|
||||||
"bworld:painted_mountains": { ...SANDY, filler_depth: 2, bare_cliffs: true, strata: true },
|
|
||||||
"bworld:stony_spires": GRASSY,
|
|
||||||
"bworld:shattered_savanna": GRASSY,
|
|
||||||
"bworld:skylands": GRASSY,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// picks a column's biome from its climate and shape, like minecraft's multi noise biome source
|
// picks a column's biome from its climate and shape, like minecraft's multi noise biome source
|
||||||
export function pick_biome(column: TerrainColumn, surface_y: number, steep: boolean): string {
|
export function pick_biome(column: TerrainColumn, surface_y: number, steep: boolean): string {
|
||||||
const { continentalness: c, erosion: e, pv, temperature: t, humidity: h } = column.climate;
|
const { continentalness: c, erosion, ridges, temperature: t, humidity: h } = column.climate;
|
||||||
|
const flat = Math.abs(erosion);
|
||||||
|
const valley = Math.abs(ridges);
|
||||||
const frozen = t < -0.65;
|
const frozen = t < -0.65;
|
||||||
const cold = t < -0.3;
|
const cold = t < -0.3;
|
||||||
const warm = t > 0.2;
|
const warm = t > 0.2;
|
||||||
const hot = t > 0.55;
|
const hot = t > 0.55;
|
||||||
|
|
||||||
if (column.island && surface_y >= column.island.bottom) {
|
|
||||||
return "bworld:skylands";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (surface_y < SEA_LEVEL - 1) {
|
if (surface_y < SEA_LEVEL - 1) {
|
||||||
if (pv < -0.7 && c > -0.12) return frozen ? "bworld:frozen_river" : "bworld:river";
|
if (valley < 0.06 && c > -0.2) return frozen ? "bworld:frozen_river" : "bworld:river";
|
||||||
if (c < -0.45) {
|
if (c < -0.45) {
|
||||||
return frozen ? "bworld:deep_frozen_ocean" : hot ? "bworld:deep_lukewarm_ocean" : "bworld:deep_ocean";
|
return frozen ? "bworld:deep_frozen_ocean" : hot ? "bworld:deep_lukewarm_ocean" : "bworld:deep_ocean";
|
||||||
}
|
}
|
||||||
return frozen ? "bworld:frozen_ocean" : hot ? "bworld:warm_ocean" : "bworld:ocean";
|
return frozen ? "bworld:frozen_ocean" : hot ? "bworld:warm_ocean" : "bworld:ocean";
|
||||||
}
|
}
|
||||||
if (c < -0.04 && surface_y <= SEA_LEVEL + 4) {
|
if (c < -0.12 && surface_y <= SEA_LEVEL + 4) {
|
||||||
return steep ? "bworld:stony_shore" : cold ? "bworld:snowy_beach" : "bworld:beach";
|
return steep ? "bworld:stony_shore" : cold ? "bworld:snowy_beach" : "bworld:beach";
|
||||||
}
|
}
|
||||||
if (pv < -0.8 && c > -0.12 && surface_y <= SEA_LEVEL + 1) {
|
if (valley < 0.04 && c > -0.2 && surface_y <= SEA_LEVEL + 1) {
|
||||||
return frozen ? "bworld:frozen_river" : "bworld:river";
|
return frozen ? "bworld:frozen_river" : "bworld:river";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,17 +132,10 @@ export function pick_biome(column: TerrainColumn, surface_y: number, steep: bool
|
|||||||
if (cold) return "bworld:frozen_peaks";
|
if (cold) return "bworld:frozen_peaks";
|
||||||
return column.jaggedness > 0.35 ? "bworld:jagged_peaks" : "bworld:stony_peaks";
|
return column.jaggedness > 0.35 ? "bworld:jagged_peaks" : "bworld:stony_peaks";
|
||||||
}
|
}
|
||||||
if (column.plateau > 0.5) {
|
if (above > 60 && cold) {
|
||||||
if (hot && h < 0.1) return "bworld:painted_mountains";
|
return "bworld:snowy_slopes";
|
||||||
return cold ? "bworld:snowy_cliffs" : "bworld:yosemite_cliffs";
|
|
||||||
}
|
}
|
||||||
if (column.shattered > 0.5) {
|
if (above > 30 && !cold && h > -0.3) {
|
||||||
return warm ? "bworld:shattered_savanna" : "bworld:stony_spires";
|
|
||||||
}
|
|
||||||
if (above > 60) {
|
|
||||||
return cold ? "bworld:snowy_slopes" : "bworld:alpine_highlands";
|
|
||||||
}
|
|
||||||
if (above > 30 && e > -0.2 && !cold && h > -0.3) {
|
|
||||||
return "bworld:meadow";
|
return "bworld:meadow";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,14 +143,13 @@ export function pick_biome(column: TerrainColumn, surface_y: number, steep: bool
|
|||||||
if (cold) return h > 0 ? "bworld:taiga" : "bworld:plains";
|
if (cold) return h > 0 ? "bworld:taiga" : "bworld:plains";
|
||||||
if (hot) return h < -0.2 ? "bworld:desert" : h < 0.4 ? "bworld:savanna" : "bworld:jungle";
|
if (hot) return h < -0.2 ? "bworld:desert" : h < 0.4 ? "bworld:savanna" : "bworld:jungle";
|
||||||
if (warm) return h < -0.3 ? "bworld:savanna" : h > 0.6 ? "bworld:jungle" : "bworld:forest";
|
if (warm) return h < -0.3 ? "bworld:savanna" : h > 0.6 ? "bworld:jungle" : "bworld:forest";
|
||||||
if (h > 0.5 && e > 0.4) return "bworld:swamp";
|
if (h > 0.5 && flat > 0.6) return "bworld:swamp";
|
||||||
return h < -0.35 ? "bworld:plains" : h < 0.45 ? "bworld:forest" : "bworld:dark_forest";
|
return h < -0.35 ? "bworld:plains" : h < 0.45 ? "bworld:forest" : "bworld:dark_forest";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SeedGenerators {
|
interface SeedGenerators {
|
||||||
terrain: OverworldTerrain;
|
terrain: OverworldTerrain;
|
||||||
snow_line: OctaveNoise2D;
|
snow_line: OctaveNoise2D;
|
||||||
strata: OctaveNoise2D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const generators = new Map<string, SeedGenerators>();
|
const generators = new Map<string, SeedGenerators>();
|
||||||
@@ -179,7 +160,6 @@ function generators_for(seed: string): SeedGenerators {
|
|||||||
found = {
|
found = {
|
||||||
terrain: new OverworldTerrain(seed),
|
terrain: new OverworldTerrain(seed),
|
||||||
snow_line: new OctaveNoise2D(seed, "snow_line", 96, [1, 1]),
|
snow_line: new OctaveNoise2D(seed, "snow_line", 96, [1, 1]),
|
||||||
strata: new OctaveNoise2D(seed, "strata", 128, [1]),
|
|
||||||
};
|
};
|
||||||
generators.set(seed, found);
|
generators.set(seed, found);
|
||||||
}
|
}
|
||||||
@@ -193,7 +173,7 @@ function generators_for(seed: string): SeedGenerators {
|
|||||||
export function estimate_biome(seed: string, x: number, z: number): { biome: string; y: number } {
|
export function estimate_biome(seed: string, x: number, z: number): { biome: string; y: number } {
|
||||||
const { terrain } = generators_for(seed);
|
const { terrain } = generators_for(seed);
|
||||||
const column = terrain.column(x, z);
|
const column = terrain.column(x, z);
|
||||||
const y = Math.round(column.island ? column.island.top : column.height);
|
const y = Math.round(column.height);
|
||||||
const flat = pick_biome(column, y, false);
|
const flat = pick_biome(column, y, false);
|
||||||
// most columns are the same either way, the neighbors are only worth sampling when they aren't
|
// most columns are the same either way, the neighbors are only worth sampling when they aren't
|
||||||
if (flat === pick_biome(column, y, true)) return { biome: flat, y };
|
if (flat === pick_biome(column, y, true)) return { biome: flat, y };
|
||||||
@@ -212,7 +192,7 @@ export function generate_overworld(
|
|||||||
ids: OverworldBlocks,
|
ids: OverworldBlocks,
|
||||||
spill: (x: number, y: number, z: number, block: number) => void,
|
spill: (x: number, y: number, z: number, block: number) => void,
|
||||||
) {
|
) {
|
||||||
const { terrain, snow_line, strata } = generators_for(seed);
|
const { terrain, snow_line } = generators_for(seed);
|
||||||
const x0 = chunk_x * CHUNK_SIZE;
|
const x0 = chunk_x * CHUNK_SIZE;
|
||||||
const z0 = chunk_z * CHUNK_SIZE;
|
const z0 = chunk_z * CHUNK_SIZE;
|
||||||
|
|
||||||
@@ -337,8 +317,6 @@ export function generate_overworld(
|
|||||||
const biome = pick_biome(column, surface_y, steep);
|
const biome = pick_biome(column, surface_y, steep);
|
||||||
const surface = BIOMES[biome];
|
const surface = BIOMES[biome];
|
||||||
const snow_y = SNOW_LINE + snow_line.sample(x0 + x, z0 + z) * 10;
|
const snow_y = SNOW_LINE + snow_line.sample(x0 + x, z0 + z) * 10;
|
||||||
const strata_offset = strata.sample(x0 + x, z0 + z) * 4;
|
|
||||||
const island_bottom = column.island ? column.island.bottom - 2 : Infinity;
|
|
||||||
|
|
||||||
heights[z * CHUNK_SIZE + x] = surface_y;
|
heights[z * CHUNK_SIZE + x] = surface_y;
|
||||||
biomes[z * CHUNK_SIZE + x] = biome;
|
biomes[z * CHUNK_SIZE + x] = biome;
|
||||||
@@ -346,46 +324,37 @@ export function generate_overworld(
|
|||||||
const index = (y: number) => y * CHUNK_AREA + z * CHUNK_SIZE + x;
|
const index = (y: number) => y * CHUNK_AREA + z * CHUNK_SIZE + x;
|
||||||
// solid blocks since the last air going down, 0 is a block with air on top
|
// solid blocks since the last air going down, 0 is a block with air on top
|
||||||
let depth = -1;
|
let depth = -1;
|
||||||
// nothing but air (and sky islands) above so far: water fills it up to sea level
|
// nothing but air above so far: water fills it up to sea level
|
||||||
let open_sky = true;
|
let open_sky = true;
|
||||||
// whether the ground's surface is under water, for its cover
|
// whether the ground's surface is under water, for its cover
|
||||||
let underwater = false;
|
let underwater = false;
|
||||||
for (let y = CHUNK_HEIGHT - 1; y >= 0; y--) {
|
for (let y = CHUNK_HEIGHT - 1; y >= 0; y--) {
|
||||||
if (!is_solid[y]) {
|
if (!is_solid[y]) {
|
||||||
depth = -1;
|
depth = -1;
|
||||||
if (open_sky && y < SEA_LEVEL) {
|
// and a river's tunnel under a mountain, and the caves it runs into
|
||||||
|
if ((open_sky || column.underground_river > 0) && y < SEA_LEVEL) {
|
||||||
blocks[index(y)] = ids.water;
|
blocks[index(y)] = ids.water;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
depth += 1;
|
depth += 1;
|
||||||
const in_island = y >= island_bottom;
|
if (open_sky) {
|
||||||
if (open_sky && !in_island) {
|
|
||||||
open_sky = false;
|
open_sky = false;
|
||||||
underwater = y < SEA_LEVEL - 1;
|
underwater = y < SEA_LEVEL - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// surface rules reach the ground and anything above it, not cave floors
|
// surface rules reach the ground and anything above it, not cave floors
|
||||||
let block: Palette = "stone";
|
let block: Palette = "stone";
|
||||||
if (y >= ground - SURFACE_REACH || in_island) {
|
if (y >= ground - SURFACE_REACH) {
|
||||||
const wet = underwater && !in_island;
|
if (depth === 0) {
|
||||||
if (surface.strata && depth > 0 && y > SEA_LEVEL) {
|
if (underwater) block = surface.underwater_top;
|
||||||
block = strata_block(y + strata_offset);
|
else if (y >= snow_y) block = steep ? "stone" : "snow";
|
||||||
} else if (depth === 0) {
|
|
||||||
if (wet) block = surface.underwater_top;
|
|
||||||
else if (y >= snow_y && !in_island) block = steep ? "stone" : "snow";
|
|
||||||
else block = steep && surface.bare_cliffs ? "stone" : surface.top;
|
else block = steep && surface.bare_cliffs ? "stone" : surface.top;
|
||||||
} else if (depth <= surface.filler_depth) {
|
} else if (depth <= surface.filler_depth) {
|
||||||
block = wet ? surface.underwater_filler : surface.filler;
|
block = underwater ? surface.underwater_filler : surface.filler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blocks[index(y)] = ids[block];
|
blocks[index(y)] = ids[block];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the bands down a painted mountain's cliffs
|
|
||||||
function strata_block(y: number): Palette {
|
|
||||||
const band = ((Math.floor(y / 3) % 6) + 6) % 6;
|
|
||||||
return band === 1 || band === 4 ? "stone" : band === 3 ? "dirt" : "sand";
|
|
||||||
}
|
|
||||||
|
|||||||
+16
-21
@@ -1,30 +1,24 @@
|
|||||||
// minecraft's CubicSpline: a smooth curve through points, where a point's value can itself be a spline of another
|
// minecraft's CubicSpline: a smooth curve through points, where a point's value can itself be a spline of another
|
||||||
// input. that nesting is how its terrain (and terralith's) turns continentalness, erosion and peaks and valleys into
|
// input. that nesting is how its terrain (and tectonic's) turns continentalness, erosion and ridges into heights:
|
||||||
// heights: a spline over continentalness whose points are splines over erosion, whose points are splines over pv
|
// a spline over continentalness whose points are splines over erosion, whose points are splines over ridges.
|
||||||
|
// K names the inputs, see TerrainInputs
|
||||||
|
|
||||||
export interface SplineInputs {
|
export type SplineValue<K extends string> = number | Spline<K>;
|
||||||
continentalness: number;
|
|
||||||
erosion: number;
|
|
||||||
pv: number;
|
|
||||||
weirdness: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SplineValue = number | Spline;
|
export interface SplinePoint<K extends string> {
|
||||||
|
|
||||||
export interface SplinePoint {
|
|
||||||
at: number;
|
at: number;
|
||||||
value: SplineValue;
|
value: SplineValue<K>;
|
||||||
// the slope there, worked out from the neighbors when not given
|
// the slope there, worked out from the neighbors when not given
|
||||||
slope?: number;
|
slope?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Spline {
|
export class Spline<K extends string> {
|
||||||
readonly input: keyof SplineInputs;
|
readonly input: K;
|
||||||
#locations: number[];
|
#locations: number[];
|
||||||
#values: SplineValue[];
|
#values: SplineValue<K>[];
|
||||||
#slopes: number[];
|
#slopes: number[];
|
||||||
|
|
||||||
constructor(input: keyof SplineInputs, points: SplinePoint[]) {
|
constructor(input: K, points: SplinePoint<K>[]) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.#locations = points.map((point) => point.at);
|
this.#locations = points.map((point) => point.at);
|
||||||
this.#values = points.map((point) => point.value);
|
this.#values = points.map((point) => point.value);
|
||||||
@@ -40,7 +34,7 @@ export class Spline {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get(inputs: SplineInputs): number {
|
get(inputs: Readonly<Record<K, number>>): number {
|
||||||
const x = inputs[this.input];
|
const x = inputs[this.input];
|
||||||
const locations = this.#locations;
|
const locations = this.#locations;
|
||||||
const last = locations.length - 1;
|
const last = locations.length - 1;
|
||||||
@@ -67,11 +61,12 @@ export class Spline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function value_of(value: SplineValue, inputs: SplineInputs) {
|
function value_of<K extends string>(value: SplineValue<K>, inputs: Readonly<Record<K, number>>) {
|
||||||
return typeof value === "number" ? value : value.get(inputs);
|
return typeof value === "number" ? value : value.get(inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// a spline through evenly spaced values of one input
|
// a spline through points given as [at, value, slope], like minecraft's json with its derivatives. slope is 0 when
|
||||||
export function spline(input: keyof SplineInputs, at: number[], values: SplineValue[]) {
|
// left out, like minecraft's
|
||||||
return new Spline(input, at.map((location, i) => ({ at: location, value: values[i] })));
|
export function spline<K extends string>(input: K, points: [number, SplineValue<K>, number?][]) {
|
||||||
|
return new Spline(input, points.map(([at, value, slope]) => ({ at, value, slope: slope ?? 0 })));
|
||||||
}
|
}
|
||||||
|
|||||||
+420
-149
@@ -1,11 +1,14 @@
|
|||||||
// the shape of the overworld, built the way minecraft 1.18+ (and terralith on top of it) does it:
|
// the shape of the overworld, built the way minecraft 1.18+ does it and shaped after tectonic
|
||||||
// large noises for continentalness, erosion and weirdness feed nested splines that give each column a target height,
|
// (https://github.com/Apollounknowndev/tectonic, MIT): large noises for continents, erosion and ridges feed nested
|
||||||
// how jagged its peaks are and how rough its ground is. a 3d density around that height decides what's solid,
|
// splines that give each column a target height, how jagged its peaks are and how rough its ground is. a 3d density
|
||||||
// and caves are cut out of it. terralith's flavor comes from the extra shapes: terraced plateaus with cliffs,
|
// around that height decides what's solid, and caves are cut out of it. tectonic's look comes from its splines,
|
||||||
// shattered hills full of overhangs, deep river valleys and gorges, jagged peaks and rare sky islands
|
// ported here in its units (1 is 128 blocks): oceans that wind between big continents with islands out at sea,
|
||||||
|
// mountain ranges where erosion is low, rivers along the valleys between ridges that go underground through
|
||||||
|
// mountains, and on the flatter land four kinds of region picked by a slow noise and the climate: valleys and
|
||||||
|
// plateaus (and badlands ridges where it's hot), tiered mesas, rolling hills and jungle pillars, and wetlands and dunes
|
||||||
import { CHUNK_HEIGHT, SEA_LEVEL } from "$/common/constants.ts";
|
import { CHUNK_HEIGHT, SEA_LEVEL } from "$/common/constants.ts";
|
||||||
import { clamp, lerp, OctaveNoise2D, OctaveNoise3D, Quantiles, smoothstep } from "./noise.ts";
|
import { clamp, OctaveNoise2D, OctaveNoise3D, Quantiles, smoothstep } from "./noise.ts";
|
||||||
import { Spline, spline, SplineInputs } from "./spline.ts";
|
import { Spline, spline } from "./spline.ts";
|
||||||
|
|
||||||
// measured with tools/noise_quantiles.ts
|
// measured with tools/noise_quantiles.ts
|
||||||
const QUANTILES_6 = new Quantiles([
|
const QUANTILES_6 = new Quantiles([
|
||||||
@@ -131,16 +134,16 @@ const TOP_SLIDE_START = CHUNK_HEIGHT - 24;
|
|||||||
const TOP_SLIDE_END = CHUNK_HEIGHT - 4;
|
const TOP_SLIDE_END = CHUNK_HEIGHT - 4;
|
||||||
const MIN_CAVE_Y = 5;
|
const MIN_CAVE_Y = 5;
|
||||||
|
|
||||||
// the climate at a column, every value spread evenly from -1 to 1
|
// the climate at a column. continentalness, erosion and ridges are scaled to about tectonic's ranges, temperature and
|
||||||
|
// humidity are spread evenly from -1 to 1
|
||||||
export interface Climate {
|
export interface Climate {
|
||||||
// ocean far below 0, coast around -0.2, further inland higher
|
// tectonic's raw continents: deep ocean below -0.45, ocean to -0.2, the coast to 0, then further and further
|
||||||
|
// inland. islands raise it out at sea
|
||||||
continentalness: number;
|
continentalness: number;
|
||||||
// low is mountains, high is flat land
|
// low is mountains, high is flat land. both ends are flat, see erosion_folded
|
||||||
erosion: number;
|
erosion: number;
|
||||||
// picks between variants, and its folded form pv
|
// 0 along valleys, where rivers run, and further from 0 towards the ridges between them
|
||||||
weirdness: number;
|
ridges: number;
|
||||||
// peaks and valleys: -1 in a valley (rivers), 1 on a peak
|
|
||||||
pv: number;
|
|
||||||
temperature: number;
|
temperature: number;
|
||||||
humidity: number;
|
humidity: number;
|
||||||
}
|
}
|
||||||
@@ -150,101 +153,369 @@ export interface TerrainColumn {
|
|||||||
climate: Climate;
|
climate: Climate;
|
||||||
// where the ground's surface is before 3d noise, in blocks
|
// where the ground's surface is before 3d noise, in blocks
|
||||||
height: number;
|
height: number;
|
||||||
// how much 3d noise moves the ground, in units of density
|
// how much 3d noise moves the ground, in units of density. high where tectonic's terrain is rugged
|
||||||
roughness: number;
|
roughness: number;
|
||||||
// 0 to 1, how much of it are terraced plateaus and shattered hills
|
// 0 to 1, how much its peaks are sharp ridges
|
||||||
plateau: number;
|
|
||||||
shattered: number;
|
|
||||||
// 0 to 1, how pointy its peaks are
|
|
||||||
jaggedness: number;
|
jaggedness: number;
|
||||||
// a sky island above it, when there is one
|
// 0 to 1, how close it is to the middle of a river that goes under a mountain here, see cave
|
||||||
island?: { top: number; bottom: number };
|
underground_river: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// minecraft's peaks and valleys: weirdness folded so both its ends are peaks and its middle a valley
|
// what tectonic's splines read: the climate, folded, and the small noises its regions are made of
|
||||||
export function peaks_and_valleys(weirdness: number) {
|
type Input =
|
||||||
return 1 - Math.abs(3 * Math.abs(weirdness) - 2);
|
| "continents"
|
||||||
}
|
| "erosion"
|
||||||
|
| "erosion_folded"
|
||||||
|
| "ridges"
|
||||||
|
| "ridges_folded"
|
||||||
|
| "region"
|
||||||
|
| "regions"
|
||||||
|
| "temperature"
|
||||||
|
| "vegetation"
|
||||||
|
| "lower_tier"
|
||||||
|
| "upper_tier"
|
||||||
|
| "badlands"
|
||||||
|
| "hills"
|
||||||
|
| "wetland"
|
||||||
|
| "pillar";
|
||||||
|
type TerrainInputs = Record<Input, number>;
|
||||||
|
type S = Spline<Input>;
|
||||||
|
const s = (input: Input, points: [number, number | S, number?][]): S => spline(input, points);
|
||||||
|
|
||||||
// the valley value holds until -0.85, so rivers have a flat bottom and some width
|
// tectonic's raw continents from how far the continents noise is from 0: 0 is the middle of an ocean
|
||||||
const PV_POINTS = [-1, -0.85, -0.65, -0.35, 0, 0.45, 0.8, 1];
|
const CONTINENT_SHAPE = s("continents", [[0, 0], [0.4, 0.575, 1], [0.48, 0.68, 1]]);
|
||||||
const EROSION_POINTS = [-1, -0.6, -0.3, 0, 0.3, 0.6, 1];
|
|
||||||
|
|
||||||
// the heights over land at one level of continentalness, relative to sea level. base lifts everything, mountains
|
// tectonic's temperature and vegetation indexes, 1 to 5, from its climate parameters
|
||||||
// scales how tall they get. each erosion gets a spline over peaks and valleys: a valley value, then how far above
|
const TEMPERATURE_INDEX = s("temperature", [
|
||||||
// base the ground rises towards the peaks
|
[-0.48, 1],
|
||||||
function land(base: number, mountains: number): Spline {
|
[-0.42, 2],
|
||||||
const row = (valley: number, rises: number[]) =>
|
[-0.18, 2],
|
||||||
spline("pv", PV_POINTS, [valley, valley, ...rises.map((rise) => base + rise * mountains)]);
|
[-0.12, 3],
|
||||||
return spline("erosion", EROSION_POINTS, [
|
[0.17, 3],
|
||||||
// barely eroded: huge mountains, their valleys are gorges high above the sea
|
[0.23, 4],
|
||||||
row(base + 14 * mountains, [22, 44, 66, 88, 104, 110]),
|
[0.52, 4],
|
||||||
row(base + 8 * mountains, [14, 28, 42, 54, 62, 66]),
|
[0.58, 5],
|
||||||
// hills and highlands, their valleys carry rivers
|
]);
|
||||||
row(-4, [8, 20, 28, 36, 42, 44]),
|
const VEGETATION_INDEX = s("vegetation", [
|
||||||
row(-5, [4, 10, 15, 20, 23, 24]),
|
[-0.38, 1],
|
||||||
row(-5, [2, 6, 9, 12, 13, 14]),
|
[-0.32, 2],
|
||||||
// worn flat: plains and wetlands
|
[-0.13, 2],
|
||||||
row(-4, [1, 3, 5, 7, 8, 8]),
|
[-0.07, 3],
|
||||||
row(-3, [0, 1, 2, 3, 3, 3]),
|
[0.07, 3],
|
||||||
|
[0.13, 4],
|
||||||
|
[0.27, 4],
|
||||||
|
[0.33, 5],
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
// target height above sea level
|
// from here on, tectonic's splines: heights in its units, relative to sea level
|
||||||
const OFFSET = spline(
|
|
||||||
"continentalness",
|
|
||||||
[-1, -0.55, -0.3, -0.18, -0.12, -0.04, 0.2, 0.5, 1],
|
|
||||||
[-46, -32, -18, -8, -2, land(1, 0.3), land(3, 0.65), land(8, 1), land(14, 1.15)],
|
|
||||||
);
|
|
||||||
|
|
||||||
// how pointy peaks get, 0 to 1. only tall, barely eroded mountains have them
|
// a river: down to below sea level where the ridges noise is 0, back up to the land around it
|
||||||
const JAGGEDNESS = spline("erosion", [-1, -0.6, -0.3, 0], [
|
const RIVER = s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01]]);
|
||||||
spline("pv", [-0.2, 0.3, 1], [0, 0.6, 1]),
|
const GENTLE_RIVER = s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01, 0.1]]);
|
||||||
spline("pv", [0, 0.5, 1], [0, 0.4, 0.7]),
|
const lower_tier = (low: number, high: number) => s("lower_tier", [[0, low], [0.15, high]]);
|
||||||
spline("pv", [0.3, 0.8, 1], [0, 0.2, 0.3]),
|
const badlands = (low: number, high: number) => s("badlands", [[0.45, 0.05], [0.6, low, 1.5], [0.63, high, 0.2]]);
|
||||||
|
|
||||||
|
// club: valleys between plateaus, with badlands ridges where it's hot
|
||||||
|
const PLATEAUS = s("ridges", [
|
||||||
|
[-0.5, 0.25, -0.1],
|
||||||
|
[-0.4, lower_tier(0.1, 0.22)],
|
||||||
|
[-0.3, 0.05, -0.8],
|
||||||
|
[-0.1, 0.01],
|
||||||
|
[-0.03, -0.06, -0.5],
|
||||||
|
[0.03, -0.06, 0.5],
|
||||||
|
[0.1, 0.01],
|
||||||
|
[0.3, 0.05, 0.8],
|
||||||
|
[0.4, lower_tier(0.135, 0.28)],
|
||||||
|
[0.5, 0.35, 0.1],
|
||||||
|
]);
|
||||||
|
const SINGLE_VALLEY = s("ridges", [
|
||||||
|
[-0.5, 0.25, -0.1],
|
||||||
|
[-0.4, lower_tier(0.1, 0.22)],
|
||||||
|
[-0.3, 0.05, -0.8],
|
||||||
|
[-0.1, 0.01],
|
||||||
|
[-0.03, -0.06, -0.5],
|
||||||
|
[0.03, -0.06, 0.5],
|
||||||
|
[0.075, 0.01],
|
||||||
|
[0.14, 0.05, 0.8],
|
||||||
|
[0.2, lower_tier(0.135, 0.28)],
|
||||||
|
[0.3, 0.35],
|
||||||
|
[0.45, 0.03],
|
||||||
|
]);
|
||||||
|
const DOUBLE_VALLEY = s("ridges", [
|
||||||
|
[-0.45, 0.03],
|
||||||
|
[-0.3, 0.25],
|
||||||
|
[-0.2, lower_tier(0.1, 0.22)],
|
||||||
|
[-0.125, 0.05, -0.8],
|
||||||
|
[-0.075, 0.01],
|
||||||
|
[-0.03, -0.06, -0.5],
|
||||||
|
[0.03, -0.06, 0.5],
|
||||||
|
[0.075, 0.01],
|
||||||
|
[0.125, 0.05, 0.8],
|
||||||
|
[0.2, lower_tier(0.135, 0.28)],
|
||||||
|
[0.3, 0.35],
|
||||||
|
[0.45, 0.03],
|
||||||
|
]);
|
||||||
|
const CLUB = s("temperature", [
|
||||||
|
[1, PLATEAUS],
|
||||||
|
[2, s("vegetation", [[1, SINGLE_VALLEY], [2, PLATEAUS]])],
|
||||||
|
[3, s("vegetation", [[2, SINGLE_VALLEY], [3, PLATEAUS], [4, PLATEAUS], [5, DOUBLE_VALLEY]])],
|
||||||
|
[4, PLATEAUS],
|
||||||
|
[5, s("ridges_folded", [[0, -0.15, 2.5], [0.1, 0.04], [0.2, badlands(0.15, 0.185)], [0.3, badlands(0.185, 0.5)]])],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// heart: rolling hills where it's mild, and in jungles ridges cut by narrow valleys
|
||||||
|
const HEART = s("temperature", [
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
s("vegetation", [
|
||||||
|
[2, s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01, 0.1], [0.2, s("hills", [[0, 0.01, 0.225]])]])],
|
||||||
|
[3, GENTLE_RIVER],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
s("vegetation", [
|
||||||
|
[3, GENTLE_RIVER],
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
s("ridges", [
|
||||||
|
[-0.75, 0.05],
|
||||||
|
[-0.175, 0.015],
|
||||||
|
[-0.125, 0.01],
|
||||||
|
[-0.04, -0.06, -0.7],
|
||||||
|
[0.04, -0.06, 0.7],
|
||||||
|
[0.125, 0.01],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[5, s("ridges_folded", [[0.04, -0.06, 0.7], [0.125, 0.01], [0.175, 0.015], [0.75, 0.05], [0.8, 0.6]])],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[5, s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01, 0.15]])],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// spade: land in tiers, and tall mesas where it's hot
|
||||||
|
const SPADE = s("temperature", [
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
s("ridges_folded", [
|
||||||
|
[0.03, -0.06, 0.5],
|
||||||
|
[0.1, 0.01],
|
||||||
|
[0.3, 0.05, 0.8],
|
||||||
|
[0.4, lower_tier(0.1, 0.22)],
|
||||||
|
[0.55, 0.25, 1],
|
||||||
|
[0.6, s("upper_tier", [[0, 0.25], [0.15, 0.45]])],
|
||||||
|
[0.64, 0.5],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
5,
|
||||||
|
s("ridges_folded", [
|
||||||
|
[0.025, -0.075, 0.03],
|
||||||
|
[0.1, 0.05],
|
||||||
|
[0.175, 0.1, 1.5],
|
||||||
|
[0.2, 0.225, 0.2],
|
||||||
|
[0.4, 0.6, 7],
|
||||||
|
[0.4, 0.6, 0.1],
|
||||||
|
[0.8, 0.7],
|
||||||
|
[0.85, 0.4],
|
||||||
|
[1, 0.4],
|
||||||
|
[1.05, 0.04],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// diamond: flat land with wetlands, and deserts (their dunes are added on top, see DUNES)
|
||||||
|
const DIAMOND = s("temperature", [
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
s("vegetation", [
|
||||||
|
[2, GENTLE_RIVER],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
s("ridges_folded", [
|
||||||
|
[0.03, -0.06, 0.5],
|
||||||
|
[0.1, 0.01],
|
||||||
|
[0.15, s("wetland", [[-0.45, -0.03, 0.03], [-0.3, 0.005], [0.3, 0.005], [0.45, -0.03, -0.03]])],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[5, s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0.01, 0.15]])],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// which region: by erosion's sign, then the slow region noise
|
||||||
|
const REGIONS = s("erosion", [
|
||||||
|
[-0.02, s("region", [[-0.1, CLUB], [0.1, HEART]])],
|
||||||
|
[0.04, s("region", [[-0.1, SPADE], [0.1, DIAMOND]])],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// the regions, after REGIONS and its height multiplier
|
||||||
|
const REGION = s("regions", [[0, 0, 1]]);
|
||||||
|
const WEAK_REGION = s("regions", [[0, 0, 0.5]]);
|
||||||
|
const HILLS = s("ridges_folded", [[0, -0.1, 1], [0.175, 0.075, 0.3], [0.3, 0.25]]);
|
||||||
|
const LOW_RIDGES = s("ridges_folded", [[0.38, -0.03], [0.45, 0.03]]);
|
||||||
|
const inland = (top: number, high: number, low: number, ridge: number, regions_end: number, hills: number) =>
|
||||||
|
s("erosion_folded", [
|
||||||
|
[0, top],
|
||||||
|
[0.175, high],
|
||||||
|
[0.3, low],
|
||||||
|
[0.375, s("ridges_folded", [[0, -0.1], [0.1, 0.125, 5], [0.1667, 0.225], [0.3, ridge]])],
|
||||||
|
[0.425, WEAK_REGION],
|
||||||
|
[0.5, REGION],
|
||||||
|
[regions_end, REGION],
|
||||||
|
[hills, HILLS],
|
||||||
|
[0.95, HILLS],
|
||||||
|
[1.075, LOW_RIDGES],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// shallower than tectonic's, the world goes 64 blocks below sea level instead of 128
|
||||||
|
const DEEP_OCEAN = -0.33;
|
||||||
|
const OCEAN = -0.17;
|
||||||
|
|
||||||
|
// target height above sea level: the ocean floor, then coasts, then further inland mountains where erosion is low
|
||||||
|
// and the regions where it's high
|
||||||
|
const OFFSET = s("continents", [
|
||||||
|
[-0.45, DEEP_OCEAN],
|
||||||
|
[-0.35, OCEAN],
|
||||||
|
[-0.195, -0.14],
|
||||||
|
[
|
||||||
|
-0.155,
|
||||||
|
s("erosion_folded", [
|
||||||
|
[0.2, s("ridges_folded", [[0, -0.1], [0.15, 0.15, 3], [0.25, 0.22]]), -0.17],
|
||||||
|
[0.3, s("ridges_folded", [[0.03, -0.06, 0.5], [0.1, 0]])],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[
|
||||||
0,
|
0,
|
||||||
|
s("erosion_folded", [
|
||||||
|
[0, 0.65],
|
||||||
|
[0.15, 0.425, -1.5],
|
||||||
|
[0.3, 0.33],
|
||||||
|
[0.375, s("ridges_folded", [[0, -0.1], [0.15, 0.15], [0.3, 0.25]])],
|
||||||
|
[0.4, RIVER],
|
||||||
|
[0.95, RIVER],
|
||||||
|
[1.075, LOW_RIDGES],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[0.1, inland(0.95, 0.55, 0.36, 0.3, 0.825, 0.875)],
|
||||||
|
[0.8, inland(1.1, 0.65, 0.38, 0.33, 0.8, 0.9)],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 3d noise strength: mountains are rougher than plains
|
// how jagged the peaks are, 0 to 0.2: only the tallest mountains, deep inland
|
||||||
const ROUGHNESS = spline("erosion", [-1, -0.5, 0, 0.5, 1], [0.32, 0.22, 0.14, 0.1, 0.06]);
|
const JAGGEDNESS = s("continents", [[0, 0], [0.175, s("erosion_folded", [[0, 0.2], [0.125, 0]])]]);
|
||||||
|
|
||||||
|
// tectonic's factor: how steeply density rises below the surface. low is rugged ground full of overhangs, on the
|
||||||
|
// ridges of hilly land
|
||||||
|
const rugged = (ridges: S) => s("erosion_folded", [[0.825, 5.6], [0.875, ridges], [0.975, ridges], [1.025, 5.6]]);
|
||||||
|
const FACTOR = s("continents", [
|
||||||
|
[-0.19, 5.6],
|
||||||
|
[-0.15, rugged(s("ridges", [[0, 5.6], [0.1, 0.6]]))],
|
||||||
|
[0.03, rugged(s("ridges", [[0, 5.6], [0.1, 0.6]]))],
|
||||||
|
[0.06, rugged(s("ridges_folded", [[0.25, 5.6], [0.4, 1.3]]))],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// how tall dunes get, up to 6, in hot flat land of the diamond region
|
||||||
|
const DUNE_HEIGHT = s("temperature", [
|
||||||
|
[4, 0],
|
||||||
|
[5, s("region", [[0, 0], [0.1, s("ridges_folded", [[0, 0], [0.25, 6]])]])],
|
||||||
|
]);
|
||||||
|
const DUNES = s("continents", [
|
||||||
|
[0, 0],
|
||||||
|
[0.05, s("erosion_folded", [[0.4, 0], [0.45, DUNE_HEIGHT], [0.8, DUNE_HEIGHT], [0.85, 0]])],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// jungle pillars: tall narrow columns in heart's jungles, on the ridges between its valleys
|
||||||
|
const pillar = (mid: number, high: number) => s("pillar", [[0.05, 0], [0.2, mid, -0.2], [0.5, high, 0.05]]);
|
||||||
|
const JUNGLE_PILLARS = s("region", [
|
||||||
|
[0, 0],
|
||||||
|
[
|
||||||
|
0.1,
|
||||||
|
s("temperature", [
|
||||||
|
[3, 0],
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
s("vegetation", [
|
||||||
|
[3, 0],
|
||||||
|
[4, s("ridges", [[-0.75, pillar(0.4, 0.7)], [-0.175, pillar(0.25, 0.5)], [-0.125, 0]])],
|
||||||
|
[
|
||||||
|
5,
|
||||||
|
s("ridges_folded", [[0.125, 0], [0.175, pillar(0.25, 0.5)], [0.75, pillar(0.45, 0.75)], [
|
||||||
|
0.8,
|
||||||
|
0,
|
||||||
|
]]),
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[5, 0],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
const PILLARS = s("continents", [
|
||||||
|
[0, 0],
|
||||||
|
[0.1, s("erosion", [[-0.875, 0], [-0.825, JUNGLE_PILLARS], [-0.425, JUNGLE_PILLARS], [-0.375, 0]])],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// blocks per unit of tectonic's height. without its vertical scale of 1.125, which is for minecraft's taller world
|
||||||
|
const BLOCKS_PER_UNIT = 128;
|
||||||
|
// the 3d noise's strength at tectonic's usual factor
|
||||||
|
const ROUGHNESS = 0.12;
|
||||||
|
// rivers that reach mountains go under them in a tunnel this tall around sea level, this wide in ridges
|
||||||
|
const RIVER_TUNNEL_BOTTOM = SEA_LEVEL - 5;
|
||||||
|
const RIVER_TUNNEL_TOP = SEA_LEVEL + 4;
|
||||||
|
const RIVER_TUNNEL_WIDTH = 0.035;
|
||||||
|
// only where the ground is this far above the river, otherwise it's an open valley
|
||||||
|
const RIVER_TUNNEL_COVER = 12;
|
||||||
|
|
||||||
export class OverworldTerrain {
|
export class OverworldTerrain {
|
||||||
#continentalness: OctaveNoise2D;
|
#continents: OctaveNoise2D;
|
||||||
|
#island_a: OctaveNoise2D;
|
||||||
|
#island_b: OctaveNoise2D;
|
||||||
#erosion: OctaveNoise2D;
|
#erosion: OctaveNoise2D;
|
||||||
#weirdness: OctaveNoise2D;
|
#ridges: OctaveNoise2D;
|
||||||
#temperature: OctaveNoise2D;
|
#temperature: OctaveNoise2D;
|
||||||
#humidity: OctaveNoise2D;
|
#humidity: OctaveNoise2D;
|
||||||
#warp_x: OctaveNoise2D;
|
#warp_x: OctaveNoise2D;
|
||||||
#warp_z: OctaveNoise2D;
|
#warp_z: OctaveNoise2D;
|
||||||
#jagged: OctaveNoise2D;
|
#region: OctaveNoise2D;
|
||||||
#plateau: OctaveNoise2D;
|
#height_multiplier: OctaveNoise2D;
|
||||||
#shattered: OctaveNoise2D;
|
#lower_tier: OctaveNoise2D;
|
||||||
#sky: OctaveNoise2D;
|
#upper_tier: OctaveNoise2D;
|
||||||
#island_shape: OctaveNoise2D;
|
#badlands: OctaveNoise2D;
|
||||||
#island_height: OctaveNoise2D;
|
#hills: OctaveNoise2D;
|
||||||
|
#wetland: OctaveNoise2D;
|
||||||
|
#pillar: OctaveNoise2D;
|
||||||
|
#dune: OctaveNoise2D;
|
||||||
|
#dune_warp: OctaveNoise2D;
|
||||||
|
#mountain_ridges: OctaveNoise2D;
|
||||||
#ground: OctaveNoise3D;
|
#ground: OctaveNoise3D;
|
||||||
#island_noise: OctaveNoise3D;
|
|
||||||
#cheese: OctaveNoise3D;
|
#cheese: OctaveNoise3D;
|
||||||
#spaghetti_a: OctaveNoise3D;
|
#spaghetti_a: OctaveNoise3D;
|
||||||
#spaghetti_b: OctaveNoise3D;
|
#spaghetti_b: OctaveNoise3D;
|
||||||
#entrances: OctaveNoise2D;
|
#entrances: OctaveNoise2D;
|
||||||
|
|
||||||
|
// the amplitudes match the quantile tables above, so each noise can be spread evenly
|
||||||
constructor(seed: string) {
|
constructor(seed: string) {
|
||||||
this.#continentalness = new OctaveNoise2D(seed, "continentalness", 1024, [1, 1, 2, 2, 1, 1]);
|
this.#continents = new OctaveNoise2D(seed, "continents", 2560, [1, 1, 2, 2, 1, 1]);
|
||||||
this.#erosion = new OctaveNoise2D(seed, "erosion", 768, [1, 1, 0, 1, 1]);
|
this.#island_a = new OctaveNoise2D(seed, "island_a", 320, [1, 1]);
|
||||||
this.#weirdness = new OctaveNoise2D(seed, "weirdness", 256, [1, 2, 1]);
|
this.#island_b = new OctaveNoise2D(seed, "island_b", 320, [1, 1]);
|
||||||
|
this.#erosion = new OctaveNoise2D(seed, "erosion", 1280, [1, 1, 0, 1, 1]);
|
||||||
|
this.#ridges = new OctaveNoise2D(seed, "ridges", 640, [1, 2, 1]);
|
||||||
this.#temperature = new OctaveNoise2D(seed, "temperature", 1536, [1.5, 0, 1]);
|
this.#temperature = new OctaveNoise2D(seed, "temperature", 1536, [1.5, 0, 1]);
|
||||||
this.#humidity = new OctaveNoise2D(seed, "humidity", 512, [1, 1]);
|
this.#humidity = new OctaveNoise2D(seed, "humidity", 512, [1, 1]);
|
||||||
this.#warp_x = new OctaveNoise2D(seed, "warp_x", 200, [1, 1]);
|
this.#warp_x = new OctaveNoise2D(seed, "warp_x", 200, [1, 1]);
|
||||||
this.#warp_z = new OctaveNoise2D(seed, "warp_z", 200, [1, 1]);
|
this.#warp_z = new OctaveNoise2D(seed, "warp_z", 200, [1, 1]);
|
||||||
this.#jagged = new OctaveNoise2D(seed, "jagged", 48, [1, 1]);
|
this.#region = new OctaveNoise2D(seed, "region", 2048, [1, 1, 2, 2, 1, 1]);
|
||||||
this.#plateau = new OctaveNoise2D(seed, "plateau", 640, [1, 1]);
|
this.#height_multiplier = new OctaveNoise2D(seed, "height_multiplier", 1024, [1, 2, 1]);
|
||||||
this.#shattered = new OctaveNoise2D(seed, "shattered", 512, [1, 1]);
|
this.#lower_tier = new OctaveNoise2D(seed, "lower_tier", 512, [1, 2, 1]);
|
||||||
this.#sky = new OctaveNoise2D(seed, "sky", 900, [1, 1]);
|
this.#upper_tier = new OctaveNoise2D(seed, "upper_tier", 512, [1, 2, 1]);
|
||||||
this.#island_shape = new OctaveNoise2D(seed, "island_shape", 56, [1, 1]);
|
this.#badlands = new OctaveNoise2D(seed, "badlands", 512, [1, 2, 1]);
|
||||||
this.#island_height = new OctaveNoise2D(seed, "island_height", 300, [1, 1]);
|
this.#hills = new OctaveNoise2D(seed, "hills", 320, [1, 1]);
|
||||||
|
this.#wetland = new OctaveNoise2D(seed, "wetland", 96, [1, 1]);
|
||||||
|
this.#pillar = new OctaveNoise2D(seed, "pillar", 32, [1, 1]);
|
||||||
|
this.#dune = new OctaveNoise2D(seed, "dune", 96, [1, 1]);
|
||||||
|
this.#dune_warp = new OctaveNoise2D(seed, "dune_warp", 400, [1, 1]);
|
||||||
|
this.#mountain_ridges = new OctaveNoise2D(seed, "mountain_ridges", 256, [1, 1]);
|
||||||
this.#ground = new OctaveNoise3D(seed, "ground", 64, [1, 1, 0.5], 1.2);
|
this.#ground = new OctaveNoise3D(seed, "ground", 64, [1, 1, 0.5], 1.2);
|
||||||
this.#island_noise = new OctaveNoise3D(seed, "island_noise", 24, [1, 1]);
|
|
||||||
this.#cheese = new OctaveNoise3D(seed, "cheese", 80, [1, 0.5], 0.6);
|
this.#cheese = new OctaveNoise3D(seed, "cheese", 80, [1, 0.5], 0.6);
|
||||||
this.#spaghetti_a = new OctaveNoise3D(seed, "spaghetti_a", 64, [1], 0.8);
|
this.#spaghetti_a = new OctaveNoise3D(seed, "spaghetti_a", 64, [1], 0.8);
|
||||||
this.#spaghetti_b = new OctaveNoise3D(seed, "spaghetti_b", 64, [1], 0.8);
|
this.#spaghetti_b = new OctaveNoise3D(seed, "spaghetti_b", 64, [1], 0.8);
|
||||||
@@ -255,83 +526,84 @@ export class OverworldTerrain {
|
|||||||
// a small warp, so coasts and biome edges aren't the noise's smooth blobs
|
// a small warp, so coasts and biome edges aren't the noise's smooth blobs
|
||||||
const wx = x + this.#warp_x.sample(x, z) * 24;
|
const wx = x + this.#warp_x.sample(x, z) * 24;
|
||||||
const wz = z + this.#warp_z.sample(x, z) * 24;
|
const wz = z + this.#warp_z.sample(x, z) * 24;
|
||||||
const weirdness = QUANTILES_3.even(this.#weirdness.sample(wx, wz));
|
|
||||||
return {
|
return {
|
||||||
continentalness: QUANTILES_6.even(this.#continentalness.sample(wx, wz)),
|
continentalness: this.#continentalness(wx, wz),
|
||||||
erosion: QUANTILES_4.even(this.#erosion.sample(wx, wz)),
|
erosion: QUANTILES_4.even(this.#erosion.sample(wx, wz)) * 1.05,
|
||||||
weirdness,
|
ridges: QUANTILES_3.even(this.#ridges.sample(wx, wz)) * 0.7,
|
||||||
pv: peaks_and_valleys(weirdness),
|
|
||||||
temperature: QUANTILES_TEMPERATURE.even(this.#temperature.sample(wx, wz)),
|
temperature: QUANTILES_TEMPERATURE.even(this.#temperature.sample(wx, wz)),
|
||||||
humidity: QUANTILES_2.even(this.#humidity.sample(wx, wz)),
|
humidity: QUANTILES_2.even(this.#humidity.sample(wx, wz)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// like tectonic: land is where the continents noise is far from 0, so oceans wind along where it crosses 0. out
|
||||||
|
// in the deep ocean, islands come up where either of two island noises is high
|
||||||
|
#continentalness(x: number, z: number) {
|
||||||
|
const far = Math.abs(QUANTILES_6.even(this.#continents.sample(x, z))) * 0.85;
|
||||||
|
const continents = -0.8 + CONTINENT_SHAPE.get({ continents: far } as TerrainInputs);
|
||||||
|
if (continents >= -0.5) return continents;
|
||||||
|
// scaled so about 3 in 100 of the deep ocean is island, both noises are spread evenly unlike tectonic's
|
||||||
|
const island = Math.max(
|
||||||
|
QUANTILES_2.even(this.#island_a.sample(x, z)),
|
||||||
|
QUANTILES_2.even(this.#island_b.sample(x, z)),
|
||||||
|
) * 0.76;
|
||||||
|
const deep = smoothstep(-0.5, -0.8, continents) * 0.7;
|
||||||
|
return Math.max(continents, (island + 0.05) * deep - 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
column(x: number, z: number): TerrainColumn {
|
column(x: number, z: number): TerrainColumn {
|
||||||
const climate = this.climate(x, z);
|
const climate = this.climate(x, z);
|
||||||
const { continentalness: c, erosion: e } = climate;
|
const { continentalness, erosion, ridges } = climate;
|
||||||
const inputs: SplineInputs = climate;
|
const lower = QUANTILES_3.even(this.#lower_tier.sample(x, z));
|
||||||
const inland = smoothstep(-0.1, 0.3, c);
|
const upper = QUANTILES_3.even(this.#upper_tier.sample(x, z));
|
||||||
|
const inputs: TerrainInputs = {
|
||||||
let height = OFFSET.get(inputs);
|
continents: continentalness,
|
||||||
|
erosion,
|
||||||
// jagged peaks: sharp ridges pushed up from the tallest mountains
|
erosion_folded: Math.abs(erosion),
|
||||||
const jaggedness = clamp(JAGGEDNESS.get(inputs), 0, 1) * inland;
|
ridges,
|
||||||
if (jaggedness > 0) {
|
ridges_folded: Math.abs(ridges),
|
||||||
const ridge = 1 - Math.abs(this.#jagged.sample(x, z));
|
region: QUANTILES_6.even(this.#region.sample(x, z)) * 0.5 + 0.1,
|
||||||
height += jaggedness * 26 * ridge * ridge;
|
regions: 0,
|
||||||
}
|
temperature: TEMPERATURE_INDEX.get({ temperature: climate.temperature } as TerrainInputs),
|
||||||
|
vegetation: VEGETATION_INDEX.get({ vegetation: climate.humidity } as TerrainInputs),
|
||||||
// terraced plateaus: raised land cut into flat benches and cliffs, like terralith's
|
lower_tier: Math.abs(lower) * 0.3,
|
||||||
// yosemite cliffs and painted mountains
|
upper_tier: Math.abs(upper) * 0.3,
|
||||||
const plateau = smoothstep(0.35, 0.55, QUANTILES_2.even(this.#plateau.sample(x, z))) *
|
badlands: Math.abs(QUANTILES_3.even(this.#badlands.sample(x, z))) * 0.7,
|
||||||
smoothstep(-0.75, -0.45, e) * (1 - smoothstep(0.1, 0.4, e)) * smoothstep(-0.05, 0.1, c);
|
hills: Math.abs(QUANTILES_2.even(this.#hills.sample(x, z))),
|
||||||
if (plateau > 0 && climate.pv > -0.8) {
|
wetland: QUANTILES_2.even(this.#wetland.sample(x, z)) * 0.6,
|
||||||
const raised = height + 20 * plateau;
|
pillar: 1.7 * (QUANTILES_2.even(this.#pillar.sample(x, z)) * 0.7 - 0.35),
|
||||||
height = lerp(plateau, height, terrace(raised, 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
// shattered hills: ground broken up by strong 3d noise into overhangs, arches and spires
|
|
||||||
const shattered = smoothstep(0.55, 0.75, QUANTILES_2.even(this.#shattered.sample(x, z))) *
|
|
||||||
smoothstep(-0.6, -0.3, e) * (1 - smoothstep(0.3, 0.5, e)) * smoothstep(-0.05, 0.1, c);
|
|
||||||
|
|
||||||
const roughness = ROUGHNESS.get(inputs) + shattered * 0.9;
|
|
||||||
|
|
||||||
return {
|
|
||||||
climate,
|
|
||||||
height: SEA_LEVEL + height,
|
|
||||||
roughness,
|
|
||||||
plateau,
|
|
||||||
shattered,
|
|
||||||
jaggedness,
|
|
||||||
island: this.#island(x, z),
|
|
||||||
};
|
};
|
||||||
|
const multiplier = clamp(1.2 + 0.4 * QUANTILES_3.even(this.#height_multiplier.sample(x, z)), 0.8, 1.6);
|
||||||
|
inputs.regions = multiplier * REGIONS.get(inputs);
|
||||||
|
|
||||||
|
const offset = OFFSET.get(inputs) + PILLARS.get(inputs);
|
||||||
|
let height = offset * BLOCKS_PER_UNIT;
|
||||||
|
|
||||||
|
// jagged peaks: sharp ridgelines along the tallest mountains
|
||||||
|
const jaggedness = clamp(JAGGEDNESS.get(inputs) / 0.2, 0, 1);
|
||||||
|
if (jaggedness > 0) {
|
||||||
|
const ridge = 1 - Math.abs(this.#mountain_ridges.sample(x, z));
|
||||||
|
height += jaggedness * 36 * ridge * ridge;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skylands: rare regions of floating islands, flat topped with long hanging undersides
|
// dunes: long ridges of sand, swept one way
|
||||||
#island(x: number, z: number): TerrainColumn["island"] {
|
const dunes = DUNES.get(inputs) / 6;
|
||||||
const region = smoothstep(0.9, 0.97, QUANTILES_2.even(this.#sky.sample(x, z)));
|
if (dunes > 0) {
|
||||||
if (region <= 0) {
|
const sweep = this.#dune_warp.sample(x, z) * 40;
|
||||||
return undefined;
|
const crest = 1 - Math.abs(this.#dune.sample(x + sweep, z * 0.35));
|
||||||
|
height += dunes * 7 * crest * crest;
|
||||||
}
|
}
|
||||||
const shape = region * smoothstep(0.05, 0.35, this.#island_shape.sample(x, z));
|
|
||||||
if (shape <= 0) {
|
const roughness = ROUGHNESS * 5.6 / FACTOR.get(inputs);
|
||||||
return undefined;
|
const valley = 1 - inputs.ridges_folded / RIVER_TUNNEL_WIDTH;
|
||||||
}
|
const covered = height > RIVER_TUNNEL_TOP - SEA_LEVEL + RIVER_TUNNEL_COVER;
|
||||||
const center = 178 + this.#island_height.sample(x, z) * 24;
|
const underground_river = valley > 0 && covered && continentalness > -0.17 ? valley : 0;
|
||||||
return { top: center + 2 + 6 * shape, bottom: center - 4 - 34 * shape * Math.sqrt(shape) };
|
|
||||||
|
return { climate, height: SEA_LEVEL + height, roughness, jaggedness, underground_river };
|
||||||
}
|
}
|
||||||
|
|
||||||
// positive is solid, before caves
|
// positive is solid, before caves
|
||||||
density(column: TerrainColumn, x: number, y: number, z: number) {
|
density(column: TerrainColumn, x: number, y: number, z: number) {
|
||||||
let density = (column.height - y) / THICKNESS + column.roughness * this.#ground.sample(x, y, z);
|
let density = (column.height - y) / THICKNESS + column.roughness * this.#ground.sample(x, y, z);
|
||||||
|
|
||||||
const island = column.island;
|
|
||||||
if (island && y > island.bottom - 4 && y < island.top + 4) {
|
|
||||||
const solid = Math.min((island.top - y) / 3, (y - island.bottom) / 6) +
|
|
||||||
0.4 * this.#island_noise.sample(x, y, z);
|
|
||||||
density = Math.max(density, solid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y > TOP_SLIDE_START) {
|
if (y > TOP_SLIDE_START) {
|
||||||
density -= smoothstep(TOP_SLIDE_START, TOP_SLIDE_END, y) * 4;
|
density -= smoothstep(TOP_SLIDE_START, TOP_SLIDE_END, y) * 4;
|
||||||
}
|
}
|
||||||
@@ -342,17 +614,23 @@ export class OverworldTerrain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// negative where a cave is. caves stay under the ground's skin except at entrances, and never break
|
// negative where a cave is. caves stay under the ground's skin except at entrances, and never break
|
||||||
// the floor of oceans and rivers
|
// the floor of oceans and rivers. rivers under mountains are tunnels, see generate_overworld for their water
|
||||||
cave(column: TerrainColumn, x: number, y: number, z: number) {
|
cave(column: TerrainColumn, x: number, y: number, z: number) {
|
||||||
if (y < MIN_CAVE_Y) {
|
if (y < MIN_CAVE_Y) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
let river = 1;
|
||||||
|
if (column.underground_river > 0 && y >= RIVER_TUNNEL_BOTTOM - 2 && y <= RIVER_TUNNEL_TOP + 2) {
|
||||||
|
const middle = (RIVER_TUNNEL_BOTTOM + RIVER_TUNNEL_TOP) / 2;
|
||||||
|
const half = (RIVER_TUNNEL_TOP - RIVER_TUNNEL_BOTTOM) / 2;
|
||||||
|
river = (Math.max(1 - column.underground_river, Math.abs(y - middle) / half) - 1) * 4;
|
||||||
|
}
|
||||||
const depth = column.height - y;
|
const depth = column.height - y;
|
||||||
if (column.height < SEA_LEVEL + 3 && depth < 14) {
|
if (column.height < SEA_LEVEL + 3 && depth < 14) {
|
||||||
return 1;
|
return river;
|
||||||
}
|
}
|
||||||
if (depth < 7 && this.#entrances.sample(x, z) < 0.5) {
|
if (depth < 7 && this.#entrances.sample(x, z) < 0.5) {
|
||||||
return 1;
|
return river;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cheese caves: big open caverns
|
// cheese caves: big open caverns
|
||||||
@@ -361,13 +639,6 @@ export class OverworldTerrain {
|
|||||||
const a = Math.abs(this.#spaghetti_a.sample(x, y, z));
|
const a = Math.abs(this.#spaghetti_a.sample(x, y, z));
|
||||||
const b = Math.abs(this.#spaghetti_b.sample(x, y, z));
|
const b = Math.abs(this.#spaghetti_b.sample(x, y, z));
|
||||||
const spaghetti = (Math.max(a, b) - 0.07) * 8;
|
const spaghetti = (Math.max(a, b) - 0.07) * 8;
|
||||||
return Math.min(cheese, spaghetti);
|
return Math.min(cheese, spaghetti, river);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// flat benches every step blocks, joined by steep cliffs
|
|
||||||
function terrace(height: number, step: number) {
|
|
||||||
const k = height / step;
|
|
||||||
const floor = Math.floor(k);
|
|
||||||
return (floor + smoothstep(0.4, 0.6, k - floor)) * step;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -47,14 +47,8 @@ export const BIOME_TREES: Record<string, { chance: number; kinds: TreeKind[] }>
|
|||||||
"bworld:snowy_taiga": { chance: 0.6, kinds: ["spruce"] },
|
"bworld:snowy_taiga": { chance: 0.6, kinds: ["spruce"] },
|
||||||
"bworld:snowy_plains": { chance: 0.03, kinds: ["spruce"] },
|
"bworld:snowy_plains": { chance: 0.03, kinds: ["spruce"] },
|
||||||
"bworld:snowy_slopes": { chance: 0.06, kinds: ["spruce"] },
|
"bworld:snowy_slopes": { chance: 0.06, kinds: ["spruce"] },
|
||||||
"bworld:snowy_cliffs": { chance: 0.1, kinds: ["spruce"] },
|
|
||||||
"bworld:alpine_highlands": { chance: 0.2, kinds: ["spruce", "spruce", "oak"] },
|
|
||||||
"bworld:yosemite_cliffs": { chance: 0.2, kinds: ["spruce", "oak"] },
|
|
||||||
"bworld:stony_spires": { chance: 0.12, kinds: ["spruce"] },
|
|
||||||
"bworld:savanna": { chance: 0.15, kinds: ["acacia", "acacia", "oak"] },
|
"bworld:savanna": { chance: 0.15, kinds: ["acacia", "acacia", "oak"] },
|
||||||
"bworld:shattered_savanna": { chance: 0.12, kinds: ["acacia"] },
|
|
||||||
"bworld:jungle": { chance: 1, kinds: ["jungle", "jungle", "big_oak"] },
|
"bworld:jungle": { chance: 1, kinds: ["jungle", "jungle", "big_oak"] },
|
||||||
"bworld:skylands": { chance: 0.3, kinds: ["oak", "big_oak"] },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface TreeSite {
|
export interface TreeSite {
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ Commands can only be registered during `setup`.
|
|||||||
| `/time add <ticks>` | Moves time forward |
|
| `/time add <ticks>` | Moves time forward |
|
||||||
| `/locatebiome <biome>` | Says where the nearest biome of that kind is, up to 6400 blocks away |
|
| `/locatebiome <biome>` | Says where the nearest biome of that kind is, up to 6400 blocks away |
|
||||||
| `/tp <x> <y> <z>` | Teleports you there |
|
| `/tp <x> <y> <z>` | Teleports you there |
|
||||||
|
| `/fly` | Toggles flying: jump goes up, sneak goes down, sprint goes faster |
|
||||||
| `/tps` | Shows how the game loop keeps up |
|
| `/tps` | Shows how the game loop keeps up |
|
||||||
|
| `/viewdistance [chunks]` | Shows or changes how far the server sends chunks, until it restarts |
|
||||||
| `/skin [url] [slim\|normal]` | Changes your skin to a 64×64 PNG, or back to the default |
|
| `/skin [url] [slim\|normal]` | Changes your skin to a 64×64 PNG, or back to the default |
|
||||||
| `/help [command]` | Every command's usage, or one's |
|
| `/help [command]` | Every command's usage, or one's |
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ stay on the server.
|
|||||||
|
|
||||||
- Chunks are 16×256×16 and sent whole, compressed, in batches, nearest first. The server paces batches by how fast each
|
- Chunks are 16×256×16 and sent whole, compressed, in batches, nearest first. The server paces batches by how fast each
|
||||||
client says it loads them.
|
client says it loads them.
|
||||||
- Players see chunks up to their view distance, at most 10 on the server's side. Light isn't sent: clients light chunks
|
- Players see chunks up to their view distance, at most 16 on the server's side. Light isn't sent: clients light chunks
|
||||||
themselves.
|
themselves.
|
||||||
- Block changes go only to players who have the chunk. Everyone else gets the change with the chunk when they come
|
- Block changes go only to players who have the chunk. Everyone else gets the change with the chunk when they come
|
||||||
close.
|
close.
|
||||||
|
|||||||
@@ -94,13 +94,16 @@ Generated blocks don't run `on_create`, and worldgen scripts can't use the serve
|
|||||||
|
|
||||||
## Terrain
|
## Terrain
|
||||||
|
|
||||||
The terrain itself is built into the engine (`common/worldgen/`). It works like Minecraft 1.18+ with the Terralith
|
The terrain itself is built into the engine (`common/worldgen/`). It works like Minecraft 1.18+, shaped after the
|
||||||
datapack: continentalness, erosion and weirdness noises set every column's height and roughness, a 3D density is carved
|
[Tectonic](https://github.com/Apollounknowndev/tectonic) mod: continents, erosion and ridges noises set every column's
|
||||||
into caves, and on top of that come terraced plateaus, shattered hills, river valleys and gorges, jagged peaks and rare
|
height and roughness, and a 3D density is carved into caves. Oceans wind between large continents, with islands out at
|
||||||
sky islands. Biome ids are the keys of `BIOMES` in `common/worldgen/overworld.ts`, like `bworld:yosemite_cliffs` or
|
sea. Mountain ranges rise where erosion is low, and rivers run along the valleys between ridges, going underground where
|
||||||
`bworld:skylands`.
|
they reach mountains. The flatter land is split into regions with their own shapes: valleys and plateaus (with badlands
|
||||||
|
ridges where it's hot), tiered mesas, rolling hills and jungle pillars, and wetlands and desert dunes.
|
||||||
|
|
||||||
`deno run -A tools/worldgen_preview.ts [seed]` renders it to PNG files.
|
Biome ids are the keys of `BIOMES` in `common/worldgen/overworld.ts`, like `bworld:plains` or `bworld:jagged_peaks`.
|
||||||
|
|
||||||
|
`deno run -A tools/worldgen_preview.ts [seed] [out dir] [x z]` renders it to PNG files, around chunk `x z`.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> `register_terrain` exists in the API for mods that replace the terrain generator, but it throws for now: the terrain
|
> `register_terrain` exists in the API for mods that replace the terrain generator, but it throws for now: the terrain
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ How the server sends the world, like Minecraft Java since 1.20.2. The code is in
|
|||||||
Light isn't sent.
|
Light isn't sent.
|
||||||
- **Numeric ids.** Chunks use the server's numeric block ids, and `join.blocks` lists the string id for each, like
|
- **Numeric ids.** Chunks use the server's numeric block ids, and `join.blocks` lists the string id for each, like
|
||||||
Minecraft's registry sync. Clients translate them as a chunk loads.
|
Minecraft's registry sync. Clients translate them as a chunk loads.
|
||||||
- **The view.** Players send their view distance with `ready` and `view_distance`. The server uses up to 10 chunks, and
|
- **The view.** Players send their view distance with `ready` and `view_distance`. The server uses up to 16 chunks, and
|
||||||
sends a round area around the player plus the ring past it, which clients need to mesh and light the edge (Minecraft's
|
sends a round area around the player plus the ring past it, which clients need to mesh and light the edge (Minecraft's
|
||||||
`ChunkTrackingView`). Moving into another chunk sends `set_center_chunk`, and `forget_level_chunk` for each chunk that
|
`ChunkTrackingView`). Moving into another chunk sends `set_center_chunk`, and `forget_level_chunk` for each chunk that
|
||||||
left the view.
|
left the view.
|
||||||
|
|||||||
@@ -81,6 +81,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Tectonic
|
||||||
|
|
||||||
|
The overworld's terrain is shaped after Tectonic by Apollo: https://github.com/Apollounknowndev/tectonic
|
||||||
|
|
||||||
|
License: MIT
|
||||||
|
|
||||||
# Voxel libre
|
# Voxel libre
|
||||||
|
|
||||||
https://github.com/VoxeLibre/VoxeLibre
|
https://github.com/VoxeLibre/VoxeLibre
|
||||||
|
|||||||
@@ -95,8 +95,9 @@ const GROUND_EPSILON = 0.02;
|
|||||||
const MAX_CATCH_UP_DAYS = 64;
|
const MAX_CATCH_UP_DAYS = 64;
|
||||||
// how long a client gets between welcome and ready to download and load everything
|
// how long a client gets between welcome and ready to download and load everything
|
||||||
const READY_TIMEOUT_TICKS = 60 * TICKS_PER_SECOND;
|
const READY_TIMEOUT_TICKS = 60 * TICKS_PER_SECOND;
|
||||||
// the furthest the server sends chunks around a player, and what players who don't say get. minecraft's default
|
// the furthest the server sends chunks around a player, and what players who don't say get, until /viewdistance
|
||||||
const SERVER_VIEW_DISTANCE = 10;
|
// changes it
|
||||||
|
const SERVER_VIEW_DISTANCE = 16;
|
||||||
// how long a tick can spend building chunks for players, the rest go out on the next ticks
|
// how long a tick can spend building chunks for players, the rest go out on the next ticks
|
||||||
const CHUNK_SEND_BUDGET_MS = 20;
|
const CHUNK_SEND_BUDGET_MS = 20;
|
||||||
|
|
||||||
@@ -171,6 +172,8 @@ export class GameServer {
|
|||||||
do_mob_spawning = true;
|
do_mob_spawning = true;
|
||||||
// what runs tick(), for /tps. tests call tick() themselves
|
// what runs tick(), for /tps. tests call tick() themselves
|
||||||
loop?: GameLoop;
|
loop?: GameLoop;
|
||||||
|
// SERVER_VIEW_DISTANCE, or what /viewdistance set it to. not saved, it's for testing
|
||||||
|
view_distance = SERVER_VIEW_DISTANCE;
|
||||||
// how long a tick can spend building chunks for players. tests lift it so what gets sent doesn't depend on speed
|
// how long a tick can spend building chunks for players. tests lift it so what gets sent doesn't depend on speed
|
||||||
chunk_send_budget_ms = CHUNK_SEND_BUDGET_MS;
|
chunk_send_budget_ms = CHUNK_SEND_BUDGET_MS;
|
||||||
|
|
||||||
@@ -392,6 +395,15 @@ export class GameServer {
|
|||||||
return this.#tick;
|
return this.#tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the furthest the server sends chunks to anyone, for now. players who asked for more get more, up to it
|
||||||
|
set_view_distance(distance: number) {
|
||||||
|
this.view_distance = distance;
|
||||||
|
for (const player of this.players()) {
|
||||||
|
player.chunks.view_distance = view_distance(player.requested_view_distance, distance);
|
||||||
|
this.#update_view(player, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
players(): ServerPlayer[] {
|
players(): ServerPlayer[] {
|
||||||
return [...this.#players.values()];
|
return [...this.#players.values()];
|
||||||
}
|
}
|
||||||
@@ -695,7 +707,7 @@ export class GameServer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.#pending.delete(conn);
|
this.#pending.delete(conn);
|
||||||
this.#join(conn, pending.name, view_distance(message.view_distance));
|
this.#join(conn, pending.name, message.view_distance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,14 +716,15 @@ export class GameServer {
|
|||||||
this.#host.close(conn);
|
this.#host.close(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
#join(conn: number, raw_name: unknown, view_distance: number) {
|
#join(conn: number, raw_name: unknown, requested_view_distance: unknown) {
|
||||||
const player = new ServerPlayer(
|
const player = new ServerPlayer(
|
||||||
this.entities,
|
this.entities,
|
||||||
conn,
|
conn,
|
||||||
this.#unique_name(raw_name),
|
this.#unique_name(raw_name),
|
||||||
view_distance,
|
view_distance(requested_view_distance, this.view_distance),
|
||||||
() => this.recipes.shaped,
|
() => this.recipes.shaped,
|
||||||
);
|
);
|
||||||
|
if (is_int(requested_view_distance)) player.requested_view_distance = requested_view_distance;
|
||||||
const saved = this.#saved_players[player.name];
|
const saved = this.#saved_players[player.name];
|
||||||
if (saved) {
|
if (saved) {
|
||||||
player.load_player(saved);
|
player.load_player(saved);
|
||||||
@@ -778,7 +791,8 @@ export class GameServer {
|
|||||||
}
|
}
|
||||||
case "view_distance":
|
case "view_distance":
|
||||||
if (is_int(message.distance)) {
|
if (is_int(message.distance)) {
|
||||||
player.chunks.view_distance = view_distance(message.distance);
|
player.requested_view_distance = message.distance;
|
||||||
|
player.chunks.view_distance = view_distance(message.distance, this.view_distance);
|
||||||
this.#update_view(player, true);
|
this.#update_view(player, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1283,6 +1297,31 @@ export class GameServer {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: only let operators do this
|
||||||
|
register(
|
||||||
|
literal<ServerCommandSource>("fly").describe("Toggles flying").executes((context) => {
|
||||||
|
const player = context.source.server_player;
|
||||||
|
player.flying = !player.flying;
|
||||||
|
player.fall_distance = 0;
|
||||||
|
context.source.send_message(player.flying ? "You can fly" : "You can't fly anymore");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: only let operators do this
|
||||||
|
register(
|
||||||
|
literal<ServerCommandSource>("viewdistance").describe("Shows or changes the server's view distance")
|
||||||
|
.executes((context) => {
|
||||||
|
context.source.send_message(`The view distance is ${this.view_distance} chunks`);
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
argument<number, ServerCommandSource>("chunks", integer(MIN_VIEW_DISTANCE, MAX_VIEW_DISTANCE))
|
||||||
|
.executes((context) => {
|
||||||
|
this.set_view_distance(context.get<number>("chunks"));
|
||||||
|
context.source.send_message(`Set the view distance to ${this.view_distance} chunks`);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
register(
|
register(
|
||||||
literal<ServerCommandSource>("tps").describe("Shows how the game loop keeps up").executes((context) => {
|
literal<ServerCommandSource>("tps").describe("Shows how the game loop keeps up").executes((context) => {
|
||||||
if (!this.loop) {
|
if (!this.loop) {
|
||||||
@@ -1497,6 +1536,10 @@ export class GameServer {
|
|||||||
player.fall_distance = 0;
|
player.fall_distance = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (player.flying) {
|
||||||
|
player.fall_distance = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const vitals = player.vitals;
|
const vitals = player.vitals;
|
||||||
const in_liquid = this.#in_liquid(x, y, z);
|
const in_liquid = this.#in_liquid(x, y, z);
|
||||||
@@ -1649,6 +1692,8 @@ export class GameServer {
|
|||||||
);
|
);
|
||||||
const attack_speed = player.attribute(ATTRIBUTES.attack_speed);
|
const attack_speed = player.attribute(ATTRIBUTES.attack_speed);
|
||||||
sync("attack_speed", attack_speed, () => ({ type: "attack_speed", value: attack_speed }));
|
sync("attack_speed", attack_speed, () => ({ type: "attack_speed", value: attack_speed }));
|
||||||
|
const flying = player.flying;
|
||||||
|
sync("flying", flying, () => ({ type: "flying", flying }));
|
||||||
const effects = [...player.effects.values()]
|
const effects = [...player.effects.values()]
|
||||||
.filter((effect) => effect.show_icon)
|
.filter((effect) => effect.show_icon)
|
||||||
.map(({ type, amplifier, duration }) => ({ id: type.id, amplifier, duration }));
|
.map(({ type, amplifier, duration }) => ({ id: type.id, amplifier, duration }));
|
||||||
@@ -1799,11 +1844,11 @@ function is_int(value: unknown): value is number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// what a player asked for, up to the server's
|
// what a player asked for, up to the server's
|
||||||
function view_distance(requested: unknown): number {
|
function view_distance(requested: unknown, server: number): number {
|
||||||
if (!is_int(requested)) {
|
if (!is_int(requested)) {
|
||||||
return SERVER_VIEW_DISTANCE;
|
return server;
|
||||||
}
|
}
|
||||||
return Math.min(SERVER_VIEW_DISTANCE, Math.max(MIN_VIEW_DISTANCE, Math.min(MAX_VIEW_DISTANCE, requested)));
|
return Math.min(server, Math.max(MIN_VIEW_DISTANCE, Math.min(MAX_VIEW_DISTANCE, requested)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// messages are parsed json, so the types in ClientMessage are only what a well behaved client sends
|
// messages are parsed json, so the types in ClientMessage are only what a well behaved client sends
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ export interface SavedPlayer {
|
|||||||
// base64 png, see /skin
|
// base64 png, see /skin
|
||||||
skin?: string;
|
skin?: string;
|
||||||
slim?: boolean;
|
slim?: boolean;
|
||||||
|
// see /fly
|
||||||
|
flying?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the most ticks the server moves a knocked back player, in case they never land, like in water
|
// the most ticks the server moves a knocked back player, in case they never land, like in water
|
||||||
@@ -53,6 +55,8 @@ export class ServerPlayer extends LivingEntity {
|
|||||||
override eye_height = PLAYER_EYE_HEIGHT;
|
override eye_height = PLAYER_EYE_HEIGHT;
|
||||||
// lying flat in the short box, as their client says. their client decides, like where they are
|
// lying flat in the short box, as their client says. their client decides, like where they are
|
||||||
swimming = false;
|
swimming = false;
|
||||||
|
// flying, from /fly. their client moves them without gravity, and they don't fall or get hungry from moving
|
||||||
|
flying = false;
|
||||||
|
|
||||||
inventory = new Container(INVENTORY_SIZE);
|
inventory = new Container(INVENTORY_SIZE);
|
||||||
// hunger and saturation, health is the entity's
|
// hunger and saturation, health is the entity's
|
||||||
@@ -90,6 +94,8 @@ export class ServerPlayer extends LivingEntity {
|
|||||||
sent = new Map<string, string>();
|
sent = new Map<string, string>();
|
||||||
// the chunks their client has and still needs
|
// the chunks their client has and still needs
|
||||||
chunks: PlayerChunks;
|
chunks: PlayerChunks;
|
||||||
|
// the view distance their client asked for, which the server's might cap, undefined when it didn't say
|
||||||
|
requested_view_distance: number | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
level: EntityLevel,
|
level: EntityLevel,
|
||||||
@@ -225,6 +231,7 @@ export class ServerPlayer extends LivingEntity {
|
|||||||
vitals: { health: this.health, ...this.vitals.save() },
|
vitals: { health: this.health, ...this.vitals.save() },
|
||||||
skin: this.skin,
|
skin: this.skin,
|
||||||
slim: this.slim || undefined,
|
slim: this.slim || undefined,
|
||||||
|
flying: this.flying || undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,5 +247,6 @@ export class ServerPlayer extends LivingEntity {
|
|||||||
this.load_health(saved.vitals?.health ?? this.max_health);
|
this.load_health(saved.vitals?.health ?? this.max_health);
|
||||||
this.skin = saved.skin;
|
this.skin = saved.skin;
|
||||||
this.slim = saved.slim ?? false;
|
this.slim = saved.slim ?? false;
|
||||||
|
this.flying = saved.flying === true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,3 +130,15 @@ Deno.test("block changes only go to players who have the chunk, the others get t
|
|||||||
const chunk = decode_level_chunk(game.world.level_chunk(0, 0));
|
const chunk = decode_level_chunk(game.world.level_chunk(0, 0));
|
||||||
assertEquals(chunk.blocks[120 * CHUNK_AREA + 5 * CHUNK_SIZE + 3], game.world.get_block_value(3, 120, 5));
|
assertEquals(chunk.blocks[120 * CHUNK_AREA + 5 * CHUNK_SIZE + 3], game.world.get_block_value(3, 120, 5));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("/viewdistance caps every player's view distance, and raising it gives them what they asked for", async () => {
|
||||||
|
const t = await test_game("mods");
|
||||||
|
t.join(1, "alice");
|
||||||
|
const player = t.game.players()[0];
|
||||||
|
t.send(1, { type: "view_distance", distance: 12 });
|
||||||
|
assertEquals(player.chunks.view_distance, 12);
|
||||||
|
t.send(1, { type: "chat", text: "/viewdistance 4" });
|
||||||
|
assertEquals([t.game.view_distance, player.chunks.view_distance], [4, 4]);
|
||||||
|
t.send(1, { type: "chat", text: "/viewdistance 32" });
|
||||||
|
assertEquals([t.game.view_distance, player.chunks.view_distance], [32, 12]);
|
||||||
|
});
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import { test_game } from "./helpers.ts";
|
|||||||
type Msg = any;
|
type Msg = any;
|
||||||
|
|
||||||
const ROD = "bworld:fishing_rod";
|
const ROD = "bworld:fishing_rod";
|
||||||
|
// below where the hook floats, even at the bottom of its bobbing, see the bworld mod's fishing
|
||||||
|
const HOOK_UNDER = 0.3;
|
||||||
|
|
||||||
// a player on a stone floor at y 99 with water next to them and a rod in hand
|
// a player on a stone floor at y 99 with water next to them and a rod in hand
|
||||||
async function setup() {
|
async function setup() {
|
||||||
@@ -27,16 +29,15 @@ async function setup() {
|
|||||||
const cast = () => t.send(1, { type: "use_block", x: 2, y: 100, z: 0, face: "top" });
|
const cast = () => t.send(1, { type: "use_block", x: 2, y: 100, z: 0, face: "top" });
|
||||||
const reel = () => t.send(1, { type: "use_item" });
|
const reel = () => t.send(1, { type: "use_item" });
|
||||||
const fish = () => inventory().filter((i: Msg) => i?.id === "bworld:cod" || i?.id === "bworld:salmon");
|
const fish = () => inventory().filter((i: Msg) => i?.id === "bworld:cod" || i?.id === "bworld:salmon");
|
||||||
// ticks until something bites, false if nothing did in 35 seconds
|
const hooks = () => t.game.entities.all().filter((e) => e.type === "bworld:fishing_hook");
|
||||||
|
// ticks until something bites, which pulls the hook under the water. false if nothing did in 35 seconds
|
||||||
const wait_for_bite = () => {
|
const wait_for_bite = () => {
|
||||||
t.take(1);
|
|
||||||
for (let i = 0; i < 700; i++) {
|
for (let i = 0; i < 700; i++) {
|
||||||
t.game.tick();
|
t.game.tick();
|
||||||
if (t.take(1).some((m: Msg) => m.type === "chat" && m.text.includes("biting"))) return true;
|
if (hooks()[0]?.y < 101 - HOOK_UNDER) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
const hooks = () => t.game.entities.all().filter((e) => e.type === "bworld:fishing_hook");
|
|
||||||
return { ...t, slot, rod, cast, reel, fish, wait_for_bite, hooks };
|
return { ...t, slot, rod, cast, reel, fish, wait_for_bite, hooks };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -44,8 +44,9 @@ export function mod_sources(mods_dir: string): ServerModSource[] {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// a game with an in memory host that remembers what it sent to each connection
|
// a game with an in memory host that remembers what it sent to each connection. the seed has low, dry land around
|
||||||
export async function test_game(mods_dir: string, save?: WorldSave, seed = "test-seed") {
|
// 0, 0, where players spawn and where tests build things
|
||||||
|
export async function test_game(mods_dir: string, save?: WorldSave, seed = "test-seed-90") {
|
||||||
EverythingRegistry.clear();
|
EverythingRegistry.clear();
|
||||||
const outbox = new Map<number, unknown[]>();
|
const outbox = new Map<number, unknown[]>();
|
||||||
const closed = new Set<number>();
|
const closed = new Set<number>();
|
||||||
|
|||||||
@@ -223,3 +223,17 @@ Deno.test("/tp x y z teleports you there", async () => {
|
|||||||
t.send(1, { type: "chat", text: "/tp 10 120.5 -3" });
|
t.send(1, { type: "chat", text: "/tp 10 120.5 -3" });
|
||||||
assertEquals([t.player.x, t.player.y, t.player.z], [10, 120.5, -3]);
|
assertEquals([t.player.x, t.player.y, t.player.z], [10, 120.5, -3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("/fly toggles flying, which is sent to the player, and flying doesn't fall", async () => {
|
||||||
|
const t = await setup();
|
||||||
|
t.take(1);
|
||||||
|
t.send(1, { type: "chat", text: "/fly" });
|
||||||
|
assert(t.player.flying);
|
||||||
|
t.game.tick();
|
||||||
|
assert(t.take(1).some((m: Msg) => m.type === "flying" && m.flying), "the player hears they fly");
|
||||||
|
t.move(110);
|
||||||
|
for (let y = 109; y >= 100; y--) t.move(y);
|
||||||
|
assertEquals(t.player.health, MAX_HEALTH);
|
||||||
|
t.send(1, { type: "chat", text: "/fly" });
|
||||||
|
assert(!t.player.flying);
|
||||||
|
});
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ Deno.test("trees grow on the ground, never closer than 4 blocks, even across chu
|
|||||||
let spilled_leaves = 0;
|
let spilled_leaves = 0;
|
||||||
for (let cx = -6; cx < 6; cx++) {
|
for (let cx = -6; cx < 6; cx++) {
|
||||||
for (let cz = -6; cz < 6; cz++) {
|
for (let cz = -6; cz < 6; cz++) {
|
||||||
const { blocks, spills } = generate_raw_chunk(cx, cz, "trees-test", ids);
|
const { blocks, spills } = generate_raw_chunk(cx, cz, game.world.seed, ids);
|
||||||
blocks.forEach((block, i) => {
|
blocks.forEach((block, i) => {
|
||||||
if (logs.has(block) && ground.has(blocks[i - CHUNK_AREA])) {
|
if (logs.has(block) && ground.has(blocks[i - CHUNK_AREA])) {
|
||||||
const x = cx * 16 + (i % 16);
|
const x = cx * 16 + (i % 16);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// renders the world generator to png files, for tuning it without starting the game:
|
// renders the world generator to png files, for tuning it without starting the game:
|
||||||
// deno run -A tools/worldgen_preview.ts [seed] [out dir]
|
// deno run -A tools/worldgen_preview.ts [seed] [out dir] [x z, the middle, in chunks]
|
||||||
// map.png: 4096 blocks across from the terrain's heights and biomes (fast, no caves or 3d noise)
|
// map.png: 4096 blocks across from the terrain's heights and biomes (fast, no caves or 3d noise)
|
||||||
// blocks.png: 768 blocks across from real generated chunks, top block with hill shading
|
// blocks.png: 768 blocks across from real generated chunks, top block with hill shading
|
||||||
// section.png: a slice down through the world along x, showing caves, overhangs and islands
|
// section.png: a slice down through the world along x, showing caves, overhangs and underground rivers
|
||||||
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, SEA_LEVEL } from "$/common/constants.ts";
|
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, SEA_LEVEL } from "$/common/constants.ts";
|
||||||
import { generate_raw_chunk } from "$/common/generation.ts";
|
import { generate_raw_chunk } from "$/common/generation.ts";
|
||||||
import { OverworldTerrain } from "$/common/worldgen/terrain.ts";
|
import { OverworldTerrain } from "$/common/worldgen/terrain.ts";
|
||||||
@@ -10,6 +10,7 @@ import { pick_biome } from "$/common/worldgen/overworld.ts";
|
|||||||
|
|
||||||
const seed = Deno.args[0] ?? "preview";
|
const seed = Deno.args[0] ?? "preview";
|
||||||
const out = Deno.args[1] ?? ".";
|
const out = Deno.args[1] ?? ".";
|
||||||
|
const [center_x, center_z] = [Number(Deno.args[2] ?? 0), Number(Deno.args[3] ?? 0)];
|
||||||
|
|
||||||
const NAMES = [
|
const NAMES = [
|
||||||
"bworld:stone",
|
"bworld:stone",
|
||||||
@@ -67,17 +68,10 @@ const BIOME_COLORS: Record<string, [number, number, number]> = {
|
|||||||
"bworld:savanna": [190, 180, 90],
|
"bworld:savanna": [190, 180, 90],
|
||||||
"bworld:jungle": [40, 160, 40],
|
"bworld:jungle": [40, 160, 40],
|
||||||
"bworld:desert": [240, 215, 140],
|
"bworld:desert": [240, 215, 140],
|
||||||
"bworld:alpine_highlands": [120, 150, 110],
|
|
||||||
"bworld:snowy_slopes": [220, 230, 240],
|
"bworld:snowy_slopes": [220, 230, 240],
|
||||||
"bworld:stony_peaks": [150, 145, 140],
|
"bworld:stony_peaks": [150, 145, 140],
|
||||||
"bworld:jagged_peaks": [200, 200, 215],
|
"bworld:jagged_peaks": [200, 200, 215],
|
||||||
"bworld:frozen_peaks": [210, 225, 250],
|
"bworld:frozen_peaks": [210, 225, 250],
|
||||||
"bworld:yosemite_cliffs": [120, 120, 90],
|
|
||||||
"bworld:snowy_cliffs": [200, 205, 210],
|
|
||||||
"bworld:painted_mountains": [200, 120, 70],
|
|
||||||
"bworld:stony_spires": [110, 120, 100],
|
|
||||||
"bworld:shattered_savanna": [170, 150, 80],
|
|
||||||
"bworld:skylands": [255, 120, 220],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function write_png(path: string, width: number, height: number, rgb: Uint8Array) {
|
async function write_png(path: string, width: number, height: number, rgb: Uint8Array) {
|
||||||
@@ -140,14 +134,13 @@ const shade = (color: [number, number, number], factor: number): [number, number
|
|||||||
const started = performance.now();
|
const started = performance.now();
|
||||||
for (let pz = 0; pz < size; pz++) {
|
for (let pz = 0; pz < size; pz++) {
|
||||||
for (let px = 0; px < size; px++) {
|
for (let px = 0; px < size; px++) {
|
||||||
const x = (px - size / 2) * step;
|
const x = (px - size / 2) * step + center_x * CHUNK_SIZE;
|
||||||
const z = (pz - size / 2) * step;
|
const z = (pz - size / 2) * step + center_z * CHUNK_SIZE;
|
||||||
const column = terrain.column(x, z);
|
const column = terrain.column(x, z);
|
||||||
heights[pz * size + px] = column.height;
|
heights[pz * size + px] = column.height;
|
||||||
const surface = Math.round(column.height);
|
const surface = Math.round(column.height);
|
||||||
const biome = pick_biome(column, surface, false);
|
const biome = pick_biome(column, surface, false);
|
||||||
let color = BIOME_COLORS[biome] ?? [255, 0, 255];
|
const color = BIOME_COLORS[biome] ?? [255, 0, 255];
|
||||||
if (column.island) color = [255, 120, 220];
|
|
||||||
rgb.set(color, (pz * size + px) * 3);
|
rgb.set(color, (pz * size + px) * 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,8 +174,8 @@ const shade = (color: [number, number, number], factor: number): [number, number
|
|||||||
const started = performance.now();
|
const started = performance.now();
|
||||||
for (let cz = 0; cz < chunks; cz++) {
|
for (let cz = 0; cz < chunks; cz++) {
|
||||||
for (let cx = 0; cx < chunks; cx++) {
|
for (let cx = 0; cx < chunks; cx++) {
|
||||||
const chunk_x = origin / CHUNK_SIZE + cx;
|
const chunk_x = origin / CHUNK_SIZE + cx + center_x;
|
||||||
const chunk_z = origin / CHUNK_SIZE + cz;
|
const chunk_z = origin / CHUNK_SIZE + cz + center_z;
|
||||||
const { blocks } = generate_raw_chunk(chunk_x, chunk_z, seed, block_ids);
|
const { blocks } = generate_raw_chunk(chunk_x, chunk_z, seed, block_ids);
|
||||||
for (let lz = 0; lz < CHUNK_SIZE; lz++) {
|
for (let lz = 0; lz < CHUNK_SIZE; lz++) {
|
||||||
for (let lx = 0; lx < CHUNK_SIZE; lx++) {
|
for (let lx = 0; lx < CHUNK_SIZE; lx++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user