mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Add option to change Y for biome map
This commit is contained in:
@@ -4,7 +4,7 @@ import { useLocale, useProject, useStore } from '../../contexts/index.js'
|
||||
import { useCanvas } from '../../hooks/index.js'
|
||||
import { biomeMap, getBiome } from '../../previews/index.js'
|
||||
import { randomSeed } from '../../Utils.js'
|
||||
import { Btn } from '../index.js'
|
||||
import { Btn, BtnMenu, NumberInput } from '../index.js'
|
||||
import type { PreviewProps } from './index.js'
|
||||
|
||||
export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps) => {
|
||||
@@ -12,6 +12,7 @@ export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps
|
||||
const { project } = useProject()
|
||||
const [seed, setSeed] = useState(randomSeed())
|
||||
const [scale, setScale] = useState(2)
|
||||
const [yOffset, setYOffset] = useState(64)
|
||||
const [focused, setFocused] = useState<{[k: string]: number | string} | undefined>(undefined)
|
||||
const { biomeColors } = useStore()
|
||||
const offset = useRef<[number, number]>([0, 0])
|
||||
@@ -21,13 +22,14 @@ export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps
|
||||
const settings = DataModel.unwrapLists(model.get(new Path(['generator', 'settings'])))
|
||||
const state = JSON.stringify([data, settings])
|
||||
const type: string = data.type?.replace(/^minecraft:/, '')
|
||||
const hasRandomness = type === 'multi_noise' || type === 'the_end'
|
||||
|
||||
const { canvas, redraw } = useCanvas({
|
||||
size() {
|
||||
return [200 / res.current, 200 / res.current]
|
||||
},
|
||||
async draw(img) {
|
||||
const options = { settings, biomeColors, offset: offset.current, scale, seed, res: res.current, version, project }
|
||||
const options = { settings, biomeColors, offset: offset.current, scale, seed, res: res.current, version, project, y: yOffset }
|
||||
await biomeMap(data, img, options)
|
||||
if (res.current === 4) {
|
||||
clearTimeout(refineTimeout.current)
|
||||
@@ -41,25 +43,27 @@ export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps
|
||||
offset.current[0] = offset.current[0] + dx * 200
|
||||
offset.current[1] = offset.current[1] + dy * 200
|
||||
clearTimeout(refineTimeout.current)
|
||||
res.current = type === 'multi_noise' ? 4 : 1
|
||||
res.current = hasRandomness ? 4 : 1
|
||||
redraw()
|
||||
},
|
||||
async onHover(x, y) {
|
||||
const options = { settings, biomeColors, offset: offset.current, scale, seed: seed, res: 1, version, project }
|
||||
const options = { settings, biomeColors, offset: offset.current, scale, seed: seed, res: 1, version, project, y: yOffset }
|
||||
const biome = await getBiome(data, Math.floor(x * 200), Math.floor(y * 200), options)
|
||||
setFocused(biome)
|
||||
},
|
||||
onLeave() {
|
||||
setFocused(undefined)
|
||||
},
|
||||
}, [version, state, scale, seed, biomeColors, project])
|
||||
}, [version, state, scale, seed, yOffset, biomeColors, project])
|
||||
|
||||
useEffect(() => {
|
||||
if (shown) {
|
||||
res.current = type === 'multi_noise' ? 4 : 1
|
||||
res.current = hasRandomness ? 4 : 1
|
||||
redraw()
|
||||
}
|
||||
}, [version, state, scale, seed, shown, biomeColors, project])
|
||||
}, [version, state, scale, seed, yOffset, shown, biomeColors, project])
|
||||
|
||||
console.log(yOffset)
|
||||
|
||||
const changeScale = (newScale: number) => {
|
||||
newScale = Math.max(1, Math.round(newScale))
|
||||
@@ -76,9 +80,16 @@ export const BiomeSourcePreview = ({ model, data, shown, version }: PreviewProps
|
||||
<Btn icon="plus" tooltip={locale(Math.round(scale) <= 1 ? 'zoom_in_limit' : 'zoom_in')}
|
||||
disabled={Math.round(scale) <= 1}
|
||||
onClick={() => changeScale(scale / 2)} />
|
||||
{(type === 'multi_noise' || type === 'the_end') &&
|
||||
{hasRandomness && <>
|
||||
<BtnMenu icon="stack">
|
||||
<div class="btn btn-input" onClick={e => e.stopPropagation()}>
|
||||
<span>{locale('y')}</span>
|
||||
<NumberInput value={yOffset} onChange={setYOffset} />
|
||||
</div>
|
||||
</BtnMenu>
|
||||
<Btn icon="sync" tooltip={locale('generate_new_seed')}
|
||||
onClick={() => setSeed(randomSeed())} />}
|
||||
onClick={() => setSeed(randomSeed())} />
|
||||
</>}
|
||||
</div>
|
||||
{focused?.temperature !== undefined && <div class="controls secondary-controls">
|
||||
<Btn class="no-pointer" label={Object.entries(focused)
|
||||
|
||||
@@ -16,6 +16,7 @@ type BiomeSourceOptions = {
|
||||
version: VersionId,
|
||||
settings: unknown,
|
||||
project: Project,
|
||||
y: number,
|
||||
}
|
||||
|
||||
export async function biomeMap(state: any, img: ImageData, options: BiomeSourceOptions) {
|
||||
@@ -33,7 +34,7 @@ export async function biomeMap(state: any, img: ImageData, options: BiomeSourceO
|
||||
const maxX = minX + quartWidth
|
||||
const maxZ = minZ + quartWidth
|
||||
|
||||
const { palette, data, width, height } = DEEPSLATE.fillBiomes(minX * 4, maxX * 4, minZ * 4, maxZ * 4, quartStep * options.res)
|
||||
const { palette, data, width, height } = DEEPSLATE.fillBiomes(minX * 4, maxX * 4, minZ * 4, maxZ * 4, quartStep * options.res, options.y)
|
||||
|
||||
let x = 0
|
||||
let z = 0
|
||||
@@ -66,7 +67,9 @@ export async function getBiome(state: any, x: number, z: number, options: BiomeS
|
||||
const xx = Math.floor(centerX + ((x - 100) * quartStep))
|
||||
const zz = Math.floor(centerZ + ((z - 100) * quartStep))
|
||||
|
||||
const { palette, data } = DEEPSLATE.fillBiomes(xx * 4, xx * 4 + 4, zz * 4, zz * 4 + 4)
|
||||
console.log('get biome', options.y)
|
||||
|
||||
const { palette, data } = DEEPSLATE.fillBiomes(xx * 4, xx * 4 + 4, zz * 4, zz * 4 + 4, 1, options.y)
|
||||
const biome = palette.get(data[0])!
|
||||
|
||||
return {
|
||||
|
||||
@@ -17,7 +17,6 @@ export class Deepslate {
|
||||
private loadingVersion: VersionId | undefined
|
||||
private loadingPromise: Promise<void> | undefined
|
||||
private readonly deepslateCache = new Map<VersionId, typeof deepslate19>()
|
||||
private readonly Y = 64
|
||||
private readonly Z = 0
|
||||
private readonly DEBUG = false
|
||||
|
||||
@@ -243,11 +242,11 @@ export class Deepslate {
|
||||
})
|
||||
}
|
||||
|
||||
public fillBiomes(minX: number, maxX: number, minZ: number, maxZ: number, step = 1) {
|
||||
public fillBiomes(minX: number, maxX: number, minZ: number, maxZ: number, step = 1, y = 64) {
|
||||
if (!this.generatorCache || !this.settingsCache) {
|
||||
throw new Error('Tried to fill biomes before generator is loaded')
|
||||
}
|
||||
const quartY = (this.Y - this.settingsCache.minY) >> 2
|
||||
const quartY = (y - this.settingsCache.minY) >> 2
|
||||
const minQuartX = minX >> 2
|
||||
const maxQuartX = maxX >> 2
|
||||
const minQuartZ = minZ >> 2
|
||||
@@ -262,7 +261,7 @@ export class Deepslate {
|
||||
|
||||
for (let x = minQuartX; x < maxQuartX; x += step) {
|
||||
for (let z = minQuartZ; z < maxQuartZ; z += step) {
|
||||
const posKey = `${x}:${z}`
|
||||
const posKey = `${x}:${quartY}:${z}`
|
||||
let biome = this.biomeCache.get(posKey)
|
||||
if (!biome) {
|
||||
if (this.DEBUG) {
|
||||
|
||||
@@ -219,6 +219,7 @@
|
||||
"worldgen/template_pool": "Template Pool",
|
||||
"worldgen/world_preset": "World Preset",
|
||||
"worldgen/flat_level_generator_preset": "Flat World Preset",
|
||||
"y": "Y",
|
||||
"zoom_in": "Zoom in",
|
||||
"zoom_in_limit": "Cannot zoom in further\n1 pixel = 4 blocks",
|
||||
"zoom_out": "Zoom out"
|
||||
|
||||
Reference in New Issue
Block a user