Skip to content

How to define new objects in NOA engine.  #194

@officialblueify

Description

@officialblueify

I have this, https://mineblox3.blueify.repl.co, and I'm using the stress test generation but I'd like to stop the water from going under the dirt, and I want to prevent trees from spawning in the water. How could I go about this?

// worldgen
var decideVoxel = (x, y, z, ht, clo, chi, pillar) => {
    if (y < ht) {
        if (y < -1.8) return water
        if (y < 1.2) return grass
        return (ht - y < 1) ? grass : grass
    }
    if (y < ht + pillar) return 
    return 0
}
noa.world.on('worldDataNeeded', (requestID, data, cx, cy, cz) => {
    // fast cases when very high/low
    if (cy > 40 || cy < -20) {
        var monoID = (cy > 0) ? 0 : water
        return noa.world.setChunkData(requestID, data, null, monoID)
    }

    for (var i = 0; i < data.shape[0]; i++) {
        var x = cx + i
        for (var k = 0; k < data.shape[2]; k++) {
            var z = cz + k
            var ht = Math.sqrt(x * x + z * z) / 100
            var a = noise(x, 150)
            var b = noise(z + 50, 140)
            var c = noise(x - z - 50, 120)
            ht += 2 * a + b + c
            var pillar = (Math.random() < 0.002) ? 5 : 0
            var clo = 39 + 2 * (b - c)
            var chi = 35 + 2 * (a - b)
            for (var j = 0; j < data.shape[1]; j++) {
                var y = cy + j
                var id = decideVoxel(x, y, z, ht, clo, chi, pillar)
                data.set(i, j, k, id)
            }
        }
    }
    // tell noa the chunk's terrain data is now set
    noa.world.setChunkData(requestID, data)
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions