猫史档案馆


【box3】矿洞生成代码

用户:YDS尹子YDS尹子查看:38 回复:38 评论:38 创建时间:2021-08-12T06:04:12


center_image

适合257的地图~

async function buildCave(num){
    var starPos=new Box3Vector3(24+Math.random()*200,65,24+Math.random()*200)
    for(let i=62;i>0;i--){
        if(voxels.getVoxel(starPos.x,i,starPos.z)==voxels.id("grass")){
            starPos.y=i;
            break;
        }
    }
    var ang=[Math.random()*360,-15]
    for(let i=0;i<num;i++){
        await sleep(100);
        cave(4+Math.random()*1,starPos);
        if(i%5!=0){
        ang[0]+=Math.random()*50-25;
        
        if(starPos.y>15)
        ang[1]+=Math.random()*4-2;
        else{
        ang[1]+=Math.random()*4+10;
        }
        }else{
            ang[0]+=Math.random()*180-90
            ang[1]+=Math.random()*10-5;
        }
        ang[0]%=360;

        
        var delta=new Box3Vector3(Math.sin(ang[0]*Math.PI/180),Math.sin(ang[1]*Math.PI/180),Math.cos(ang[0]*Math.PI/180)).scale(5);
        starPos.x+=delta.x;
        starPos.y+=delta.y;
        starPos.z+=delta.z;
    }
    await sleep(1000);
}
function cave(r,pos){
var block=0;
for(let i=pos.x-r;i<=pos.x+r;i++){
    for(let j=pos.z-r;j<=pos.z+r;j++){
        for(let k=pos.y-r;k<=pos.y+r;k++){   
            if(new Box3Vector3(i,k,j).distance(pos)<=r&&voxels.getVoxel(i,k+1,j)!=voxels.id("water")){
                voxels.setVoxel(i,k,j,block);
                
            }
        }
    }
}
voxels.setVoxel(pos.x,pos.y+r,pos.z,"lantern_01")

}
buildCave(100);//洞穴长度

 


回复

上一页1 页 / 共 2下一页
七式草莓七式草莓

抢沙发()

能不能向你问不会的代码??

点赞0


评论


七式草莓七式草莓

还有空气里面有灯是怎么回事??

跑酷生成器()

点赞0


评论


YDS尹子YDS尹子

建议平均地形高度:55

点赞0


评论


神兽喵神兽喵

可以没矿物嘤嘤嘤

针不戳*=3

点赞0


评论


七式草莓七式草莓

控制台改良版

async function buildCave(num){
    var starPos=new Box3Vector3(24+Math.random()*200,65,24+Math.random()*200);
    for(let i=62;i>0;i--){
        if(voxels.getVoxel(starPos.x,i,starPos.z)==voxels.id("grass")){
            starPos.y=i;
            break;
        }
    };
    var ang=[Math.random()*360,-15];
    for(let i=0;i<num;i++){
        await sleep(100);
        cave(4+Math.random()*1,starPos);
        if(i%5!=0){
        ang[0]+=Math.random()*50-25;
        
        if(starPos.y>15)
        ang[1]+=Math.random()*4-2;
        else{
        ang[1]+=Math.random()*4+10;
        };
        }else{
            ang[0]+=Math.random()*180-90;
            ang[1]+=Math.random()*10-5;
        };
        ang[0]%=360;

        
        var delta=new Box3Vector3(Math.sin(ang[0]*Math.PI/180),Math.sin(ang[1]*Math.PI/180),Math.cos(ang[0]*Math.PI/180)).scale(5);
        starPos.x+=delta.x;
        starPos.y+=delta.y;
        starPos.z+=delta.z;
    };
    await sleep(1000);
};
function cave(r,pos){
var block=0;
for(let i=pos.x-r;i<=pos.x+r;i++){
    for(let j=pos.z-r;j<=pos.z+r;j++){
        for(let k=pos.y-r;k<=pos.y+r;k++){   
            if(new Box3Vector3(i,k,j).distance(pos)<=r&&voxels.getVoxel(i,k+1,j)!=voxels.id("water")){
                voxels.setVoxel(i,k,j,block);
                
            };
        };
    };
};
voxels.setVoxel(pos.x,pos.y+r,pos.z,"lantern_01");

};
buildCave(100);

点赞0


评论


JYF_斗罗JYF_斗罗

牛~

点赞0


评论


指令者指令者

尹子yyds!

点赞0


评论


ZCH编程小贝壳ZCH编程小贝壳

尹子今天早上开始批量发帖了吗emotion_doge)))

点赞1


评论


array_已退array_已退

针不戳awa

毕竟在我的地图里已经用了()

点赞0


评论


聋猪up聋猪up

257*257

我这辈子还没见过257

点赞0


评论


阳光的流熔怪Uyt5阳光的流熔怪Uyt5

woc尹子nb!

点赞0


评论


卑微OIer卑微OIer

