mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Visualizations for 1.18.2 and density functions
This commit is contained in:
@@ -4,9 +4,9 @@ import { useState } from 'preact/hooks'
|
||||
import { useModel } from '../../hooks'
|
||||
import type { VersionId } from '../../services'
|
||||
import { checkVersion } from '../../services'
|
||||
import { BiomeSourcePreview, DecoratorPreview, NoisePreview, NoiseSettingsPreview } from '../previews'
|
||||
import { BiomeSourcePreview, DecoratorPreview, DensityFunctionPreview, NoisePreview, NoiseSettingsPreview } from '../previews'
|
||||
|
||||
export const HasPreview = ['dimension', 'worldgen/noise', 'worldgen/noise_settings', 'worldgen/configured_feature', 'worldgen/placed_feature']
|
||||
export const HasPreview = ['dimension', 'worldgen/density_function', 'worldgen/noise', 'worldgen/noise_settings', 'worldgen/configured_feature', 'worldgen/placed_feature']
|
||||
|
||||
type PreviewPanelProps = {
|
||||
model: DataModel | null,
|
||||
@@ -29,6 +29,11 @@ export function PreviewPanel({ model, version, id, shown }: PreviewPanelProps) {
|
||||
if (data) return <BiomeSourcePreview {...{ model, version, shown, data }} />
|
||||
}
|
||||
|
||||
if (id === 'worldgen/density_function') {
|
||||
const data = model.get(new Path([]))
|
||||
if (data) return <DensityFunctionPreview {...{ model, version, shown, data }} />
|
||||
}
|
||||
|
||||
if (id === 'worldgen/noise') {
|
||||
const data = model.get(new Path([]))
|
||||
if (data) return <NoisePreview {...{ model, version, shown, data }} />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DataModel, Path } from '@mcschema/core'
|
||||
import type { NoiseParameters } from 'deepslate'
|
||||
import { NoiseGeneratorSettings, TerrainShaper } from 'deepslate'
|
||||
import { NoiseGeneratorSettings } from 'deepslate'
|
||||
import { useEffect, useRef, useState } from 'preact/hooks'
|
||||
import type { PreviewProps } from '.'
|
||||
import { Btn, BtnMenu } from '..'
|
||||
@@ -9,9 +9,7 @@ import { useCanvas } from '../../hooks'
|
||||
import { biomeMap, getBiome } from '../../previews'
|
||||
import { newSeed } from '../../Utils'
|
||||
|
||||
const LAYERS = ['biomes', 'temperature', 'humidity', 'continentalness', 'erosion', 'weirdness', 'offset', 'factor', 'jaggedness'] as const
|
||||
|
||||
const OverworldShaper = TerrainShaper.overworld()
|
||||
const LAYERS = ['biomes', 'temperature', 'humidity', 'continentalness', 'erosion', 'weirdness'] as const
|
||||
|
||||
export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps) => {
|
||||
const { locale } = useLocale()
|
||||
@@ -24,8 +22,7 @@ export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps
|
||||
|
||||
const seed = BigInt(model.get(new Path(['generator', 'seed'])))
|
||||
const octaves = getOctaves(model.get(new Path(['generator', 'settings'])))
|
||||
const shaper = getShaper(model.get(new Path(['generator', 'settings'])))
|
||||
const state = shown ? calculateState(data, octaves, shaper) : ''
|
||||
const state = shown ? calculateState(data, octaves) : ''
|
||||
const type: string = data.type?.replace(/^minecraft:/, '')
|
||||
|
||||
const { canvas, redraw } = useCanvas({
|
||||
@@ -33,7 +30,7 @@ export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps
|
||||
return [200 / res.current, 200 / res.current]
|
||||
},
|
||||
async draw(img) {
|
||||
const options = { octaves, shaper, biomeColors: {}, layers, offset: offset.current, scale, seed, res: res.current, version }
|
||||
const options = { octaves, biomeColors: {}, layers, offset: offset.current, scale, seed, res: res.current, version }
|
||||
await biomeMap(data, img, options)
|
||||
if (res.current === 4) {
|
||||
clearTimeout(refineTimeout.current)
|
||||
@@ -51,7 +48,7 @@ export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps
|
||||
redraw()
|
||||
},
|
||||
async onHover(x, y) {
|
||||
const options = { octaves, shaper, biomeColors: {}, layers, offset: offset.current, scale, seed, res: 1, version }
|
||||
const options = { octaves, biomeColors: {}, layers, offset: offset.current, scale, seed, res: 1, version }
|
||||
const biome = await getBiome(data, Math.floor(x * 200), Math.floor(y * 200), options)
|
||||
setFocused(biome)
|
||||
},
|
||||
@@ -108,8 +105,8 @@ export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps
|
||||
</>
|
||||
}
|
||||
|
||||
function calculateState(data: any, octaves: Record<string, NoiseParameters>, shaper: TerrainShaper) {
|
||||
return JSON.stringify([data, octaves, shaper.toJson()])
|
||||
function calculateState(data: any, octaves: Record<string, NoiseParameters>) {
|
||||
return JSON.stringify([data, octaves])
|
||||
}
|
||||
|
||||
export function getOctaves(obj: any): Record<string, NoiseParameters> {
|
||||
@@ -149,16 +146,3 @@ export function getOctaves(obj: any): Record<string, NoiseParameters> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getShaper(obj: any): TerrainShaper {
|
||||
if (typeof obj === 'string') {
|
||||
switch (obj.replace(/^minecraft:/, '')) {
|
||||
case 'overworld':
|
||||
case 'amplified':
|
||||
return OverworldShaper
|
||||
default:
|
||||
return TerrainShaper.fromJson({ offset: 0, factor: 0, jaggedness: 0 })
|
||||
}
|
||||
}
|
||||
return TerrainShaper.fromJson(DataModel.unwrapLists(obj?.noise?.terrain_shaper))
|
||||
}
|
||||
|
||||
70
src/app/components/previews/DensityFunctionPreview.tsx
Normal file
70
src/app/components/previews/DensityFunctionPreview.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'preact/hooks'
|
||||
import type { PreviewProps } from '.'
|
||||
import { Btn, BtnMenu } from '..'
|
||||
import { useLocale } from '../../contexts'
|
||||
import { useCanvas } from '../../hooks'
|
||||
import { densityFunction } from '../../previews'
|
||||
import { CachedCollections } from '../../services'
|
||||
import { randomSeed } from '../../Utils'
|
||||
|
||||
export const DensityFunctionPreview = ({ data, shown, version }: PreviewProps) => {
|
||||
const { locale } = useLocale()
|
||||
const [seed, setSeed] = useState(randomSeed())
|
||||
const [autoScroll, setAutoScroll] = useState(false)
|
||||
const [focused, setFocused] = useState<string | undefined>(undefined)
|
||||
const offset = useRef(0)
|
||||
const scrollInterval = useRef<number | undefined>(undefined)
|
||||
const state = JSON.stringify([data])
|
||||
|
||||
const size = data?.noise?.height ?? 256
|
||||
const { canvas, redraw } = useCanvas({
|
||||
size() {
|
||||
return [size, size]
|
||||
},
|
||||
async draw(img) {
|
||||
const options = { offset: offset.current, width: img.width, seed, version }
|
||||
await densityFunction(data, img, options)
|
||||
},
|
||||
async onDrag(dx) {
|
||||
offset.current += dx * size
|
||||
redraw()
|
||||
},
|
||||
async onHover(x, y) {
|
||||
const worldX = Math.floor(x * size - offset.current)
|
||||
const worldY = size - Math.max(1, Math.ceil(y * size)) + (data?.noise?.min_y ?? 0)
|
||||
setFocused(`X=${worldX} Y=${worldY}`)
|
||||
},
|
||||
onLeave() {
|
||||
setFocused(undefined)
|
||||
},
|
||||
}, [state, seed])
|
||||
|
||||
useEffect(() => {
|
||||
if (scrollInterval.current) {
|
||||
clearInterval(scrollInterval.current)
|
||||
}
|
||||
if (shown) {
|
||||
redraw()
|
||||
if (autoScroll) {
|
||||
scrollInterval.current = setInterval(() => {
|
||||
offset.current -= 8
|
||||
redraw()
|
||||
}, 100) as any
|
||||
}
|
||||
}
|
||||
}, [state, seed, shown, autoScroll])
|
||||
|
||||
const allBiomes = useMemo(() => CachedCollections?.get('worldgen/biome') ?? [], [version])
|
||||
|
||||
return <>
|
||||
<div class="controls preview-controls">
|
||||
{focused && <Btn label={focused} class="no-pointer" />}
|
||||
<BtnMenu icon="gear" tooltip={locale('terrain_settings')}>
|
||||
<Btn icon={autoScroll ? 'square_fill' : 'square'} label={locale('preview.auto_scroll')} onClick={() => setAutoScroll(!autoScroll)} />
|
||||
</BtnMenu>
|
||||
<Btn icon="sync" tooltip={locale('generate_new_seed')}
|
||||
onClick={() => setSeed(randomSeed())} />
|
||||
</div>
|
||||
<canvas ref={canvas} width={size} height={size}></canvas>
|
||||
</>
|
||||
}
|
||||
@@ -26,7 +26,7 @@ export const NoiseSettingsPreview = ({ data, shown, version }: PreviewProps) =>
|
||||
},
|
||||
async draw(img) {
|
||||
const options = { biome, biomeDepth, biomeScale, offset: offset.current, width: img.width, seed, version }
|
||||
noiseSettings(data, img, options)
|
||||
await noiseSettings(data, img, options)
|
||||
},
|
||||
async onDrag(dx) {
|
||||
offset.current += dx * size
|
||||
@@ -36,7 +36,7 @@ export const NoiseSettingsPreview = ({ data, shown, version }: PreviewProps) =>
|
||||
const worldX = Math.floor(x * size - offset.current)
|
||||
const worldY = size - Math.max(1, Math.ceil(y * size)) + (data?.noise?.min_y ?? 0)
|
||||
const block = getNoiseBlock(worldX, worldY)
|
||||
setFocused(block ? `Y=${worldY} (${block.getName().replace(/^minecraft:/, '')})` : `Y=${worldY}`)
|
||||
setFocused(block ? `Y=${worldY} (${block.getName().path})` : `Y=${worldY}`)
|
||||
},
|
||||
onLeave() {
|
||||
setFocused(undefined)
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { VersionId } from '../../services'
|
||||
|
||||
export * from './BiomeSourcePreview'
|
||||
export * from './DecoratorPreview'
|
||||
export * from './DensityFunctionPreview'
|
||||
export * from './NoisePreview'
|
||||
export * from './NoiseSettingsPreview'
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DataModel } from '@mcschema/core'
|
||||
import type { NoiseParameters } from 'deepslate'
|
||||
import { FixedBiome, LegacyRandom, NormalNoise, TerrainShaper } from 'deepslate'
|
||||
import { FixedBiome, Identifier, LegacyRandom, NormalNoise } from 'deepslate'
|
||||
import init, { biome_parameters, climate_noise, climate_sampler, multi_noise } from 'deepslate-rs'
|
||||
// @ts-expect-error
|
||||
import wasm from 'deepslate-rs/deepslate_rs_bg.wasm?url'
|
||||
import type { VersionId } from '../services'
|
||||
import { fetchPreset } from '../services'
|
||||
import { checkVersion, fetchPreset } from '../services'
|
||||
import { BiMap, clamp, deepClone, deepEqual, square, stringToColor } from '../Utils'
|
||||
|
||||
let ready = false
|
||||
@@ -31,7 +31,6 @@ type Triple = [number, number, number]
|
||||
type BiomeColors = Record<string, Triple>
|
||||
type BiomeSourceOptions = {
|
||||
octaves: Record<string, NoiseParameters>,
|
||||
shaper: TerrainShaper,
|
||||
biomeColors: BiomeColors,
|
||||
offset: [number, number],
|
||||
scale: number,
|
||||
@@ -42,10 +41,10 @@ type BiomeSourceOptions = {
|
||||
}
|
||||
|
||||
interface CachedBiomeSource {
|
||||
getBiome(x: number, y: number, z: number): string
|
||||
getBiomes?(xFrom: number, xTo: number, xStep: number, yFrom: number, yTo: number, yStep: number, zFrom: number, zTo: number, zStep: number): string[]
|
||||
getBiome(x: number, y: number, z: number): Identifier
|
||||
getBiomes?(xFrom: number, xTo: number, xStep: number, yFrom: number, yTo: number, yStep: number, zFrom: number, zTo: number, zStep: number): Identifier[]
|
||||
getClimate?(x: number, y: number, z: number): {[k: string]: number}
|
||||
getClimates?(layers: Set<keyof typeof LAYERS>, xFrom: number, xTo: number, xStep: number, yFrom: number, yTo: number, yStep: number, zFrom: number, zTo: number, zStep: number): {[k: string]: number}[]
|
||||
getClimates?(xFrom: number, xTo: number, xStep: number, yFrom: number, yTo: number, yStep: number, zFrom: number, zTo: number, zStep: number): {[k: string]: number}[]
|
||||
}
|
||||
|
||||
let cacheState: any
|
||||
@@ -65,7 +64,7 @@ export async function biomeMap(state: any, img: ImageData, options: BiomeSourceO
|
||||
|
||||
const biomes = !options.layers.has('biomes') ? undefined : biomeSource.getBiomes?.(...xRange, 64, 65, 1, ...zRange)
|
||||
const layers = [...options.layers].filter(l => l !== 'biomes') as (keyof typeof LAYERS)[]
|
||||
const noise = layers.length === 0 ? undefined : biomeSource.getClimates?.(new Set(layers), ...xRange, 64, 65, 1, ...zRange)
|
||||
const noise = layers.length === 0 ? undefined : biomeSource.getClimates?.(...xRange, 64, 65, 1, ...zRange)
|
||||
|
||||
for (let x = 0; x < 200; x += options.res) {
|
||||
for (let z = 0; z < 200; z += options.res) {
|
||||
@@ -76,7 +75,7 @@ export async function biomeMap(state: any, img: ImageData, options: BiomeSourceO
|
||||
let color: Triple = [50, 50, 50]
|
||||
if (options.layers.has('biomes')) {
|
||||
const biome = biomes?.[j] ?? biomeSource.getBiome(worldX, 64, worldZ)
|
||||
color = getBiomeColor(biome, options.biomeColors)
|
||||
color = getBiomeColor(biome.toString(), options.biomeColors)
|
||||
} else if (noise && layers[0]) {
|
||||
const value = noise[j][layers[0]]
|
||||
const [min, max] = LAYERS[layers[0]]
|
||||
@@ -96,13 +95,13 @@ export async function getBiome(state: any, x: number, z: number, options: BiomeS
|
||||
|
||||
const [xx, zz] = toWorld([x, z], options)
|
||||
return {
|
||||
biome: biomeSource.getBiome(xx, 64, zz),
|
||||
biome: biomeSource.getBiome(xx, 64, zz).toString(),
|
||||
...biomeSource.getClimate?.(xx, 64, zz),
|
||||
}
|
||||
}
|
||||
|
||||
async function getCached(state: any, options: BiomeSourceOptions): Promise<{ biomeSource: CachedBiomeSource}> {
|
||||
const newState = [state, options.octaves, options.shaper.toJson(), `${options.seed}`, options.version]
|
||||
const newState = [state, options.octaves, `${options.seed}`, options.version]
|
||||
if (!deepEqual(newState, cacheState)) {
|
||||
cacheState = deepClone(newState)
|
||||
|
||||
@@ -116,7 +115,7 @@ async function getCached(state: any, options: BiomeSourceOptions): Promise<{ bio
|
||||
async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<CachedBiomeSource> {
|
||||
switch (state?.type?.replace(/^minecraft:/, '')) {
|
||||
case 'fixed':
|
||||
return new FixedBiome(state.biome as string)
|
||||
return new FixedBiome(Identifier.parse(state.biome as string))
|
||||
|
||||
case 'checkerboard':
|
||||
const shift = (state.scale ?? 2) + 2
|
||||
@@ -124,21 +123,21 @@ 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].node as string)
|
||||
return Identifier.parse(state.biomes?.[i].node as string)
|
||||
},
|
||||
}
|
||||
|
||||
case 'multi_noise':
|
||||
switch(state.preset?.replace(/^minecraft:/, '')) {
|
||||
case 'nether':
|
||||
state = options.version === '1.18' ? NetherPreset18 : NetherPreset
|
||||
state = checkVersion(options.version, '1.18') ? NetherPreset18 : NetherPreset
|
||||
break
|
||||
case 'overworld':
|
||||
state = options.version === '1.18' ? await OverworldPreset18() : state
|
||||
state = checkVersion(options.version, '1.18') ? await OverworldPreset18() : state
|
||||
break
|
||||
}
|
||||
state = DataModel.unwrapLists(state)
|
||||
if (options.version === '1.18') {
|
||||
if (checkVersion(options.version, '1.18')) {
|
||||
await loadWasm()
|
||||
const BiomeIds = new BiMap<string, number>()
|
||||
const param = (p: number | number[]) => {
|
||||
@@ -167,11 +166,11 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<
|
||||
return {
|
||||
getBiome(x, y, z) {
|
||||
const ids = multi_noise(parameters, sampler, x, x + 1, 1, y, y + 1, 1, z, z + 1, 1)
|
||||
return BiomeIds.getA(ids[0]) ?? 'unknown'
|
||||
return Identifier.parse(BiomeIds.getA(ids[0]) ?? 'unknown')
|
||||
},
|
||||
getBiomes(xFrom, xTo, xStep, yFrom, yTo, yStep, zFrom, zTo, zStep) {
|
||||
const ids = multi_noise(parameters, sampler, xFrom, xTo, xStep, yFrom, yTo, yStep, zFrom, zTo, zStep)
|
||||
return [...ids].map(id => BiomeIds.getA(id) ?? 'unknown')
|
||||
return [...ids].map(id => Identifier.parse(BiomeIds.getA(id) ?? 'unknown'))
|
||||
},
|
||||
getClimate(x, y, z) {
|
||||
const climate = climate_noise(sampler, x, x + 1, 1, y, y + 1, 1, z, z + 1, 1)
|
||||
@@ -184,21 +183,17 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<
|
||||
weirdness: w,
|
||||
}
|
||||
},
|
||||
getClimates(layers, xFrom, xTo, xStep, yFrom, yTo, yStep, zFrom, zTo, zStep) {
|
||||
getClimates(xFrom, xTo, xStep, yFrom, yTo, yStep, zFrom, zTo, zStep) {
|
||||
const climate = climate_noise(sampler, xFrom, xTo, xStep, yFrom, yTo, yStep, zFrom, zTo, zStep)
|
||||
const result = []
|
||||
for (let i = 0; i < climate.length; i += 7) {
|
||||
const [t, h, c, e, w] = climate.slice(i, i + 5)
|
||||
const point = TerrainShaper.point(c, e, w)
|
||||
result.push({
|
||||
temperature: t,
|
||||
humidity: h,
|
||||
continentalness: c,
|
||||
erosion: e,
|
||||
weirdness: w,
|
||||
...layers.has('offset') && { offset: options.shaper.offset(point) },
|
||||
...layers.has('factor') && { factor: options.shaper.factor(point) },
|
||||
...layers.has('jaggedness') && { jaggedness: options.shaper.jaggedness(point) },
|
||||
})
|
||||
}
|
||||
return result
|
||||
@@ -212,10 +207,10 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<
|
||||
return new NormalNoise(new LegacyRandom(options.seed + BigInt(i)), config)
|
||||
})
|
||||
if (!Array.isArray(state.biomes) || state.biomes.length === 0) {
|
||||
return new FixedBiome('unknown')
|
||||
return new FixedBiome(Identifier.create('unknown'))
|
||||
}
|
||||
return {
|
||||
getBiome(x: number, _y: number, z: number): string {
|
||||
getBiome(x: number, _y: number, z: number): Identifier {
|
||||
const n = noise.map(n => n.sample(x, z, 0))
|
||||
let minDist = Infinity
|
||||
let minBiome = ''
|
||||
@@ -226,7 +221,7 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<
|
||||
minBiome = biome
|
||||
}
|
||||
}
|
||||
return minBiome
|
||||
return Identifier.parse(minBiome)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { DataModel } from '@mcschema/core'
|
||||
import type { BlockState } from 'deepslate'
|
||||
import { BlockPos, Chunk, ChunkPos, FixedBiome, NoiseChunkGenerator, NoiseGeneratorSettings } from 'deepslate'
|
||||
import { BlockPos, Chunk, ChunkPos, clampedMap, DensityFunction, FixedBiome, Identifier, NoiseChunkGenerator, NoiseGeneratorSettings, NoiseParameters, NoiseRouter, NoiseSettings, Registry, WorldgenRegistries, XoroshiroRandom } from 'deepslate'
|
||||
import * as deepslate18 from 'deepslate-1.18'
|
||||
import type { VersionId } from '../services'
|
||||
import { checkVersion } from '../services'
|
||||
import { checkVersion, fetchAllPresets } from '../services'
|
||||
import { deepClone, deepEqual } from '../Utils'
|
||||
import { NoiseChunkGenerator as OldNoiseChunkGenerator } from './noise/NoiseChunkGenerator'
|
||||
|
||||
@@ -40,20 +41,25 @@ const colors: Record<string, [number, number, number]> = {
|
||||
let cacheState: any
|
||||
let generatorCache: NoiseChunkGenerator
|
||||
let chunkCache: Chunk[] = []
|
||||
const registryCache = new Map<VersionId, Registry<Registry<any>>>()
|
||||
|
||||
export function noiseSettings(state: any, img: ImageData, options: NoiseSettingsOptions) {
|
||||
export async function noiseSettings(state: any, img: ImageData, options: NoiseSettingsOptions) {
|
||||
if (checkVersion(options.version, '1.18')) {
|
||||
if (checkVersion(options.version, '1.18.2')) {
|
||||
await initRegistries(options.version)
|
||||
}
|
||||
|
||||
const { settings, generator } = getCached(state, options)
|
||||
|
||||
const slice = new LevelSlice(-options.offset, options.width, settings.noise.minY, settings.noise.height)
|
||||
slice.generate(generator, options.biome ?? 'minecraft:plains')
|
||||
slice.generate(generator, options.biome)
|
||||
|
||||
const data = img.data
|
||||
for (let x = 0; x < options.width; x += 1) {
|
||||
for (let y = 0; y < settings.noise.height; y += 1) {
|
||||
const i = x * 4 + (settings.noise.height-y-1) * 4 * img.width
|
||||
const state = slice.getBlockState([x - options.offset, y + settings.noise.minY, Z])
|
||||
const color = colors[state.getName()] ?? [0, 0, 0]
|
||||
const color = colors[state.getName().toString()] ?? [0, 0, 0]
|
||||
data[i] = color[0]
|
||||
data[i + 1] = color[1]
|
||||
data[i + 2] = color[2]
|
||||
@@ -88,6 +94,79 @@ export function getNoiseBlock(x: number, y: number) {
|
||||
return chunk.getBlockState(BlockPos.create(x, y, Z))
|
||||
}
|
||||
|
||||
export async function densityFunction(state: any, img: ImageData, options: NoiseSettingsOptions) {
|
||||
const { fn, settings } = await createDensityFunction(state, options)
|
||||
|
||||
const arr = Array(options.width * settings.height)
|
||||
let min = Infinity
|
||||
let max = -Infinity
|
||||
for (let x = 0; x < options.width; x += 1) {
|
||||
for (let y = 0; y < settings.height; y += 1) {
|
||||
const i = x + (settings.height-y-1) * options.width
|
||||
const density = fn.compute(DensityFunction.context(x - options.offset, y, 0))
|
||||
min = Math.min(min, density)
|
||||
max = Math.max(max, density)
|
||||
arr[i] = density
|
||||
}
|
||||
}
|
||||
|
||||
const data = img.data
|
||||
for (let i = 0; i < options.width * settings.height; i += 1) {
|
||||
const color = Math.floor(clampedMap(arr[i], min, max, 0, 256))
|
||||
data[4 * i] = color
|
||||
data[4 * i + 1] = color
|
||||
data[4 * i + 2] = color
|
||||
data[4 * i + 3] = 255
|
||||
}
|
||||
}
|
||||
|
||||
async function createDensityFunction(state: any, options: NoiseSettingsOptions) {
|
||||
await initRegistries(options.version)
|
||||
|
||||
const random = XoroshiroRandom.create(options.seed).forkPositional()
|
||||
const settings = NoiseSettings.fromJson({
|
||||
min_y: -64,
|
||||
height: 384,
|
||||
size_horizontal: 1,
|
||||
size_vertical: 2,
|
||||
sampling: { xz_scale: 1, y_scale: 1, xz_factor: 80, y_factor: 160 },
|
||||
bottom_slide: { target: 0.1171875, size: 3, offset: 0 },
|
||||
top_slide: { target: -0.078125, size: 2, offset: 8 },
|
||||
terrain_shaper: { offset: 0.044, factor: 4, jaggedness: 0 },
|
||||
})
|
||||
const originalFn = DensityFunction.fromJson(state)
|
||||
const fn = originalFn.mapAll(NoiseRouter.createVisitor(random, settings))
|
||||
|
||||
return {
|
||||
fn,
|
||||
settings,
|
||||
}
|
||||
}
|
||||
|
||||
const Registries: [string, { fromJson(obj: unknown): any}][] = [
|
||||
['worldgen/noise', NoiseParameters],
|
||||
['worldgen/density_function', DensityFunction],
|
||||
]
|
||||
|
||||
async function initRegistries(version: VersionId) {
|
||||
const rootRegistries = registryCache.get(version) ?? new Registry(new Identifier('misode', 'temp'))
|
||||
if (!registryCache.has(version)) {
|
||||
await Promise.all(Registries.map(([id, c]) => fetchRegistry(version, rootRegistries, id, c)))
|
||||
registryCache.set(version, rootRegistries)
|
||||
}
|
||||
WorldgenRegistries.DENSITY_FUNCTION.clear().assign(rootRegistries.getOrThrow(Identifier.create('worldgen/density_function')))
|
||||
WorldgenRegistries.NOISE.clear().assign(rootRegistries.getOrThrow(Identifier.create('worldgen/noise')))
|
||||
}
|
||||
|
||||
async function fetchRegistry<T extends { fromJson(obj: unknown): T }>(version: VersionId, root: Registry<Registry<unknown>>, id: string, clazz: T) {
|
||||
const entries = await fetchAllPresets(version, id)
|
||||
const registry = new Registry<typeof clazz>(Identifier.create(id))
|
||||
for (const [key, value] of entries.entries()) {
|
||||
registry.register(Identifier.parse(key), clazz.fromJson(value))
|
||||
}
|
||||
root.register(registry.key, registry)
|
||||
}
|
||||
|
||||
function getCached(state: unknown, options: NoiseSettingsOptions) {
|
||||
const settings = NoiseGeneratorSettings.fromJson(DataModel.unwrapLists(state))
|
||||
|
||||
@@ -95,8 +174,13 @@ function getCached(state: unknown, options: NoiseSettingsOptions) {
|
||||
if (!deepEqual(newState, cacheState)) {
|
||||
cacheState = deepClone(newState)
|
||||
chunkCache = []
|
||||
const biomeSource = new FixedBiome('unknown')
|
||||
generatorCache = new NoiseChunkGenerator(options.seed, biomeSource, settings)
|
||||
if (checkVersion(options.version, '1.18.2')) {
|
||||
const biomeSource = new FixedBiome(Identifier.create('unknown'))
|
||||
generatorCache = new NoiseChunkGenerator(options.seed, biomeSource, settings)
|
||||
} else {
|
||||
const biomeSource = new deepslate18.FixedBiome('unknown')
|
||||
generatorCache = new deepslate18.NoiseChunkGenerator(options.seed, biomeSource, settings as any) as any
|
||||
}
|
||||
}
|
||||
return {
|
||||
settings,
|
||||
@@ -137,10 +221,10 @@ class LevelSlice {
|
||||
})
|
||||
}
|
||||
|
||||
public generate(generator: NoiseChunkGenerator, forcedBiome: string) {
|
||||
public generate(generator: NoiseChunkGenerator, forcedBiome?: string) {
|
||||
this.chunks.forEach((chunk, i) => {
|
||||
if (!this.done[i]) {
|
||||
generator.fill(chunk)
|
||||
generator.fill(chunk, true)
|
||||
generator.buildSurface(chunk, forcedBiome)
|
||||
this.done[i] = true
|
||||
chunkCache.push(chunk)
|
||||
|
||||
@@ -15,10 +15,11 @@ import { ModelWrapper } from './ModelWrapper'
|
||||
const selectRegistries = ['loot_table.type', 'loot_entry.type', 'function.function', 'condition.condition', 'criterion.trigger', 'recipe.type', 'dimension.generator.type', 'dimension.generator.biome_source.type', 'dimension.generator.biome_source.preset', 'carver.type', 'feature.type', 'decorator.type', 'feature.tree.minimum_size.type', 'block_state_provider.type', 'trunk_placer.type', 'foliage_placer.type', 'tree_decorator.type', 'int_provider.type', 'float_provider.type', 'height_provider.type', 'structure_feature.type', 'surface_builder.type', 'processor.processor_type', 'rule_test.predicate_type', 'pos_rule_test.predicate_type', 'template_element.element_type', 'block_placer.type', 'block_predicate.type', 'material_rule.type', 'material_condition.type', 'structure_placement.type', 'density_function.type']
|
||||
const hiddenFields = ['number_provider.type', 'score_provider.type', 'nbt_provider.type', 'int_provider.type', 'float_provider.type', 'height_provider.type']
|
||||
const flattenedFields = ['feature.config', 'decorator.config', 'int_provider.value', 'float_provider.value', 'block_state_provider.simple_state_provider.state', 'block_state_provider.rotated_block_provider.state', 'block_state_provider.weighted_state_provider.entries.entry.data', 'rule_test.block_state', 'structure_feature.config', 'surface_builder.config', 'template_pool.elements.entry.element', 'decorator.block_survives_filter.state', 'material_rule.block.result_state']
|
||||
const inlineFields = ['loot_entry.type', 'function.function', 'condition.condition', 'criterion.trigger', 'dimension.generator.type', 'dimension.generator.biome_source.type', 'feature.type', 'decorator.type', 'block_state_provider.type', 'feature.tree.minimum_size.type', 'trunk_placer.type', 'foliage_placer.type', 'tree_decorator.type', 'block_placer.type', 'rule_test.predicate_type', 'processor.processor_type', 'template_element.element_type', 'nbt_operation.op', 'number_provider.value', 'score_provider.name', 'score_provider.target', 'nbt_provider.source', 'nbt_provider.target', 'generator_biome.biome', 'block_predicate.type', 'material_rule.type', 'material_condition.type']
|
||||
const inlineFields = ['loot_entry.type', 'function.function', 'condition.condition', 'criterion.trigger', 'dimension.generator.type', 'dimension.generator.biome_source.type', 'feature.type', 'decorator.type', 'block_state_provider.type', 'feature.tree.minimum_size.type', 'trunk_placer.type', 'foliage_placer.type', 'tree_decorator.type', 'block_placer.type', 'rule_test.predicate_type', 'processor.processor_type', 'template_element.element_type', 'nbt_operation.op', 'number_provider.value', 'score_provider.name', 'score_provider.target', 'nbt_provider.source', 'nbt_provider.target', 'generator_biome.biome', 'block_predicate.type', 'material_rule.type', 'material_condition.type', 'density_function.type']
|
||||
const nbtFields = ['function.set_nbt.tag', 'advancement.display.icon.nbt', 'text_component_object.nbt', 'entity.nbt', 'block.nbt', 'item.nbt']
|
||||
const fixedLists = ['generator_biome.parameters.temperature', 'generator_biome.parameters.humidity', 'generator_biome.parameters.continentalness', 'generator_biome.parameters.erosion', 'generator_biome.parameters.depth', 'generator_biome.parameters.weirdness', 'feature.end_spike.crystal_beam_target', 'feature.end_gateway.exit', 'decorator.block_filter.offset', 'block_predicate.matching_blocks.offset', 'block_predicate.matching_fluids.offset', 'model_element.from', 'model_element.to', 'model_element.rotation.origin', 'model_element.faces.uv', 'item_transform.rotation', 'item_transform.translation', 'item_transform.scale', 'generator_structure.random_spread.locate_offset']
|
||||
const collapsedFields = ['noise_settings.surface_rule', 'noise_settings.noise.terrain_shaper']
|
||||
const collapsableFields = ['density_function.argument', 'density_function.argument1', 'density_function.argument2', 'density_function.input', 'density_function.when_in_range', 'density_function.when_out_of_range']
|
||||
|
||||
const findGenerator = (id: string) => {
|
||||
return config.generators.find(g => g.id === id.replace(/^\$/, ''))
|
||||
@@ -265,12 +266,13 @@ const renderHtml: RenderHook = {
|
||||
}
|
||||
}
|
||||
const context = path.getContext().join('.')
|
||||
if (collapsedFields.includes(context)) {
|
||||
if (collapsableFields.includes(context) || collapsedFields.includes(context)) {
|
||||
const toggled = isToggled('')
|
||||
const expanded = collapsedFields.includes(context) ? toggled : !toggled
|
||||
prefix = <>
|
||||
<button class="toggle tooltipped tip-se" aria-label={localize(lang, toggled ? 'collapse' : 'expand')} onClick={toggled ? collapse('') : expand('')}>{toggled ? Octicon.chevron_down : Octicon.chevron_right}</button>
|
||||
<button class="toggle tooltipped tip-se" aria-label={localize(lang, expanded ? 'collapse' : 'expand')} onClick={toggled ? collapse('') : expand('')}>{expanded ? Octicon.chevron_down : Octicon.chevron_right}</button>
|
||||
</>
|
||||
if (!toggled) {
|
||||
if (!expanded) {
|
||||
return [prefix, suffix, null]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { CollectionRegistry } from '@mcschema/core'
|
||||
import config from '../../config.json'
|
||||
import { message } from '../Utils'
|
||||
import type { BlockStateRegistry, VersionId } from './Schemas'
|
||||
import type { CollectionRegistry } from '@mcschema/core';
|
||||
import config from '../../config.json';
|
||||
import { message } from '../Utils';
|
||||
import type { BlockStateRegistry, VersionId } from './Schemas';
|
||||
|
||||
// Cleanup old caches
|
||||
['1.15', '1.16', '1.17'].forEach(v => localStorage.removeItem(`cache_${v}`));
|
||||
@@ -21,7 +21,7 @@ declare var __LATEST_VERSION__: string
|
||||
const latestVersion = __LATEST_VERSION__ ?? ''
|
||||
const mcmetaUrl = 'https://raw.githubusercontent.com/misode/mcmeta'
|
||||
|
||||
type McmetaTypes = 'summary' | 'data' | 'assets'
|
||||
type McmetaTypes = 'summary' | 'data' | 'assets' | 'registries'
|
||||
|
||||
function mcmeta(version: Version, type: McmetaTypes) {
|
||||
return `${mcmetaUrl}/${version.dynamic ? type : `${version.ref}-${type}`}`
|
||||
@@ -88,6 +88,20 @@ export async function fetchPreset(versionId: VersionId, registry: string, id: st
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchAllPresets(versionId: VersionId, registry: string) {
|
||||
console.debug(`[fetchAllPresets] ${versionId} ${registry}`)
|
||||
const version = config.versions.find(v => v.id === versionId)!
|
||||
try {
|
||||
const entries = await getData(`${mcmeta(version, 'registries')}/${registry}/data.min.json`)
|
||||
return new Map<string, unknown>(await Promise.all(
|
||||
entries.map(async (e: string) =>
|
||||
[e, await getData(`${mcmeta(version, 'data')}/data/minecraft/${registry}/${e}.json`)])
|
||||
))
|
||||
} catch (e) {
|
||||
throw new Error(`Error occurred while fetching all ${registry} presets: ${message(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
export type SoundEvents = {
|
||||
[key: string]: {
|
||||
sounds: (string | { name: string })[],
|
||||
|
||||
Reference in New Issue
Block a user