猫史档案馆


【box3】尹子代码分享--点击两个点自动填充方块!

用户:YDS尹子YDS尹子查看:15 回复:15 评论:15 创建时间:2020-07-09T07:43:36


这次需要填写的只有user,就是你的名字。

注意事项:

1.通过在聊天区输入“%方块名”的形式设置填充方块,例如“%white”

1.1如果输入不存在的方块名,系统会告诉你的,所以不用担心~

2.右键方块设置起始点这次没有坐标大小的问题

var user="YDS尹子";
var start={x:0,y:0,z:0};
var end={x:0,y:0,z:0};
var block="white";
function reorder(){
    if(start.x>end.x){
        var a=start.x;start.x=end.x;end.x=a;
    }
    if(start.y>end.y){
        var a=start.y;start.y=end.y;end.y=a;
    }
    if(start.z>end.z){
        var a=start.z;start.z=end.z;end.z=a;
    }
}
function fill(block){
    for(let i=start.x;i<=end.x;i++){for(let j=start.z;j<=end.z;j++){for(let k=start.y;k<=end.y;k++){
        voxels.setVoxel(i,k,j,block);
    }}}
}
world.onPlayerJoin(({entity})=>{
    entity.player.build=0;
})
world.onChat(({entity,message})=>{
    if(entity.player.name==user){
        if(message.charAt(0)=="%"){
            block=message.split('%')[1];
            if(block!="air"&&voxels.id(block)==0){
                world.say("The block does not exist.\nPlease choose again.");
                block="white";
            }else{
                world.say("fill block set.")
                block=block;
            }
        }
    }
})
world.click=world.onPress(({button,entity,raycast:{voxelIndex}})=>{
    if(button=="action1"&&entity.player.name==user){
        if(entity.player.build==0){
            start={x:voxelIndex.x,y:voxelIndex.y,z:voxelIndex.z};
            entity.player.build=1;
            world.say("start position set")
        }else if(entity.player.build==1){
            end={x:voxelIndex.x,y:voxelIndex.y,z:voxelIndex.z};
            entity.player.build=0;
            reorder();
            world.say("end position set\nfill started.\nfilled with "+block+".")
            fill(block);
            world.say("fill ended.")
        }
    }
    voxels.setVoxel(start.x,start.y,start.z,block);
    voxels.setVoxel(end.x,end.y,end.z,block);
})

2020/7/9 7:36

 

 

 


回复

上一页1 页 / 共 1下一页
BSS梅者如西BSS梅者如西

sofa

点赞0


评论


BSS梅者如西BSS梅者如西

帮忙顶

点赞0


评论


时_代眼泪_卡西米尔骑士时_代眼泪_卡西米尔骑士

顶顶顶顶

点赞0


评论


YDS尹子YDS尹子

喵d

点赞0


评论


BSS梅者如西BSS梅者如西

DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

点赞0


评论


QBZ_QBZ_

哇,给尹子打call!

点赞0


评论


YDS尹子YDS尹子

升级版:可以给多人使用权限

暂时无法在控制台运行

教程:http://www.yxtnt.cn/img/fill.mp4

var user=["ZNS卿本尊","YDS尹子"];
var start={x:0,y:0,z:0};
var end={x:0,y:0,z:0};
var block="white";
function reorder(){
    if(start.x>end.x){
        var a=start.x;start.x=end.x;end.x=a;
    }
    if(start.y>end.y){
        var a=start.y;start.y=end.y;end.y=a;
    }
    if(start.z>end.z){
        var a=start.z;start.z=end.z;end.z=a;
    }
}
function fill(block){
    for(let i=start.x;i<=end.x;i++){for(let j=start.z;j<=end.z;j++){for(let k=start.y;k<=end.y;k++){
        voxels.setVoxel(i,k,j,block);
    }}}
}
world.onPlayerJoin(({entity})=>{
    entity.player.build=0;
})
//我是分界线
world.onChat(({entity,message})=>{
    if(user.indexOf(entity.player.name)!=-1){
        if(message.charAt(0)=="%"){
            block=message.split('%')[1];
            if(block!="air"&&voxels.id(block)==0){
                world.say("The block does not exist.\nPlease choose again.");
                block="white";
            }else{
                world.say("fill block set.");
                block=block;
            }
        }
    }
})
//我是分界线
world.click=world.onPress(({button,entity,raycast:{voxelIndex}})=>{
    if(button=="action1"&&user.indexOf(entity.player.name)!=-1){
        if(entity.player.build==0){
            start={x:voxelIndex.x,y:voxelIndex.y,z:voxelIndex.z};
            entity.player.build=1;
            world.say("start position set:");
        }else if(entity.player.build==1){
            end={x:voxelIndex.x,y:voxelIndex.y,z:voxelIndex.z};
            entity.player.build=0;
            reorder();
            world.say("end position set\nfill started.\nfilled with "+block+".");
            fill(block);
            world.say("fill ended.");
        }
    }
})

点赞0


评论


SCS_user_eee2detYg0SCS_user_eee2detYg0

哈哈哈,太棒了

点赞0


评论


Chara_juechuief_sChara_juechuief_s

66666666666666

点赞0


评论


猫悟淡猫悟淡

d'd

点赞0


评论


未命名用户015734未命名用户015734

咕咕掌

点赞1


评论


Moira屑玖iMoira屑玖i

喵喵可还行·······

点赞0


评论


xlcfxlcf

谁挖的坟?

点赞1


评论


J_K_Hermione_build白泽J_K_Hermione_build白泽

厉害厉害

点赞0


评论


MrAssMrAss

针不戳

点赞0


评论