Skip to content

Commit

Permalink
1.21.2 spawnpoint algorithm & update deepslate
Browse files Browse the repository at this point in the history
- fixes wrong biome layout
  • Loading branch information
jacobsjo committed Oct 15, 2024
1 parent 9e47e8e commit 7c34dd1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/components/MainMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
25 changes: 17 additions & 8 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -80,7 +81,8 @@ type Metadata = {
experimentalDatapacks: {
url: string,
translation_key: string
}[]
}[],
spawnAlgorithm: SpawnTarget.Algorithm
}

export const versionMetadata: { [version: string]: Metadata } = {
Expand All @@ -95,23 +97,26 @@ export const versionMetadata: { [version: string]: Metadata } = {
datapackFormat: 12,
resourceLocations: {
structure: ResourceLocation.LEGACY_STRUCTURE
}
},
spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED
},
"1_20": {
vanillaDatapack: "1_20",
experimentalDatapacks: [],
datapackFormat: 15,
resourceLocations: {
structure: ResourceLocation.LEGACY_STRUCTURE
}
},
spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED
},
"1_20_2": {
vanillaDatapack: "1_20_2",
experimentalDatapacks: [],
datapackFormat: 18,
resourceLocations: {
structure: ResourceLocation.LEGACY_STRUCTURE
}
},
spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED
},
"1_20_4": {
vanillaDatapack: "1_20_4",
Expand All @@ -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",
Expand All @@ -137,15 +143,17 @@ export const versionMetadata: { [version: string]: Metadata } = {
datapackFormat: 41,
resourceLocations: {
structure: ResourceLocation.LEGACY_STRUCTURE
}
},
spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED
},
"1_21": {
vanillaDatapack: "1_21",
experimentalDatapacks: [],
datapackFormat: 48,
resourceLocations: {
structure: ResourceLocation.STRUCTURE
}
},
spawnAlgorithm: SpawnTarget.Algorithm.LEGACY_ZERO_BIASED
},
"1_21_2": {
vanillaDatapack: "1_21_2",
Expand All @@ -158,6 +166,7 @@ export const versionMetadata: { [version: string]: Metadata } = {
datapackFormat: 56,
resourceLocations: {
structure: ResourceLocation.STRUCTURE
}
},
spawnAlgorithm: SpawnTarget.Algorithm.BEST_CLIMATE
},
}
29 changes: 21 additions & 8 deletions src/util/SpawnTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand All @@ -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) {
Expand All @@ -53,8 +58,16 @@ export class SpawnTarget{
}
}
}


}
}

export namespace SpawnTarget {
export enum Algorithm {
LEGACY_ZERO_BIASED,
BEST_CLIMATE
}
}




0 comments on commit 7c34dd1

Please sign in to comment.