用户:
1086DRRalsei查看:9 回复:2 评论:9 创建时间:2021-02-11T17:56:00
费了一下午写出来的
有些来自官方代码
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 < 301; w++) {
var 喵 = Math.floor(Math.random() * 180)
var wz = Math.floor(Math.random() * 180)
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 + '/300)')
}
该账号已被封禁……
最后一行的代码有点问题哦~
建议改成world.say(`地形生成中,请耐心等待(进度:${w/300}`)
否则会消息推送为:地形生成中……请耐心等待(30(随便一个数字)/300)
点赞0
评论