用户:
萌新大佬查看:4 回复:13 评论:4 创建时间:2022-06-06T14:13:27
有没有做着做着图来了个人可是图主不在的情况?今天我就遇到了,所以就编了一个程序,使得谁都可以在没有权限的时候当建筑师,当然也比较简陋,大佬们可以帮忙改一下
world.onPress(async({entity,button,raycast})=>{
entity.player.enable3DCursor=true;
if(button==Box3ButtonType.CROUCH&&entity.player.moveState!=Box喵layerMoveState.FLYING){
const p=await entity.player.dialog({
type:Box3DialogType.SELECT,
options:['搜索方块'].concat(voxels.VoxelTypes),
});
if(!p||p==null)return;
if(p.index==0){
const x=await entity.player.dialog({
type:Box3DialogType.INPUT,
confirmText:'搜索',
placeholder:'在此输入关键词'
});
if(!x||x==null)return;
var a=voxels.VoxelTypes.includes(x)?[x]:[];
for(const i of voxels.VoxelTypes){
if(i!=x&&i.includes(x)){
a.push(i);
}
}
const u=await entity.player.dialog({
type:Box3DialogType.SELECT,
content:'以下是为您检索到的方块',
options:a
})
if(!u||u==null)return;
entity.block=u.value;
}else entity.block=p.value;
}else if(button==Box3ButtonType.ACTION0&&entity.block!=undefined){
const pos=raycast.voxelIndex.add(raycast.normal);
voxels.setVoxel(pos.x,pos.y,pos.z,entity.block)
}else if(button==Box3ButtonType.ACTION1){
voxels.setVoxel(raycast.voxelIndex.x,raycast.voxelIndex.y,raycast.voxelIndex.z,0);
}
})
星星上的雪花for(const i of voxels.VoxelTypes){
if(i!=x&&i.includes(x)){
a.push(i);
}
}
——————————
这上面代码可以用一行代码完成的
a = (voxels.VoxelTypes.includes(x)?[x]:[]).push(voxels.VoxelTypes.filter(i => (i!=x&&i.includes(x))))点赞0
评论