从零开发PocketMine插件笔记(1)——给僵尸实体添加不同掉落物

环境:php7.0

服务端:GenisysPro

我的世界版本:1.1.X

辅助工具:devtools.phar插件

目标:修改PureEntitiesX生物插件中僵尸的掉落物,从而延伸到所有实体

原始代码:

public function getDrops() {
    $drops = []; // 初始化掉落物数组

    if ($this->isLootDropAllowed()) { // 检查是否允许掉落物品
        array_push($drops, Item::get(Item::ROTTEN_FLESH, 0, mt_rand(0, 2))); // 添加腐肉掉落,数量在0到2之间随机
        switch (mt_rand(0, 5)) { // 随机选择一种物品进行掉落
            case 1:
                array_push($drops, Item::get(Item::CARROT, 0, 1)); // 添加胡萝卜掉落,数量为1
                break;
            case 2:
                array_push($drops, Item::get(Item::POTATO, 0, 1)); // 添加土豆掉落,数量为1
                break;
            case 3:
                array_push($drops, Item::get(Item::IRON_INGOT, 0, 1)); // 添加铁锭掉落,数量为1
                break;
        }

        // 以9%的掉落几率添加装备
        $this->getMobEquipment()->addLoot($drops);
    }

    return $drops; // 返回掉落物品数组
}

array_push(该数组,添加的数据) 函数是PHP中用于向数组末尾添加一个或多个元素的函数。它的基本功能是将新元素添加到已有数组的木末尾,并返回新数组的长度。

mt_rand(最小值,最大值) 函数返回一个随机数

Item::get(物品名称, 特殊值, 数量))

所以在这里我们可以稍作修改,让僵尸死亡后掉落0-2个TNT,胡萝卜,土豆,小麦种子,西瓜种子,南瓜种子这样我们就不用满世界乱跑地图去找种子了O(∩_∩)O哈哈~

修改后代码:

//-------------------------------------------------------------------------------------------------------------------
    public function getDrops() {
        $drops = []; // 初始化掉落物数组
    
        if ($this->isLootDropAllowed()) { // 检查是否允许掉落物品
            array_push($drops, Item::get(Item::ROTTEN_FLESH, 0, mt_rand(0, 2))); // 添加腐肉掉落,数量在0到2之间随机
            switch (mt_rand(0, 5)) { // 随机选择一种物品进行掉落
                case 1:
                    array_push($drops, Item::get(Item::CARROT, 0, 3)); // 添加胡萝卜掉落,数量为1
                    break;
                case 2:
                    array_push($drops, Item::get(Item::POTATO, 0, 3)); // 添加土豆掉落,数量为1
                    break;
                case 3:
                    array_push($drops, Item::get(Item::IRON_INGOT, 0, 1)); // 添加铁锭掉落,数量为1
                    break;
//------------------------------------------------------------------------------------
                case 4:
                    array_push($drops, Item::get(Item::WHEAT_SEEDS, 0, 3)); //小麦种子
                    break;
                case 5:
                    array_push($drops, Item::get(Item::PUMPKIN_SEEDS, 0, 3)); //南瓜种子
                    break;
                case 6:
                    array_push($drops, Item::get(Item::MELON_SEEDS, 0, 3)); //西瓜种子
                    break;
//-------------------------------------------------------------------------------------------

            }
    
            // 以9%的掉落几率添加装备
            $this->getMobEquipment()->addLoot($drops);
        }
    
        return $drops; // 返回掉落物品数组
    }
//--------------------------------------------------------------------------------------------------------------------

效果图

先欠着

温馨提示: 本文最后更新于2024-07-18 00:16:45,某些文章具有时效性,若有错误或已失效,请在下方评论 留言或联系 树萌芽の小窝
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
评论 共1条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/shumengya.top/wp-content/plugins/ACG/inc/options/functions.php on line 382

    Warning: file_get_contents(https://api.oioweb.cn/api/ip/ipaddress?ip=183.221.133.61): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/shumengya.top/wp-content/plugins/ACG/inc/options/functions.php on line 382