猫史档案馆


有大佬来帮我改一改吗

用户:1366155545013661555450查看:3 回复:3 评论:3 创建时间:2022-08-16T16:00:08


function half(a){
    if(a%1>0.5){
        return a-a%1+1
    }else{
        return a-a%1+0.5
    }
}
function list_scpoy(list){
    a=[]
    for(const i in list){
        a.push(i)
    }return a
}
async function river(name,height){
    var math=Math.random()
    let way=[]
    if(math<0.25){
        var x=randint(128,160)
        var z=randint(-32,160)
        var start_round=randint(4,10)
        var round=start_round+half_river()*2
        way.push(x)
        way.push(z)
        way.push(round)
        for(i=0;i<randint(20,30);i++){ 
            cylinder(x,height+80,z,"sand",round+2,1)
            cylinder(x,height+79,z,"sand",round,1)
            if(round>=4.5){
                cylinder(x,height+79,z,"sand",round,1)
                cylinder(x,height+78,z,"sand",round-2,1)
            }if(round>=6.5){
                cylinder(x,height+78,z,"sand",round-1,1)
                cylinder(x,height+77,z,"sand",round-3,1)
            }if(round>=8.5){
                cylinder(x,height+77,z,"sand",round-2,1)
                cylinder(x,height+76,z,"sand",round-4,1)
            }var round2=round
            var height2=height
            for(i=height;i<name.length;i++){
                var round2=round2+name[height2]
                cylinder(x,i+81,z,"air",round2,1)
                var height2=height2+1
            }var x=x-randint(1,round-1)
            var z=z+half_river()*2+half_river()*2
            if(round<=start_round-3||round<=3.5){
                var round=round+1
            }else if(round>=start_round+3||round>=10.5){
                var round=round-1
            }else{
                var round=round+half_river()*2
            }
            if(x>160 || x<-32 || z>160 || z<-32){
                break
            }
            way.push(x)
            way.push(z)
            way.push(round)
        }way.pop()
        way.pop()
        way.pop()
        for(i=0;i<way.length/3+1;i++){
            var x=way[i*3]
            var z=way[i*3+1]
            var round=way[i*3+2]
            cylinder(x,height+80,z,"water",round,1)
            if(round>=4.5){
                cylinder(x,height+79,z,"water",round-2,1)
            }if(round>=6.5){
                cylinder(x,height+78,z,"water",round-3,1)
            }if(round>=8.5){
            cylinder(x,height+77,z,"water",round-4,1)
    }}}if(math<0.5){
        var x=randint(-32,0)
        var z=randint(-32,160)
        var start_round=randint(4,10)
        var round=start_round+half_river()*2
        way.push(x)
        way.push(z)
        way.push(round)
        for(i=0;i<randint(20,30);i++){ 
            cylinder(x,height+80,z,"sand",round+2,1)
            cylinder(x,height+79,z,"sand",round,1)
            if(round>=4.5){
                cylinder(x,height+79,z,"sand",round,1)
                cylinder(x,height+78,z,"sand",round-2,1)
            }if(round>=6.5){
                cylinder(x,height+78,z,"sand",round-1,1)
                cylinder(x,height+77,z,"sand",round-3,1)
            }if(round>=8.5){
                cylinder(x,height+77,z,"sand",round-2,1)
                cylinder(x,height+76,z,"sand",round-4,1)
            }var round2=round
            var height2=height
            for(i=height;i<name.length;i++){
                var round2=round2+name[height2]
                cylinder(x,i+81,z,"air",round2,1)
                var height2=height2+1
            }var x=x+randint(1,round-1)
            var z=z+half_river()*2+half_river()*2
            if(round<=start_round-3||round<=3.5){
                var round=round+1
            }else if(round>=start_round+3||round>=10.5){
                var round=round-1
            }else{
                var round=round+half_river()*2
            }
            if(x>160 || x<-32 || z>160 || z<-32){
                break
            }
            way.push(x)
            way.push(z)
            way.push(round)
        }way.pop()
        way.pop()
        way.pop()
        for(var i=0;i<way.length/3+1;i++){
            var x=way[i*3]
            var z=way[i*3+1]
            var round=way[i*3+2]
            cylinder(x,height+80,z,"water",round,1)
            if(round>=4.5){
                cylinder(x,height+79,z,"water",round-2,1)
            }if(round>=6.5){
                cylinder(x,height+78,z,"water",round-3,1)
            }if(round>=8.5){
                cylinder(x,height+77,z,"water",round-4,1)
    }}}if(math<0.75){
        var x=randint(-32,160)
        var z=randint(128,160)
        var start_round=randint(4,10)
        var round=start_round+half_river()*2
        way.push(x)
        way.push(z)
        way.push(round)
        for(i=0;i<randint(20,30);i++){ 
            cylinder(x,height+80,z,"sand",round+2,1)
            cylinder(x,height+79,z,"sand",round,1)
            if(round>=4.5){
                cylinder(x,height+79,z,"sand",round,1)
                cylinder(x,height+78,z,"sand",round-2,1)
            }if(round>=6.5){
                cylinder(x,height+78,z,"sand",round-1,1)
                cylinder(x,height+77,z,"sand",round-3,1)
            }if(round>=8.5){
                cylinder(x,height+77,z,"sand",round-2,1)
                cylinder(x,height+76,z,"sand",round-4,1)
            }var round2=round
            var height2=height
            for(i=height;i<name.length;i++){
                var round2=round2+name[height2]
                cylinder(x,i+81,z,"air",round2,1)
                var height2=height2+1
            }var x=x+half_river()*2+half_river()*2
            var z=z-randint(1,round-1)
            if(round<=start_round-3||round<=3.5){
                var round=round+1
            }else if(round>=start_round+3||round>=10.5){
                var round=round-1
            }else{
                var round=round+half_river()*2
            }
            if(x>160 || x<-32 || z>160 || z<-32){
                break
            }
            way.push(x)
            way.push(z)
            way.push(round)
        }way.pop()
        way.pop()
        way.pop()
        for(i=0;i<way.length/3+1;i++){
            var x=way[i*3]
            var z=way[i*3+1]
            var round=way[i*3+2]
            cylinder(x,height+80,z,"water",round,1)
            if(round>=4.5){
                cylinder(x,height+79,z,"water",round-2,1)
            }if(round>=6.5){
                cylinder(x,height+78,z,"water",round-3,1)
            }if(round>=8.5){
            cylinder(x,height+77,z,"water",round-4,1)
    }}}else{
        var x=randint(-32,160)
        var z=randint(-128,-160)
        var start_round=randint(4,10)
        var round=start_round+half_river()*2
        way.push(x)
        way.push(z)
        way.push(round)
        for(i=0;i<randint(20,30);i++){ 
            cylinder(x,height+80,z,"sand",round+2,1)
            cylinder(x,height+79,z,"sand",round,1)
            if(round>=4.5){
                cylinder(x,height+79,z,"sand",round,1)
                cylinder(x,height+78,z,"sand",round-2,1)
            }if(round>=6.5){
                cylinder(x,height+78,z,"sand",round-1,1)
                cylinder(x,height+77,z,"sand",round-3,1)
            }if(round>=8.5){
                cylinder(x,height+77,z,"sand",round-2,1)
                cylinder(x,height+76,z,"sand",round-4,1)
            }var round2=round
            var height2=height
            for(i=height;i<name.length;i++){
                var round2=round2+name[height2]
                cylinder(x,i+81,z,"air",round2,1)
                var height2=height2+1
            }var x=x+half_river()*2+half_river()*2
            var z=z-randint(1,round-1)
            if(round<=start_round-3||round<=3.5){
                var round=round+1
            }else if(round>=start_round+3||round>=10.5){
                var round=round-1
            }else{
                var round=round+half_river()*2
            }
            if(x>160 || x<-32 || z>160 || z<-32){
                break
            }
            way.push(x)
            way.push(z)
            way.push(round)
        }way.pop()
        way.pop()
        way.pop()
        for(var i=0;i<way.length/3+1;i++){
            var x=way[i*3]
            var z=way[i*3+1]
            var round=way[i*3+2]
            cylinder(x,height+80,z,"water",round,1)
            if(round>=4.5){
                cylinder(x,height+79,z,"water",round-2,1)
            }if(round>=6.5){
                cylinder(x,height+78,z,"water",round-3,1)
            }if(round>=8.5){
            cylinder(x,height+77,z,"water",round-4,1)
    }}}for(var y=80;y<96;y++){
    for(var x=0;x<127;x++){
    for(var z=0;z<127;z++){
    if(voxels.name(voxels.getVoxel(x,y,z))=="dirt" && voxels.getVoxel(x,y+1,z)==0){// 如果当前格子不为空而它上面那格是空的, 则表示它是此地形的表面 
    voxels.setVoxel(x,y,z,'grass')
}}}}}
function hole(name,height){
    var x=randint(-喵,172)
    var z=randint(-喵,172)
    var y=randint(height+80,90)
    var height2=y
    for(i=y;i<name.length;i++){
                var round2=round2+name[height2]
                cylinder(x,i+81,z,"air",round2,1)
                var height2=height2+1
    }for(var y=80;y<96;y++){
    for(var x=0;x<127;x++){
    for(var z=0;z<127;z++){
    if(voxels.name(voxels.getVoxel(x,y,z))=="dirt" && voxels.getVoxel(x,y+1,z)==0){// 如果当前格子不为空而它上面那格是空的, 则表示它是此地形的表面 
    voxels.setVoxel(x,y,z,'grass')
}}}}}
function half_river(){
    s=Math.random()
    if(s<=0.3){
        return -0.5
    }else if(s<=0.6){
        return 0
    }else{
        return 0.5
}}
async function new_world(){
    let dirt=[]
    var water=randint(5,7)
    for (var i=0;i<15;i++){
    if(i==water){
        dirt.push(3)
    }else{
        dirt.push(randint(4,7))
    }}
    club(0,80,0,128,15,128,'dirt')
    await sleep(10)
    for(var i=0;i<randint(1,7);i++){
        river(dirt,water)
        await sleep(200)
    }await sleep(3)//for(i=0;i<randint(3,5);i++){
        //hole(dirt,water)
        //await sleep(0.3)
        sun_zombie=[]
        await sleep(10)
    for(var time=0;time<randint(80,120);time++){
        tree(Math.round(Math.random()*127),Math.round(Math.random()*127))
        await(1)
}}
function club(place_x,place_y,place_z,side_x,side_y,side_z,rock){
    var ex=place_x+side_x
    var ey=place_y+side_y
    var ez=place_z+side_z
    for(var x=place_x;x<ex;x++){  
        for(var z=place_z;z<ez;z++){
            for(var y=place_y;y<ey;y++){
                voxels.setVoxel(x,y,z,rock)
            }
        }
    }
}
function sphere(vox, cx, cy, cz, radius){
    let xend = cx+radius
    let yend = cy+radius
    let zend = cz+radius
    for(let x=cx-radius;x<=xend;x++){
    for(let y=cy-radius;y<=yend;y++){
    for(let z=cz-radius;z<=zend;z++){
        let dx = x
        let dy = y-cy
        let dz = z-cz;
        if(Math.round(Math.sqrt(dx*dx+dy*dy+dz*dz)) <= radius){
            voxels.setVoxel(x,y,z,vox)
        }
    }}}
}
function randint(minNum,maxNum){ 
    switch(arguments.length){ 
        case 1: 
            return parseInt(Math.random()*minNum+1,10); 
        break; 
        case 2: 
            return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
        break; 
            default: 
                return 0; 
            break;
    }
}
function in_stone(hight_place_y,hight_size_x,hight_size_y,hight_size_z,material,hight_time,low_time){
    for(var hard=0;hard<randint(hight_time,low_time);hard++){
        club(randint(0,127),randint(0,hight_place_y-hight_size_y),randint(0,127-hight_size_z),randint(1,hight_size_x),randint(1,hight_size_y),randint(1,hight_size_z),material)
    }
}
function spawn_grass(x,y,z,meshName,scale){
  const meshScale = scale/16 //默认模型方块大小倍数为地图方块的1/16
  const entity = world.createEntity({
    mesh:meshName,//模型名
    collides:false,//不能碰撞
    fixed:true,//固定
    gravity:true,// 不受重力影响
    meshScale:[meshScale,meshScale,meshScale],//xyz放大倍数
    position:[x,y,z],//位置坐标
  })
  entity.addTag(scale)
  return entity
}
function spawn1(x,y,z,meshName,scale,tag){
  const meshScale = scale/16 //默认模型方块大小倍数为地图方块的1/16
  const entity = world.createEntity({
    mesh:meshName,//模型名
    collides:true,//不能碰撞
    fixed:true,//固定
    gravity:true,// 不受重力影响
    meshScale:[meshScale,meshScale,meshScale],//xyz放大倍数
    position:[x,y,z],//位置坐标
  })
  entity.addTag(tag)
  return entity
}
function tree(x,z){
    for(var y=85;y<96;y++){
        if(voxels.name(voxels.getVoxel(x,y,z))=="grass" && voxels.getVoxel(x,y+1,z)==0){
            if(voxels.getVoxel(x-2,y+3,z)==0 && voxels.getVoxel(x+2,y+3,z)==0 && voxels.getVoxel(x,y+3,z+2)==0 && voxels.getVoxel(x,y+3,z-2)==0){
                club(x-2,y+3,z-2,5,2,5,"green_leaf")
                club(x-1,y+5,z-1,3,1,3,"green_leaf")
                club(x-1,y+6,z,3,1,1,'green_leaf')
                club(x,y+6,z-1,1,1,3,'green_leaf')
                club(x,y+1,z,1,5,1,"wood")
                break
            }else{
                break
            }

        }
    }
}
function hight_low(hight){
    var func=Math.random()
    if (func<0.5){
        var turn=Math.round(Math.random()*hight)
        return turn
    }else{
        var turn=0-Math.round(Math.random()*hight)
        return turn
    }
}
function scopy(obj) {  
    var newObj = {};  
    if (obj instanceof Array) {  
        newObj = [];  
    }  
    for (var key in obj) {  
        var val = obj[key];  
        //newObj[key] = typeof val === 'object' ? arguments.callee(val) : val; //arguments.callee 在哪一个函数中运行,它就代表哪个函数, 一般用在匿名函数中。  
        newObj[key] = typeof val === 'object' ? scopy(val): val;  
    }  
    return newObj;  
}; 
async function rock(){
    for(var y=0;y<81;y++){
        club(0,y,0,128,1,128,"stone")
        await sleep(1)
    }await sleep(3)
    in_stone(60,2,2,2,'black',700,1000)
    in_stone(60,2,2,2,'orange',500,800)
    in_stone(40,2,2,2,'medium_yellow',150,230)
    in_stone(20,2,1,2,'medium_spring_green',300,500)
    in_stone(20,1,1,2,'medium_green',10,20)
    await sleep(10)
    for(var time=0;time<randint(2,5);time++){
        buildCave(30,40)
        buildCave(30,60)   
}}
new_world()
rock()


回复

上一页1 页 / 共 1下一页
1366155545013661555450

他老是time out

 

点赞0


评论


呵呵0486呵呵0486

换行好美观()()

点赞0


评论


萌新大佬萌新大佬

river里面循环嵌套用的一个循环变量

点赞0


评论