diff --git a/package-lock.json b/package-lock.json index e3634cf..1bc3797 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@fortawesome/free-solid-svg-icons": "^6.4.0", "@fortawesome/vue-fontawesome": "^3.0.3", "@vueuse/components": "^10.2.0", - "deepslate": "^0.18.0", + "deepslate": "^0.22.4", "idb-keyval": "^6.2.1", "leaflet": "^1.9.4", "mc-datapack-loader": "0.4.0", @@ -3235,9 +3235,10 @@ } }, "node_modules/deepslate": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/deepslate/-/deepslate-0.18.0.tgz", - "integrity": "sha512-mip9lv9ka0ksdaQ6OrfwQHFyr171vtTrmy1FAIWWy+owWbGnYiXioIS6uX4jEeQ9MMaWrBXwKHuPu5Hv+H7E3w==", + "version": "0.22.4", + "resolved": "https://registry.npmjs.org/deepslate/-/deepslate-0.22.4.tgz", + "integrity": "sha512-Fv0SELOnZhgariC4uGRgLmk1VdGQD9xr5nxQsRwb3YiSk+CWDWoNmdOtL93XCNHPAXRjppmW4eFJoT0Eut06dA==", + "license": "MIT", "dependencies": { "gl-matrix": "^3.3.0", "md5": "^2.3.0", @@ -8428,9 +8429,9 @@ "dev": true }, "deepslate": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/deepslate/-/deepslate-0.18.0.tgz", - "integrity": "sha512-mip9lv9ka0ksdaQ6OrfwQHFyr171vtTrmy1FAIWWy+owWbGnYiXioIS6uX4jEeQ9MMaWrBXwKHuPu5Hv+H7E3w==", + "version": "0.22.4", + "resolved": "https://registry.npmjs.org/deepslate/-/deepslate-0.22.4.tgz", + "integrity": "sha512-Fv0SELOnZhgariC4uGRgLmk1VdGQD9xr5nxQsRwb3YiSk+CWDWoNmdOtL93XCNHPAXRjppmW4eFJoT0Eut06dA==", "requires": { "gl-matrix": "^3.3.0", "md5": "^2.3.0", diff --git a/package.json b/package.json index 3943587..877a53a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@fortawesome/free-solid-svg-icons": "^6.4.0", "@fortawesome/vue-fontawesome": "^3.0.3", "@vueuse/components": "^10.2.0", - "deepslate": "^0.18.0", + "deepslate": "^0.22.4", "idb-keyval": "^6.2.1", "leaflet": "^1.9.4", "mc-datapack-loader": "0.4.0", diff --git a/src/components/MainMap.vue b/src/components/MainMap.vue index 11f794c..359d393 100644 --- a/src/components/MainMap.vue +++ b/src/components/MainMap.vue @@ -14,6 +14,7 @@ import { CachedBiomeSource } from '../util/CachedBiomeSource'; import MapButton from './MapButton.vue'; import { SpawnTarget } from '../util/SpawnTarget'; import { useI18n } from 'vue-i18n'; +import { versionMetadata } from "../util"; const searchStore = useSearchStore() const settingsStore = useSettingsStore() @@ -268,7 +269,7 @@ function getMarker(structureId: Identifier, chunk: ChunkPos) { function updateSpawnMarker(){ if (settingsStore.dimension.equals(Identifier.create("overworld"))){ const crs = map.options.crs! - const spawnTarget = SpawnTarget.fromJson(loadedDimensionStore.loaded_dimension.noise_settings_json?.spawn_target) + const spawnTarget = SpawnTarget.fromJson(loadedDimensionStore.loaded_dimension.noise_settings_json?.spawn_target, versionMetadata[settingsStore.mc_version].spawnAlgorithm) const spawn = spawnTarget.getSpawnPoint(loadedDimensionStore.sampler) const pos = new L.Point(spawn[0] + 7, - spawn[1] - 7) spawnMarker.setLatLng(crs.unproject(pos)) diff --git a/src/util.ts b/src/util.ts index ef185f7..29ea033 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,6 @@ import { Climate, DensityFunction, Identifier, lerp, NoiseRouter, NoiseSettings, WorldgenRegistries } from "deepslate" import { ResourceLocation } from "mc-datapack-loader" +import { SpawnTarget } from "./util/SpawnTarget" export function lerpClimate(a: Climate.TargetPoint, b: Climate.TargetPoint, c: number) { return new Climate.TargetPoint( @@ -80,7 +81,8 @@ type Metadata = { experimentalDatapacks: { url: string, translation_key: string - }[] + }[], + spawnAlgorithm: SpawnTarget.Algorithm } export const versionMetadata: { [version: string]: Metadata } = { @@ -95,7 +97,8 @@ export const versionMetadata: { [version: string]: Metadata } = { datapackFormat: 12, resourceLocations: { structure: ResourceLocation.LEGACY_STRUCTURE - } + }, + spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED }, "1_20": { vanillaDatapack: "1_20", @@ -103,7 +106,8 @@ export const versionMetadata: { [version: string]: Metadata } = { datapackFormat: 15, resourceLocations: { structure: ResourceLocation.LEGACY_STRUCTURE - } + }, + spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED }, "1_20_2": { vanillaDatapack: "1_20_2", @@ -111,7 +115,8 @@ export const versionMetadata: { [version: string]: Metadata } = { datapackFormat: 18, resourceLocations: { structure: ResourceLocation.LEGACY_STRUCTURE - } + }, + spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED }, "1_20_4": { vanillaDatapack: "1_20_4", @@ -124,7 +129,8 @@ export const versionMetadata: { [version: string]: Metadata } = { datapackFormat: 26, resourceLocations: { structure: ResourceLocation.LEGACY_STRUCTURE - } + }, + spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED }, "1_20_6": { vanillaDatapack: "1_20_6", @@ -137,7 +143,8 @@ export const versionMetadata: { [version: string]: Metadata } = { datapackFormat: 41, resourceLocations: { structure: ResourceLocation.LEGACY_STRUCTURE - } + }, + spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED }, "1_21": { vanillaDatapack: "1_21", @@ -145,7 +152,8 @@ export const versionMetadata: { [version: string]: Metadata } = { datapackFormat: 48, resourceLocations: { structure: ResourceLocation.STRUCTURE - } + }, + spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED }, "1_21_2": { vanillaDatapack: "1_21_2", @@ -158,6 +166,7 @@ export const versionMetadata: { [version: string]: Metadata } = { datapackFormat: 56, resourceLocations: { structure: ResourceLocation.STRUCTURE - } + }, + spawnAlgorithm: SpawnTarget.Algorithm.BEST_CLIMATE }, } \ No newline at end of file diff --git a/src/util/SpawnTarget.ts b/src/util/SpawnTarget.ts index 6009368..d680610 100644 --- a/src/util/SpawnTarget.ts +++ b/src/util/SpawnTarget.ts @@ -4,13 +4,14 @@ import { Climate, Json } from "deepslate"; export class SpawnTarget{ constructor( - private paramPoints: Climate.ParamPoint[] + private paramPoints: Climate.ParamPoint[], + private algorithm: SpawnTarget.Algorithm ){ } - public static fromJson(obj: unknown){ - return new SpawnTarget(Json.readArray(obj, Climate.ParamPoint.fromJson) ?? []) + public static fromJson(obj: unknown, algorithm: SpawnTarget.Algorithm){ + return new SpawnTarget(Json.readArray(obj, Climate.ParamPoint.fromJson) ?? [], algorithm) } public getSpawnPoint(climateSampler: Climate.Sampler): [number, number] { @@ -24,13 +25,17 @@ export class SpawnTarget{ return result function getFitness(x: number, z: number){ - const distanceFitness = Math.pow((x * x + z * z) / (2500 * 2500),2); - const climate = climateSampler.sample(x >> 2, 0, z >> 2) const surfaceClimate = Climate.target(climate.temperature, climate.humidity, climate.continentalness, climate.erosion, 0, climate.weirdness) const climateFitness = Math.min(...self.paramPoints.map(p => p.fittness(surfaceClimate))) - return distanceFitness + climateFitness + switch (self.algorithm) { + case SpawnTarget.Algorithm.LEGACY_ZERO_BIASED: + const distanceFitness = Math.pow((x * x + z * z) / (2500 * 2500),2); + return distanceFitness + climateFitness + case SpawnTarget.Algorithm.BEST_CLIMATE: + return BigInt(x*x + z*z) + BigInt(2048 * 2048) * BigInt(Math.floor(10000 * 10000 * climateFitness)) + } } function radialSearch(maxRadius: number, radiusStep: number, centerX: number, centerZ: number) { @@ -53,8 +58,16 @@ export class SpawnTarget{ } } } - - } +} +export namespace SpawnTarget { + export enum Algorithm { + LEGACY_ZERO_BIASED, + BEST_CLIMATE + } } + + + +