尹子,你就差还原mc了

点赞1


评论


面具狐狸云绾兮面具狐狸云绾兮

烦诶·()

点赞0


评论


星辰Lolita星辰Lolita

666

点赞0


评论


治愈绾兮治愈绾兮

传奇的福利()()()

点赞0


评论


一个STUB用户_6715468一个STUB用户_6715468

岛民玩不起sin

点赞0


评论


星辰Lolita星辰Lolita

starPos?

点赞0


评论


AlcalaAlcala

nb

点赞0


评论


IaeaIaea

尹子yyds!!

点赞0


评论


TobylaiTobylai

尹子

这不是你的失传代码吗(

点赞2


评论


平安喵平安喵

要是放的多一点,那就成迷宫了

点赞0


评论


一个STUB用户_6715468一个STUB用户_6715468

我运气太差了

执行了10次有8次另一端在虚空里

点赞0


评论


如风gvk如风gvk

尹子帮帮忙吧,https://box3.cod喵/e/177f77dc7910e9f9507c

点赞0


评论


七式草莓七式草莓

能不能向我们讲一下原理

点赞0


评论


七式草莓七式草莓

还有你的速建是用什么打包的

点赞0


评论


面具狐狸云绾兮面具狐狸云绾兮

https://box3.codemao.cn/e/dd6740d9e27ee3c600ab

点赞0


评论


平安喵平安喵

https://box3.codemao.cn/e/9df34c4887361156cde1

 

点赞0


评论


七式草莓七式草莓

/* 此处我使用了注释,如果其他部分影响了排版也不会影响代码执行
 * 我在你的代码里面说明了原理,控制台也能使用了
 */
let/**/buildCave = async (num) => {
    /* 随机确定初始位置 */
    var/**/starPos = new Box3Vector3(24 + Math.random() * 200, 65, 24 + Math.random() * 200);
    /* 如果能,把Y坐标设置到喵地的高度 */
    for (let/**/i = 62; i > 0; i--) {
        if (voxels.getVoxel(starPos.x, i, starPos.z) == voxels.id("grass")) {
            starPos.y = i;
            break;
        }
    };
    /* 定义一个变量
     * 
     * 第一项:水平角度
     * 第二项:升降角度
     */
    var/**/ang = [Math.random() * 360, -15];
    /* 生成矿 洞 */
    for (let/**/i = 0; i < num; i++) {
        /* 防止过度卡顿 */
        await/**/sleep(100);
        /* 用空气填充一个球体,构成矿 洞的基础部分 */
        cave(4 + Math.random() * 1, starPos);
        /* 每填充5个球中有4个小程度的转弯,一个大成度的转弯 */
        if (i % 5 != 0) {
            /* 转弯 */
            ang[0] += Math.random() * 50 - 25;
            if (starPos.y > 15)
                ang[1] += Math.random() * 4 - 2;
            else {
                ang[1] += Math.random() * 4 + 10;
            };
        } else {
            ang[0] += Math.random() * 180 - 90;
            ang[1] += Math.random() * 10 - 5;
        };
        /* 纠正水平角度的角度错误 */
        ang[0] %= 360;

        /* 根据角度计算转弯的幅度 */
        var/**/delta = new/**/Box3Vector3(
            Math.sin(ang[0] * Math.PI / 180),
            Math.sin(ang[1] * Math.PI / 180),
            Math.cos(ang[0] * Math.PI / 180)
        ).scale(5);

        /* 将转弯的幅度应用到矿 洞的生成 */
        starPos.x += delta.x;
        starPos.y += delta.y;
        starPos.z += delta.z;
    };
    /* 这是干什么的??? */
    await/**/sleep(1000);
};

/* 用空气填充一个球体的函数 */
function/**/cave(r, pos) {
    /* 定义材质 */
    var/**/block = 0;
    /* 在可能的范围检测 */
    for (let/**/i = pos.x - r; i <= pos.x + r; i++) {
        for (let/**/j = pos.z - r; j <= pos.z + r; j++) {
            for (let/**/k = pos.y - r; k <= pos.y + r; k++) {
                /* 如果检测的位置在这个球里面 */
                if (new/**/Box3Vector3(i, k, j).distance(pos) <= r && voxels.getVoxel(i, k + 1, j) != voxels.id("water")) {
                    /* 设置方块为空气,原版为setVoxel,为了提高效率,使用了setVoxelId */
                    voxels.setVoxelId(i, k, j, block);
                };
            };
        };
    };

    /* 建造灯 */
    voxels.setVoxel(pos.x, pos.y + r, pos.z, "lantern_01");
};

/* 执行函数,参数为生成的矿 洞长度 */
buildCave(100);

点赞0


评论


该账号已停用该账号已停用

厉害!

emotion_编程猫_厉害了

点赞0


评论


Beck_seaBeck_sea

代码玩家竟恐怖如斯

点赞0


评论