猫史档案馆


一键生成树林!!!(修改版)

用户:1086DRRalsei1086DRRalsei查看:0 回复:3 评论:0 创建时间:2021-02-12T09:09:54


有些代码来自官方

但大部分是我自己写的

function cylinder(cx, cy, cz, vox, radius, height) {
    xend = cx + radius
    yend = cy + height
    zend = cz + radius
    for (let x = cx - radius; x <= xend; x++) {
        for (let z = cz - radius; z <= zend; z++) {
            dx = x - cx;
            dz = z - cz;
            if (Math.round(Math.sqrt(dx * dx + dz * dz)) <= radius) {
                for (let y = cy; y < yend; y++) {
                    voxels.setVoxel(x, y, z, vox)
                }
            }
        }
    }

}

for (let i = 0; i < 340; i++) { // 300个随机圆柱体构成场景
    x = Math.random() * 325 // x坐标
    z = Math.random() * 325 // z坐标
    r = 2 + Math.random() * 5 //半径 2~7
    h = Math.random() * 4 // 高 0~4
    cylinder(x, 9, z, 'dirt', r, h)
}

for (let y = 9; y < 13; y++) {//扫描9~12层的格子
    for (let x = 0; x < 327; x++) {
        for (let z = 0; z < 327; z++) {
            if (voxels.getVoxel(x, y, z) != 0 && voxels.getVoxel(x, y + 1, z) == 0) {// 如果当前格子不为空而它上面那格是空的, 则表示它是此地形的表面 
                voxels.setVoxel(x, y, z, 'grass')// 土块替换成喵地
            }
        }
    }
}
async function 喵(x, y, z, r = 0) {
    r = Math.floor(Math.random() * 5+2)
    for (let q = x-r;q < x+r;q++){
        for (let w = y;w<y+r;w++){
            for (let e = z-r;e<z+r;e++){
                voxels.setVoxel(q,w,e,'green_leaf')
            }
        }
    }
}
for (let w = 0; w < 601; w++) {
    var 喵 = Math.floor(Math.random() * 280)
    var wz = Math.floor(Math.random() * 280)
    var wc = Math.floor(Math.random() * 10)
    while (!wc % 2 === 1) {
        var wc = Math.floor(Math.random() * 10)
    }
    var wth = Math.floor(Math.random() * 10)
    var wh = Math.floor(Math.random() * 12) + 7
    for (let w1 = 7; w1 < 7 + wh; w1++) {
        voxels.setVoxelId(喵, w1, wz, voxels.id('wood'))
    }
    喵(喵, 7 + wh, wz)
    world.say('地形生成中...请耐心等待...(' + w + '/600)')
}


回复

上一页1 页 / 共 1下一页
AbnormalLOGAbnormalLOG

改一下:

function cylinder(cx, cy, cz, vox, radius, height) {
    xend = cx + radius;
    yend = cy + height;
    zend = cz + radius;
    for (let x = cx - radius; x <= xend; x++) {
        for (let z = cz - radius; z <= zend; z++) {
            dx = x - cx;
            dz = z - cz;
            if (Math.round(Math.sqrt(dx * dx + dz * dz)) <= radius) {
                for (let y = cy; y < yend; y++) {
                    voxels.setVoxel(x, y, z, vox);
                };
            };
        };
    };

};

for (let i = 0; i < 340; i++) { /* 300个随机圆柱体构成场景*/
    x = Math.random() * 325; /* x坐标*/
    z = Math.random() * 325; /* z坐标*/
    r = 2 + Math.random(); * 5 /*半径 2~7*/
    h = Math.random() * 4; /* 高 0~4*/
    cylinder(x, 9, z, 'dirt', r, h);
};

for (let y = 9; y < 13; y++) {//扫描9~12层的格子
    for (let x = 0; x < 327; x++) {
        for (let z = 0; z < 327; z++) {
            if (voxels.getVoxel(x, y, z) != 0 && voxels.getVoxel(x, y + 1, z) == 0) {/* 如果当前格子不为空而它上面那格是空的, 则表示它是此地形的表面 */
                voxels.setVoxel(x, y, z, 'grass');/* 土块替换成喵地*/
            };
        };
    };
};
async function 喵(x, y, z, r = 0) {
    r = Math.floor(Math.random() * 5+2);
    for (let q = x-r;q < x+r;q++){
        for (let w = y;w<y+r;w++){
            for (let e = z-r;e<z+r;e++){
                voxels.setVoxel(q,w,e,'green_leaf');
            };
        };
    };
};
for (let w = 0; w < 601; w++) {
    var 喵 = Math.floor(Math.random() * 280);
    var wz = Math.floor(Math.random() * 280);
    var wc = Math.floor(Math.random() * 10);
    while (!wc % 2 === 1) {
        var wc = Math.floor(Math.random() * 10);
    };
    var wth = Math.floor(Math.random() * 10);
    var wh = Math.floor(Math.random() * 12) + 7;
    for (let w1 = 7; w1 < 7 + wh; w1++) {
        voxels.setVoxelId(喵, w1, wz, voxels.id('wood'));
    };
    喵(喵, 7 + wh, wz);
    world.say('地形生成中...请耐心等待...(' + w + '/600)');
};



点赞0


评论


未名用户未名用户

center_image

点赞0


评论


灵清帝王吃爆一切厕所灵清帝王吃爆一切厕所

挖坟

点赞0


评论