diff --git a/src/MapLayers/BiomeLayer.ts b/src/MapLayers/BiomeLayer.ts index afe2563..eeb64b1 100644 --- a/src/MapLayers/BiomeLayer.ts +++ b/src/MapLayers/BiomeLayer.ts @@ -1,7 +1,7 @@ import * as L from "leaflet" //import { last, range, takeWhile } from "lodash"; import { Climate } from "deepslate"; -import { calculateHillshade, getSurfaceDensityFunction, hashCode } from "../util"; +import { calculateHillshade, getCustomDensityFunction, hashCode } from "../util"; import MultiNoiseCalculator from "../webworker/MultiNoiseCalculator?worker" import { useSearchStore } from "../stores/useBiomeSearchStore"; import { useLoadedDimensionStore } from "../stores/useLoadedDimensionStore"; @@ -18,9 +18,9 @@ type Tile = { ctx: CanvasRenderingContext2D, done: L.DoneCallback, array?: { - climate: Climate.TargetPoint, surface: number, - biome: string + biome: string, + terrain: number }[][], step?: number, isRendering?: boolean, @@ -130,7 +130,9 @@ export class BiomeLayer extends L.GridLayer { let hillshade = 1.0 const y = project_down ? Math.min(tile.array[x + 1][z + 1].surface, this.y.value) : this.y.value const belowSurface = y < tile.array[x + 1][z + 1].surface - if (do_hillshade && project_down && !belowSurface) { + if (tile.array[x + 1][z + 1].terrain < 0){ + hillshade = 0.15 + } else if (do_hillshade && project_down && !belowSurface) { hillshade = calculateHillshade( tile.array[x + 2][z + 1].surface - tile.array[x][z + 1].surface, @@ -216,7 +218,8 @@ export class BiomeLayer extends L.GridLayer { if (do_update.dimension) { update.biomeSourceJson = toRaw(this.loadedDimensionStore.loaded_dimension.biome_source_json) update.noiseGeneratorSettingsJson = toRaw(this.loadedDimensionStore.loaded_dimension.noise_settings_json) - update.surfaceDensityFunctionId = getSurfaceDensityFunction(this.loadedDimensionStore.loaded_dimension.noise_settings_id!, this.settingsStore.dimension)?.toString() ?? "" + update.surfaceDensityFunctionId = getCustomDensityFunction("snowcapped_surface", this.loadedDimensionStore.loaded_dimension.noise_settings_id!, this.settingsStore.dimension)?.toString() ?? "" + update.terrainDensityFunctionId = getCustomDensityFunction("map_simple_terrain", this.loadedDimensionStore.loaded_dimension.noise_settings_id!, this.settingsStore.dimension)?.toString() ?? "" } if (do_update.settings) { diff --git a/src/stores/useLoadedDimensionStore.ts b/src/stores/useLoadedDimensionStore.ts index 2412cf5..4f3733c 100644 --- a/src/stores/useLoadedDimensionStore.ts +++ b/src/stores/useLoadedDimensionStore.ts @@ -5,7 +5,7 @@ import { compile, computed, reactive, ref, watch } from "vue"; import { useI18n } from "vue-i18n"; import { getPreset } from "../BuildIn/MultiNoiseBiomeParameterList"; import { VANILLA_ITEMS } from "../BuildIn/VanillaItems"; -import { getSurfaceDensityFunction, hashCode } from "../util"; +import { getCustomDensityFunction, hashCode } from "../util"; import { useDatapackStore } from "./useDatapackStore"; import { useSettingsStore } from "./useSettingsStore"; @@ -201,7 +201,7 @@ export const useLoadedDimensionStore = defineStore('loaded_dimension', () => { }) const surface_density_function = computed(() => { - const surface_density_function_id = getSurfaceDensityFunction(loaded_dimension.noise_settings_id ?? Identifier.create("empty"), settingsStore.dimension) + const surface_density_function_id = getCustomDensityFunction("snowcapped_surface", loaded_dimension.noise_settings_id ?? Identifier.create("empty"), settingsStore.dimension) if (surface_density_function_id !== undefined){ return new DensityFunction.HolderHolder(Holder.reference(WorldgenRegistries.DENSITY_FUNCTION, surface_density_function_id)).mapAll((random_state.value).createVisitor((noise_generator_settings.value).noise, (noise_generator_settings.value).legacyRandomSource)) } else { diff --git a/src/util.ts b/src/util.ts index fbbffaf..88100ca 100644 --- a/src/util.ts +++ b/src/util.ts @@ -23,18 +23,18 @@ function idIfExists(id: Identifier) { return undefined } -function getDimensionDensityFunction(noise_settings_id: Identifier, dimension_id: Identifier): Identifier { +function getDimensionDensityFunction(name: string, noise_settings_id: Identifier, dimension_id: Identifier): Identifier { const dimensionName = dimension_id.path.split("/").reverse()[0] const noiseSettingsPath = noise_settings_id.path.split("/") noiseSettingsPath[noiseSettingsPath.length - 1] = `${dimensionName}_${noiseSettingsPath[noiseSettingsPath.length - 1]}` - return new Identifier(noise_settings_id.namespace, noiseSettingsPath.join("/") + "/snowcapped_surface") + return new Identifier(noise_settings_id.namespace, noiseSettingsPath.join("/") + "/" + name) } -export function getSurfaceDensityFunction(noise_settings_id: Identifier, dimension_id: Identifier): Identifier | undefined { - return idIfExists(new Identifier(noise_settings_id.namespace, noise_settings_id.path + "/snowcapped_surface")) - ?? idIfExists(getDimensionDensityFunction(noise_settings_id, dimension_id)) - ?? idIfExists(new Identifier(noise_settings_id.namespace, "snowcapped_surface")) - ?? idIfExists(new Identifier("minecraft", "snowcapped_surface")) +export function getCustomDensityFunction(name: string, noise_settings_id: Identifier, dimension_id: Identifier): Identifier | undefined { + return idIfExists(new Identifier(noise_settings_id.namespace, noise_settings_id.path + "/" + name)) + ?? idIfExists(getDimensionDensityFunction(name, noise_settings_id, dimension_id)) + ?? idIfExists(new Identifier(noise_settings_id.namespace, name)) + ?? idIfExists(new Identifier("minecraft", name)) } const zenith = 20.0 * Math.PI / 180.0; diff --git a/src/webworker/MultiNoiseCalculator.ts b/src/webworker/MultiNoiseCalculator.ts index 412627d..d929bdf 100644 --- a/src/webworker/MultiNoiseCalculator.ts +++ b/src/webworker/MultiNoiseCalculator.ts @@ -11,6 +11,7 @@ class MultiNoiseCalculator { sampler?: Climate.Sampler, biomeSource?: BiomeSource, surfaceDensityFunction?: DensityFunction, + terrainDensityFunction?: DensityFunction, noiseGeneratorSettings?: NoiseGeneratorSettings randomState?: RandomState y: number, @@ -32,6 +33,7 @@ class MultiNoiseCalculator { densityFunctions?: { [key: string]: unknown }, noises?: { [key: string]: unknown }, surfaceDensityFunctionId?: string, + terrainDensityFunctionId?: string, generationVersion?: number seed?: bigint, @@ -70,16 +72,27 @@ class MultiNoiseCalculator { this.state.sampler = Climate.Sampler.fromRouter(this.state.randomState.router) } - if (update.surfaceDensityFunctionId && this.state.randomState && this.state.noiseGeneratorSettings) { + if (this.state.randomState && this.state.noiseGeneratorSettings) { if (update.surfaceDensityFunctionId === ""){ this.state.surfaceDensityFunction = undefined - } else { + } else if (update.surfaceDensityFunctionId) { this.state.surfaceDensityFunction = new DensityFunction.HolderHolder( Holder.reference( WorldgenRegistries.DENSITY_FUNCTION, Identifier.parse(update.surfaceDensityFunctionId) )).mapAll(this.state.randomState.createVisitor(this.state.noiseGeneratorSettings.noise, this.state.noiseGeneratorSettings.legacyRandomSource)) } + + if (update.terrainDensityFunctionId === ""){ + this.state.terrainDensityFunction = undefined + } else if (update.terrainDensityFunctionId) { + this.state.terrainDensityFunction = new DensityFunction.HolderHolder( + Holder.reference( + WorldgenRegistries.DENSITY_FUNCTION, + Identifier.parse(update.terrainDensityFunctionId) + )).mapAll(this.state.randomState.createVisitor(this.state.noiseGeneratorSettings.noise, this.state.noiseGeneratorSettings.legacyRandomSource)) + } + } this.taskQueue = [] @@ -109,7 +122,7 @@ class MultiNoiseCalculator { } private calculateMultiNoiseValues(key: string, min_x: number, min_z: number, max_x: number, max_z: number, tileSize: number): void { - const array: { surface: number, biome: string }[][] = Array(tileSize + 2) + const array: { surface: number, biome: string, terrain: number }[][] = Array(tileSize + 2) const step = (max_x - min_x) / tileSize for (let ix = -1; ix < tileSize + 2; ix++) { array[ix] = Array(tileSize + 2) @@ -119,7 +132,8 @@ class MultiNoiseCalculator { const surface = this.state.surfaceDensityFunction?.compute(DensityFunction.context(x * 4, 0, z * 4)) ?? Number.POSITIVE_INFINITY const y = this.state.projectDown ? Math.min(surface, this.state.y) : this.state.y const biome = this.state.biomeSource?.getBiome(x, y >> 2, z, this.state.sampler!).toString() ?? "minecraft:plains" - array[ix][iz] = { surface, biome } + const terrain = this.state.terrainDensityFunction?.compute(DensityFunction.context(x * 4, y , z * 4)) ?? Number.POSITIVE_INFINITY + array[ix][iz] = { surface, biome, terrain } } }