Add bamboo feature

This commit is contained in:
Misode
2023-12-11 22:59:31 +01:00
parent c84772e3a8
commit a74be78c51
2 changed files with 30 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
import type { BlockState, Random } from 'deepslate' import type { Random } from 'deepslate'
import { BlockPos } from 'deepslate' import { BlockPos, BlockState } from 'deepslate'
import type { VersionId } from '../../services/index.js' import type { VersionId } from '../../services/index.js'
import { sampleBlockState, sampleInt } from './WorldgenUtils.jsx' import { sampleBlockState, sampleInt } from './WorldgenUtils.jsx'
@@ -20,6 +20,25 @@ export function placeFeature(data: any, ctx: FeatureContext) {
const Features: { const Features: {
[key: string]: (config: any, ctx: FeatureContext) => void, [key: string]: (config: any, ctx: FeatureContext) => void,
} = { } = {
bamboo: (config, ctx) => {
const n = ctx.nextInt(12) + 5
if (ctx.nextFloat() < config?.probability ?? 0) {
const s = ctx.nextInt(4) + 1
for (let x = -s; x <= s; x += 1) {
for (let z = -s; z <= s; z += 1) {
if (x * x + z * z <= s * s) {
ctx.place([x, -1, z], new BlockState('podzol', { snowy: 'false' }))
}
}
}
}
for (let i = 0; i < n; i += 1) {
ctx.place([0, i, 0], new BlockState('bamboo', { age: '1', leaves: 'none', stage: '0' }))
}
ctx.place([0, n, 0], new BlockState('bamboo', { age: '1', leaves: 'large', stage: '1'}))
ctx.place([0, n-1, 0], new BlockState('bamboo', { age: '1', leaves: 'large', stage: '0'}))
ctx.place([0, n-2, 0], new BlockState('bamboo', { age: '1', leaves: 'small', stage: '0'}))
},
tree: (config, ctx) => { tree: (config, ctx) => {
const trunk = config.trunk_placer const trunk = config.trunk_placer
const trunkPlacerType = trunk.type.replace(/^minecraft:/, '') const trunkPlacerType = trunk.type.replace(/^minecraft:/, '')

View File

@@ -15,7 +15,7 @@ import { InteractiveCanvas3D } from './InteractiveCanvas3D.jsx'
import { nextGaussian } from './WorldgenUtils.jsx' import { nextGaussian } from './WorldgenUtils.jsx'
import type { PreviewProps } from './index.js' import type { PreviewProps } from './index.js'
const MAX_SIZE = 25 const MAX_SIZE = 45
export const FeaturePreview = ({ data, version, shown }: PreviewProps) => { export const FeaturePreview = ({ data, version, shown }: PreviewProps) => {
const { locale } = useLocale() const { locale } = useLocale()
@@ -35,8 +35,8 @@ export const FeaturePreview = ({ data, version, shown }: PreviewProps) => {
version: version, version: version,
random, random,
place: (pos, block) => { place: (pos, block) => {
const structurePos = BlockPos.offset(pos, placeOffset, 0, placeOffset) const structurePos = BlockPos.offset(pos, placeOffset, placeOffset, placeOffset)
if (structurePos.some(v => v < 0 || v >= MAX_SIZE)) return if (structurePos.some((v, i) => v < 0 || v >= structure.getSize()[i])) return
const name = typeof block === 'string' ? block : block.getName() const name = typeof block === 'string' ? block : block.getName()
const properties = typeof block === 'string' ? undefined : block.getProperties() const properties = typeof block === 'string' ? undefined : block.getProperties()
structure.addBlock(structurePos, name, properties) structure.addBlock(structurePos, name, properties)
@@ -52,10 +52,14 @@ export const FeaturePreview = ({ data, version, shown }: PreviewProps) => {
const renderer = useRef<StructureRenderer | undefined>(undefined) const renderer = useRef<StructureRenderer | undefined>(undefined)
const onSetup = useCallback((canvas: HTMLCanvasElement) => { const onSetup = useCallback((canvas: HTMLCanvasElement) => {
if (renderer.current) {
renderer.current.setStructure(structure)
return
}
if (!resources || !shown) return if (!resources || !shown) return
const gl = canvas.getContext('webgl') const gl = canvas.getContext('webgl')
if (!gl) return if (!gl) return
renderer.current = new StructureRenderer(gl, structure, resources) renderer.current = new StructureRenderer(gl, structure, resources, { useInvisibleBlockBuffer: false })
}, [resources, shown, structure]) }, [resources, shown, structure])
const onResize = useCallback((width: number, height: number) => { const onResize = useCallback((width: number, height: number) => {
renderer.current?.setViewport(0, 0, width, height) renderer.current?.setViewport(0, 0, width, height)
@@ -69,7 +73,7 @@ export const FeaturePreview = ({ data, version, shown }: PreviewProps) => {
<Btn icon="sync" tooltip={locale('generate_new_seed')} onClick={() => setSeed(randomSeed())} /> <Btn icon="sync" tooltip={locale('generate_new_seed')} onClick={() => setSeed(randomSeed())} />
</div> </div>
<div class="full-preview"> <div class="full-preview">
<InteractiveCanvas3D onSetup={onSetup} onDraw={onDraw} onResize={onResize} startDistance={10} startPosition={[MAX_SIZE/2, 0, MAX_SIZE/2]} startYRotation={2.6} /> <InteractiveCanvas3D onSetup={onSetup} onDraw={onDraw} onResize={onResize} startDistance={10} startPosition={[MAX_SIZE/2, MAX_SIZE/2, MAX_SIZE/2]} startYRotation={2.6} />
</div> </div>
</> </>
} }