猫史档案馆


【求助】代码为什么有时候超时过一会又好了???

用户:1366155545013661555450查看:1 回复:2 评论:1 创建时间:2022-07-10T15:04:14


求大佬给解决方法。

world.onPlayerJoin(({ entity }) => {
    entity.player.canFly = true;
});
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 river(name,height){
    world.say("1")
    var math=Math.random()
    if(math<0.25){
        var x=randint(喵,128)
        var z=randint(喵,128)
        var start_round=randint(2,4)
        var round=round+half(Math.random()-0.5)
        for(i=0;i<randint(30,50);i++){
            cylinder(x,height,z,"water",round,1)
            if(round<=2.5){
                cylinder(x,height-1,z,"water",round-2,1)
            }if(round<=3.5){
                cylinder(x,height-2,z,"water",round-3,1)
            }if(round=4.5){
                cylinder(x,height-3,z,"water",round-4,1)
            }var round2=round
            for(i=height;i<name.length;i++){
                var round2=round2+name[height]
                cylinder(x,i+1,z,"water",round2,1)
            }var x=x+randint(1,round-1)
            var z=z+randint(1,round-1)
            if(round<=start_round-1||round<=1.5){
                var round=round+1
            }else if(round>=start_round+1||round>=4.5){
                var round=round-1
            }else{
                var round=round+half(Math.random()-0.5)
            }}}}
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 half(a){
    if(a%1>0.5){
        return a-a%1+1
    }else{
        return a-a%1+0.5
    }
}
function cylinder(cx,cy,cz,vox,radius,height){
  var xend = cx+radius
  var yend = cy+height
  var zend = cz+radius
  for(var x=cx-radius;x<=xend;x++){
    for(var z=cz-radius;z<=zend;z++){
      var dx = x-cx;
      var dz = z-cz;
      if(Math.round(Math.sqrt(dx*dx+dz*dz))<=radius){
        for(var y=cy;y<yend;y++){
          voxels.setVoxel(x,y,z,vox)
        }
      }
    }
  }
}
club(0,70,0,128,15,128,'dirt')
let dirt=[]
var water=randint(5,7)
for (i=0;i<15;i++){
    dirt.push(randint(1,2))
}
for (i=0;i<10;i++){
    river(dirt,water)
}


回复

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

加了await后又只能运行一次

 

点赞0


评论


1366155545013661555450

问题就是加了之后它就动都不动了

点赞0


评论