mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-02 21:52:54 +00:00
Fix previews after wrapping lists
This commit is contained in:
@@ -128,3 +128,17 @@ export function deepEqual(a: any, b: any) {
|
||||
}
|
||||
return a !== a && b !== b
|
||||
}
|
||||
|
||||
export function unwrapLists(value: any): any {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(v => unwrapLists(v.node))
|
||||
} else if (typeof value === 'object' && value !== null) {
|
||||
const res: Record<string, any> = {}
|
||||
Object.entries(value).map(([k, v]) => {
|
||||
res[k] = unwrapLists(v)
|
||||
})
|
||||
return res
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { BiomeSource, Climate, NoiseOctaves } from 'deepslate'
|
||||
import { FixedBiome, MultiNoise, NoiseGeneratorSettings, NoiseSampler, NormalNoise, Random } from 'deepslate'
|
||||
import { fetchPreset } from '../DataFetcher'
|
||||
import type { VersionId } from '../Schemas'
|
||||
import { deepClone, deepEqual, square, stringToColor } from '../Utils'
|
||||
import { deepClone, deepEqual, square, stringToColor, unwrapLists } from '../Utils'
|
||||
|
||||
type BiomeColors = Record<string, number[]>
|
||||
type BiomeSourceOptions = {
|
||||
@@ -77,7 +77,7 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<
|
||||
return {
|
||||
getBiome(x: number, _y: number, z: number) {
|
||||
const i = (((x >> shift) + (z >> shift)) % numBiomes + numBiomes) % numBiomes
|
||||
return (state.biomes?.[i] as string)
|
||||
return (state.biomes?.[i].node as string)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<
|
||||
break
|
||||
}
|
||||
if (options.version === '1.18') {
|
||||
return MultiNoise.fromJson(state)
|
||||
return MultiNoise.fromJson(unwrapLists(state))
|
||||
} else {
|
||||
const noise = ['altitude', 'temperature', 'humidity', 'weirdness']
|
||||
.map((id, i) => {
|
||||
@@ -106,7 +106,7 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<
|
||||
const n = noise.map(n => n.sample(x, z, 0))
|
||||
let minDist = Infinity
|
||||
let minBiome = ''
|
||||
for (const { biome, parameters: p } of state.biomes) {
|
||||
for (const { biome, parameters: p } of unwrapLists(state.biomes)) {
|
||||
const dist = square(p.altitude - n[0]) + square(p.temperature - n[1]) + square(p.humidity - n[2]) + square(p.weirdness - n[3]) + square(p.offset)
|
||||
if (dist < minDist) {
|
||||
minDist = dist
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PerlinNoise, Random } from 'deepslate'
|
||||
import type { VersionId } from '../Schemas'
|
||||
import { clamp, stringToColor } from '../Utils'
|
||||
import { clamp, stringToColor, unwrapLists } from '../Utils'
|
||||
|
||||
type BlockPos = [number, number, number]
|
||||
type Placement = [BlockPos, number]
|
||||
@@ -49,7 +49,7 @@ export function decorator(state: any, img: ImageData, options: DecoratorOptions)
|
||||
|
||||
for (let x = 0; x < options.size[0] / 16; x += 1) {
|
||||
for (let z = 0; z < options.size[2] / 16; z += 1) {
|
||||
getPlacements([x * 16, 0, z * 16], state, ctx)
|
||||
getPlacements([x * 16, 0, z * 16], unwrapLists(state), ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { BlockPos, BlockState } from 'deepslate'
|
||||
import { Chunk, ChunkPos, FixedBiome, NoiseChunkGenerator, NoiseGeneratorSettings } from 'deepslate'
|
||||
import type { VersionId } from '../Schemas'
|
||||
import { checkVersion } from '../Schemas'
|
||||
import { deepClone, deepEqual } from '../Utils'
|
||||
import { deepClone, deepEqual, unwrapLists } from '../Utils'
|
||||
import { NoiseChunkGenerator as OldNoiseChunkGenerator } from './noise/NoiseChunkGenerator'
|
||||
|
||||
export type NoiseSettingsOptions = {
|
||||
@@ -70,7 +70,7 @@ export function noiseSettings(state: any, img: ImageData, options: NoiseSettings
|
||||
}
|
||||
|
||||
function getCached(state: unknown, options: NoiseSettingsOptions) {
|
||||
const settings = NoiseGeneratorSettings.fromJson(state)
|
||||
const settings = NoiseGeneratorSettings.fromJson(unwrapLists(state))
|
||||
// Temporary fix for slides
|
||||
settings.noise.bottomSlide.target *= 128
|
||||
settings.noise.topSlide.target *= 128
|
||||
|
||||
Reference in New Issue
Block a user