游戏直播礼物互动——我的世界填格子TNT整蛊游戏直播(直播弹幕抓取)

一、前言        

        相信大家和我一样!很好奇那些我的世界游戏直播是怎么进行礼物互动的!

        刷抖音时看到有人在直播我的世界,进去看见后发现竟是个整蛊类的游戏直播

                                                              图片来自直播截图

         游戏内容就和上图一样:主播在填格子,填满区域内格子算完成任务,观众可以通过点赞、送礼来整蛊主播完成任务。

        而我曾是一位我的世界游戏爱好者,这种新颖的游戏直播礼物互动的整蛊游戏,非常吸引我。

        于是我去”借鉴“”查阅“相关资料,从学习如何做插件,到学习如何结合爬虫抓取直播间的数据进行游戏上的反馈。

        终于在我的不懈努力下,我仿造出来一个类似的我的世界填格子TNT整蛊游戏直播!

        以下便是我做出来的我的世界直播互动游戏!

二、步骤

1、首先获取直播间数据:

以下为示例图

2、其次建立我的世界服务器

使用paper.jar:

首先去官网下载 https://papermc.io/software/paper

开服教程可以借鉴其他的博主

记住要有JDK

点击脚本会自动下载,出现以下画面就可以

3、我的世界版本1.20.4,

离线模式进入游戏

登入服务器——多人游戏 输入127.0.0.1即可

4、关键环节——插件的制作

具体代码就不展示了,因为涉及到编译器、依赖库的问题比较多

这里只展示部分生成TNT和增加消除格子的代码

    //生成TNT函数
    public void spawnTNT(int num,String name,String gift) {
        World world = areaLocation.getWorld();
        int x = areaLocation.getBlockX();
        int y = areaLocation.getBlockY();
        int z = areaLocation.getBlockZ();
        int quantity = 10;
        player.playSound(player.getLocation(),"niganma",1.0f,1.0f);
        String title = "§d坤坤打击!";
        String subtitle = "§e"+name+"§7送出§6"+gift+": §9TNTק9"+num+"§9!";
        player.sendTitle(title, subtitle, 10, 20, 10);
        player.sendMessage(subtitle);
//        System.out.println(name+"送出 "+gift+" : TNT×"+num+"!");
        System.out.println(name+" 送出 "+gift);
        for (int i = 0; i < quantity; i++) {
            int spawnX = x  + 2 + (int) (Math.random() * length-2);
            int spawnZ = z  + 2 + (int) (Math.random() * width-2);
            int spawnY = y + num; // Spawn the TNT 20 blocks above the area
            Location tntLocation = new Location(world, spawnX, spawnY, spawnZ);
            TNTPrimed tnt = (TNTPrimed) world.spawnEntity(tntLocation, EntityType.PRIMED_TNT);
            tnt.setFuseTicks(80); // Adjust fuse ticks as needed
        }
    }
    //增加格子函数
    public void addBlocks(World world, int x, int y, int z,int h,String name,String gift) {
        player.playSound(player.getLocation(),"aligaduo",1.0f,1.0f);
        String title = "§d雪中送碳!";
        String subtitle = "§e"+name+"§7送出§6"+gift+": §4增加§4"+ h +"§4层!";
//        String subtitle = "§4增加5层!";
        player.sendTitle(title, subtitle, 10, 20, 10);
        player.sendMessage(subtitle);
//        System.out.println(name+"送出 "+gift+" : 增加"+ h +"层!");
        System.out.println(name+" 送出 "+gift);
        int currentLow = getCurrentLow(world,x,y,z);
//        System.out.println(currentLow);
        if(currentLow + h >= height-1){
            h = height-currentLow;
        }
//        System.out.println(h);
//        else if(currentHeight<h){
//            h = currentHeight;
//        }
        for (int i = 1; i < length-1; i++) {
            for (int j = currentLow-1; j < currentLow + h - 1; j++) {
                for (int k = 1; k < width-1; k++) {
                    Material fixedMaterial = getFixedMaterial(j);
                    world.getBlockAt(x + i, y + j, z + k).setType(fixedMaterial);
                }
            }
        }
        updateFillProgress();
    }
    //消除格子函数
    public void clearBlocks(World world, int x, int y, int z,int h,String name,String gift) {
        player.playSound(player.getLocation(),"rqq",1.0f,1.0f);
        String title = "§d爱的清除!";
        String subtitle = "§e"+name+"§7送出§6"+gift+": §4消除§4"+ h +"§4层!";
//        String subtitle = "§4消除5层!";
        player.sendTitle(title, subtitle, 10, 20, 10);
        player.sendMessage(subtitle);
//        System.out.println(name+"送出 "+gift+" : 消除"+ h +"层!");
        System.out.println(name+" 送出 "+gift);
        int currentHeight = getCurrentHeight(world,x,y,z);
//        System.out.println(currentHeight);
        if(currentHeight==0){
            return;
        }
        else if(currentHeight<h){
            h = currentHeight;
        }
        for (int i = 1; i < length-1; i++) {
            for (int j = currentHeight; j > currentHeight-1-h; j--) {
                for (int k = 1; k < width-1; k++) {
                    if(j!=0){
                        world.getBlockAt(x + i, y + j, z + k).setType(Material.AIR);
                    }

                }
            }
        }
        updateFillProgress();
    }

                                                注明:代码是本人自己写的,无出处

三、效果展示

我的世界填格子TNT整蛊游戏直播效果展示视频

说明:视频来自b站本人的号——我的世界整蛊直播互动https://space.bilibili.com/38316029

四、结语

        兄弟们,因为创作不易,想了解的人也多,有米分享了,想要的可以私信我

        谢谢大家!后续有想法做不同的游戏模式的,也可以找我做或者一起探讨哦!

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值