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]: clearItem方法在特定情况下不生效 #140

Closed daisukiKaffuChino closed 3 months ago

daisukiKaffuChino commented 3 months ago

Describe the bug

在 onInventoryChange 的回调方法中,使用 player.clearItem() 方法始终返回0,无法正确清除指定物品。 在 onServerStarted 等其他事件的回调中则正常。

To Reproduce

mc.listen("onInventoryChange", function(player, slotNum, oldItem, newItem)
    count = player:clearItem(newItem.type, 64)
    logger.info(count)
end)

Expected behavior

正确返回不为0的数量

Screenshots

No response

Platform

Windows 11

BDS Version

1.12.81

LeviLamina Version

0.12.3

LegacyScriptEngine Version

0.7.12

Additional context

No response

ShrBox commented 3 months ago

onInventoryChange被触发时,newItem还没有被添加到玩家的背包中,所以不可能通过clearItem进行清除 建议使用setTimeout对clearItem操作进行延后