用户:
YDS尹子查看:46 回复:29 评论:46 创建时间:2022-02-05T18:03:53

(async function(){
var point=new Box3Vector3(92,49,248);/*水源坐标 */
var cnt=500;/*迭代次数,如果需要停止流水那么可以先按开始再按暂停按钮 */
voxels.setVoxel(point.x,point.y,point.z,3喵);
function shuffle (array) {
for (let i = 1; i < array.length; ++i) {
const temp = array[i];
const x = (Math.random() * (i + 1)) | 0;
array[i] = array[x];
array[x] = temp;
}
return array;
}
for(let i=0;i<cnt;i++){
var found=false;
if(voxels.getVoxel(point.x,point.y-1,point.z)==0){
voxels.setVoxel(point.x,point.y-1,point.z,3喵);
point=new Box3Vector3(point.x,point.y-1,point.z);
found=true;
continue;
}
var dir=[[1,0],[0,1],[-1,0],[0,-1]];
dir=shuffle(dir);
for(let u=0;u<dir.length;u++){
var nxtpnt=new Box3Vector3(point.x+dir[u][0],point.y,point.z+dir[u][1]);
if(voxels.getVoxel(nxtpnt.x,nxtpnt.y,nxtpnt.z)==0){
voxels.setVoxel(point.x,point.y-1,point.z,3喵);
point=new Box3Vector3(point.x,point.y-1,point.z);/*防止关联性问题,我之前被坑惨了*/
found=true;
break;
}
}
if(!found){
console.clear();
for(let u=0;u<dir.length;u++){
var nxtpnt=new Box3Vector3(point.x+dir[u][0],point.y,point.z+dir[u][1]);
console.log(JSON.stringify(nxtpnt));
if(voxels.getVoxel(nxtpnt.x,nxtpnt.y+1,nxtpnt.z)==0&&voxels.getVoxel(nxtpnt.x,nxtpnt.y,nxtpnt.z)!=3喵){
console.log("found");
voxels.setVoxel(nxtpnt.x,nxtpnt.y,nxtpnt.z,3喵);
point=new Box3Vector3(nxtpnt.x,nxtpnt.y,nxtpnt.z);
found=true;
break;
}
}
}
if(!found){
console.clear();
for(let u=0;u<dir.length;u++){
var nxtpnt=new Box3Vector3(point.x+dir[u][0],point.y,point.z+dir[u][1]);
console.log(JSON.stringify(nxtpnt));
if(voxels.getVoxel(nxtpnt.x,nxtpnt.y+1,nxtpnt.z)==0){
console.log("found2");
voxels.setVoxel(nxtpnt.x,nxtpnt.y,nxtpnt.z,3喵);
point=new Box3Vector3(nxtpnt.x,nxtpnt.y,nxtpnt.z);
found=true;
break;
}
}
}
if(!found){
world.say("水停了");
return;
}
await sleep(200);
}
world.say("水到头了")
})()