Skip to content

[Bug] 长矛破坏盔甲架未进入 onAttackEntity / onMobHurt 监听 #405

Open

Description

@Limo-awa

Describe the bug

使用 Lua 脚本监听 onAttackEntity 和 onMobHurt,尝试阻止玩家对盔甲架造成破坏。
测试发现:

  • 剑攻击盔甲架时,onAttackEntity 正常触发,回调返回 false 可以阻止破坏。
  • 长矛攻击盔甲架时,下面复现代码中的两个盔甲架诊断分支均无日志输出,盔甲架直接被破坏。
  • 目前已知,长矛攻击其他实体可以被阻止,但偏偏攻击盔甲架无法被阻止

To Reproduce

mc.listen("onAttackEntity", function(player, entity)
    if entity == nil or entity.type ~= "minecraft:armor_stand" then
        return
    end

    logger.warn(
        "[ArmorStandTest] onAttackEntity triggered; returning false"
    )

    return false
end)

mc.listen("onMobHurt", function(mob, source, damage, cause)
    if mob == nil or mob.type ~= "minecraft:armor_stand" then
        return
    end

    local sourceType = "nil"
    if source ~= nil then
        sourceType = tostring(source.type)
    end

    logger.warn(
        "[ArmorStandTest] onMobHurt triggered" ..
        "; source=" .. sourceType ..
        "; damage=" .. tostring(damage) ..
        "; cause=" .. tostring(cause) ..
        "; returning false"
    )

    return false
end)
  1. 加载上述 Lua 测试脚本。
  2. 放置一个盔甲架。
  3. 使用剑攻击盔甲架,控制台能输出内容
  4. 使用长矛攻击盔甲架,控制台无法输出内容

Expected behavior

玩家使用长矛攻击盔甲架时,应通过适用的可取消事件通知脚本;脚本返回 false 后,盔甲架不应被该次攻击破坏

Screenshots

Image只有剑可以输出,长矛武器无法输出

Platform

windows10

Version

0.22.2

Additional context

有趣的是,长矛攻击其他实体可以被拦截,偏偏拦截不了盔甲架

Activity

  1. added theissue type on Oct 17, 2026
  2. yangyangzhong82 commented on Oct 17, 2026

    @yangyangzhong82
    Contributor

    发错了 去lse那里反馈

  3. transferred this issue fromLiteLDev/LeviLaminaon Oct 27, 2026
  4. changed the title [-][Bug] [LegacyScriptEngine] 长矛破坏盔甲架未进入 onAttackEntity / onMobHurt 监听[/-] [+][Bug] 长矛破坏盔甲架未进入 onAttackEntity / onMobHurt 监听[/+] on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions