Skip to content

Commit

Permalink
support multilevel surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsjo committed Sep 27, 2024
1 parent 3790a22 commit b201a63
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/MapLayers/BiomeLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ 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 (tile.array[x + 1][z + 1].terrain < 0){
if (do_hillshade && tile.array[x + 1][z + 1].terrain < 0){
hillshade = 0.15
} else if (do_hillshade && project_down && !belowSurface) {

Expand Down
1 change: 0 additions & 1 deletion src/MapLayers/Graticule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class Graticule extends LayerGroup {
var x_line_min = Math.floor(nw.x / distance) * distance
var z_line_min = Math.floor(se.y / distance) * distance

console.log(x_line_count + ", " + z_line_count)
var lines = new Array(x_line_count + z_line_count)

for (var i = 0 ; i <= x_line_count ; i++){
Expand Down
4 changes: 2 additions & 2 deletions src/components/MainMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function getPosition(map: L.Map, latlng: L.LatLng) {
const pos = crs.project(latlng)
pos.y *= -1
const surface = (loadedDimensionStore.surface_density_function)?.compute(DensityFunction.context((pos.x >> 2) << 2, 0, (pos.y >> 2) << 2)) ?? Number.POSITIVE_INFINITY
const surface = (loadedDimensionStore.surface_density_function)?.compute(DensityFunction.context((pos.x >> 2) << 2, y.value, (pos.y >> 2) << 2)) ?? Number.POSITIVE_INFINITY
const pos_y: number = project_down.value ? Math.min(surface, y.value) : y.value
return BlockPos.create(pos.x, pos_y, pos.y)
Expand Down Expand Up @@ -313,7 +313,7 @@ watch(searchStore.structures, () => {
<YSlider class="slider" v-model:y="y" />
</Suspense>
<MapButton icon="fa-arrows-down-to-line" :disabled="loadedDimensionStore.surface_density_function === undefined" v-model="project_down" :title="$t('map.setting.project')" />
<MapButton icon="fa-mountain-sun" :disabled="!project_down || loadedDimensionStore.surface_density_function === undefined" v-model="do_hillshade" :title="$t('map.setting.hillshade')" />
<MapButton icon="fa-mountain-sun" :disabled="(!project_down || loadedDimensionStore.surface_density_function === undefined) && ! loadedDimensionStore.terrain_density_function" v-model="do_hillshade" :title="$t('map.setting.hillshade')" />
<MapButton icon="fa-water" :disabled="loadedDimensionStore.surface_density_function === undefined" v-model="show_sealevel" :title="$t('map.setting.sealevel')" />
<MapButton icon="fa-table-cells" v-model="show_graticule" :title="$t('map.setting.graticule')" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/YSlider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defineEmits(['update:y'])

<template>
<div class="slider">
<vue-slider :dot-attrs="{'aria-label': $t('map.yslider.aria-label')}" v-if="y_limits !== undefined" direction="btt" height="6rem" tooltip-placement="left" tooltip="hover" :lazy="true" :process="false"
<vue-slider :dot-attrs="{'aria-label': $t('map.yslider.aria-label')}" v-if="y_limits !== undefined" direction="btt" height="18rem" tooltip-placement="left" tooltip="hover" :lazy="true" :process="false"
v-bind:model-value="y"
@change="y => $emit('update:y', y)"
:max="y_limits[1]" :min="y_limits[0]"
Expand Down
11 changes: 10 additions & 1 deletion src/stores/useLoadedDimensionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ export const useLoadedDimensionStore = defineStore('loaded_dimension', () => {
}
})

const terrain_density_function = computed(() => {
const surface_density_function_id = getCustomDensityFunction("map_simple_terrain", 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 {
return undefined
}
})

function getIcon(id: Identifier){
const item = loaded_dimension.structure_icons?.get(id.toString()) ?? Identifier.create(VANILLA_ITEMS[Math.abs(hashCode(id.toString())) % VANILLA_ITEMS.length])
return `https://raw.githubusercontent.com/jacobsjo/mcicons/icons/item/${item.path}.png`
Expand All @@ -231,6 +240,6 @@ export const useLoadedDimensionStore = defineStore('loaded_dimension', () => {
return biome_source
}

return { loaded_dimension, noise_generator_settings, sampler, surface_density_function, reload, getIcon, getBiomeColor, getBiomeSource }
return { loaded_dimension, noise_generator_settings, sampler, surface_density_function, terrain_density_function, reload, getIcon, getBiomeColor, getBiomeSource }
})

2 changes: 1 addition & 1 deletion src/webworker/MultiNoiseCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class MultiNoiseCalculator {
for (let iz = -1; iz < tileSize + 2; iz++) {
const x = ix * step + min_x
const z = iz * step + min_z
const surface = this.state.surfaceDensityFunction?.compute(DensityFunction.context(x * 4, 0, z * 4)) ?? Number.POSITIVE_INFINITY
const surface = this.state.surfaceDensityFunction?.compute(DensityFunction.context(x * 4, this.state.y, 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"
const terrain = this.state.terrainDensityFunction?.compute(DensityFunction.context(x * 4, y , z * 4)) ?? Number.POSITIVE_INFINITY
Expand Down

0 comments on commit b201a63

Please sign in to comment.