LiteLDev / LegacyScriptEngine

A plugin engine for running LLSE plugins on LeviLamina
https://lse.liteldev.com/
GNU General Public License v3.0
43 stars 8 forks source link

[Bug]:mc.explode();效果异常 #125

Closed LAppleXGR358 closed 2 months ago

LAppleXGR358 commented 4 months ago

Describe the bug

maxResistance参数设置没有效果,设置任何数都能炸掉黑曜石,甚至基岩和水都会被炸掉,设置成负数会导致爆炸半径受影响;

To Reproduce

使用代码mc.explode(pos, player, 1, 10, true, false);在目标位置执行一次威力为1,半径为10,破坏方块,不着火的爆炸; 效果:目标位置半径10范围内所有方块都被爆炸清除,包括本该防爆的方块。

使用代码mc.explode(pos, player, -10, 10, true, false);在目标位置执行一次威力为-10,半径为10,破坏方块,不着火的爆炸; 效果:目标位置爆炸范围远超半径10,客户端非常卡顿。

Expected behavior

按照正常设定的范围和威力产生爆炸效果

Screenshots

No response

Platform

Windows 10

BDS Version

1.20.81

LeviLamina Version

0.12.3

LegacyScriptEngine Version

0.7.7

ShrBox commented 4 months ago

这个API是完全直接调用原版的,我也不知道该咋搞(

ShrBox commented 4 months ago

使用代码mc.explode(pos, player, 1, 10, true, false);在目标位置执行一次威力为1,半径为10,破坏方块,不着火的爆炸; 效果:目标位置半径10范围内所有方块都被爆炸清除,包括本该防爆的方块。

无法复现这种情况

LAppleXGR358 commented 4 months ago

使用代码mc.explode(pos, player, 1, 10, true, false);在目标位置执行一次威力为1,半径为10,破坏方块,不着火的爆炸; 效果:目标位置半径10范围内所有方块都被爆炸清除,包括本该防爆的方块。

无法复现这种情况

测试了一下,这样不会有问题

mc.listen("onJump", (pl) => {
    mc.explode(pl.pos, pl, 1, 5, true, false);
})

这样就会有问题

mc.listen("onProjectileCreated", (shooter, en) => {
   mc.explode(en.pos, shooter, 1, 5, true, false);
})

我的完整代码,作用是箭落地或击中实体则发生爆炸

mc.listen("onProjectileCreated", (shooter, en) => {
    // 12582992为箭的id
    if (en.id == 12582992 &&shooter.isPlayer()) {
        //预存箭坐标
        let pos = en.pos;
        let time2;
        let time;
        //每隔100ms判断是否落地
        time = setInterval(() => {
            //击中实体,箭消失,在预存位置产生爆炸,停止计时
            if (en.name == undefined) {
                mc.explode(pos, shooter, 1, 5, true, false);
                if (time != undefined) clearInterval(time);
                if (time2 != undefined) clearInterval(time2);
            }
            //落地,箭坐标处产生爆炸,停止计时,清除箭
            if (en.isOnGround) {
                mc.explode(en.pos, shooter, 1, 5, true, false);
                if (time != undefined) clearInterval(time);
                if (time2 != undefined) clearInterval(time2);
                en.despawn();
            }
            //末尾将箭坐标存入
            pos = en.pos;
        }, 100)
        //计时,超过10秒没有爆炸则直接在箭预存坐标位置产生爆炸
        time2 = setTimeout(() => {
            if (time != undefined) clearInterval(time);
            mc.explode(pos, shooter, 1, 5, true, false);
        }, 10000)
    }
})
ShrBox commented 2 months ago

使用代码mc.explode(pos, player, 1, 10, true, false);在目标位置执行一次威力为1,半径为10,破坏方块,不着火的爆炸; 效果:目标位置半径10范围内所有方块都被爆炸清除,包括本该防爆的方块。

无法复现这种情况

测试了一下,这样不会有问题

mc.listen("onJump", (pl) => {
    mc.explode(pl.pos, pl, 1, 5, true, false);
})

这样就会有问题

mc.listen("onProjectileCreated", (shooter, en) => {
   mc.explode(en.pos, shooter, 1, 5, true, false);
})

我的完整代码,作用是箭落地或击中实体则发生爆炸

mc.listen("onProjectileCreated", (shooter, en) => {
    // 12582992为箭的id
    if (en.id == 12582992 &&shooter.isPlayer()) {
        //预存箭坐标
        let pos = en.pos;
        let time2;
        let time;
        //每隔100ms判断是否落地
        time = setInterval(() => {
            //击中实体,箭消失,在预存位置产生爆炸,停止计时
            if (en.name == undefined) {
                mc.explode(pos, shooter, 1, 5, true, false);
                if (time != undefined) clearInterval(time);
                if (time2 != undefined) clearInterval(time2);
            }
            //落地,箭坐标处产生爆炸,停止计时,清除箭
            if (en.isOnGround) {
                mc.explode(en.pos, shooter, 1, 5, true, false);
                if (time != undefined) clearInterval(time);
                if (time2 != undefined) clearInterval(time2);
                en.despawn();
            }
            //末尾将箭坐标存入
            pos = en.pos;
        }, 100)
        //计时,超过10秒没有爆炸则直接在箭预存坐标位置产生爆炸
        time2 = setTimeout(() => {
            if (time != undefined) clearInterval(time);
            mc.explode(pos, shooter, 1, 5, true, false);
        }, 10000)
    }
})

偶然阅读了LSE的屎山代码后发现,如果mc.explode中传的是Player的话,由于在提取Player时调用的是EntityClass::extract而不是EntityClass::tryExtractActor,会返回空指针,所以传进Level::explode的是空指针而非实体 所以我认为把箭或者其它本不会爆炸的实体传进Level::explode可能会导致异常情况