From a27c89935d1d11a0982e7e5bbb8b4836aebaeb3c Mon Sep 17 00:00:00 2001 From: Neige <2468629609@qq.com> Date: Mon, 24 Jul 2023 17:26:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8BPlayerUtil.giveItem=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=90=9E=E7=89=A9=E5=93=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/taboolib/platform/util/PlayerUtil.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/platform/platform-bukkit/src/main/kotlin/taboolib/platform/util/PlayerUtil.kt b/platform/platform-bukkit/src/main/kotlin/taboolib/platform/util/PlayerUtil.kt index 1eb7dfca7..41464af14 100644 --- a/platform/platform-bukkit/src/main/kotlin/taboolib/platform/util/PlayerUtil.kt +++ b/platform/platform-bukkit/src/main/kotlin/taboolib/platform/util/PlayerUtil.kt @@ -14,7 +14,12 @@ fun HumanEntity.giveItem(itemStack: List) { fun HumanEntity.giveItem(itemStack: ItemStack?, repeat: Int = 1) { if (itemStack.isNotAir()) { - repeat(repeat) { inventory.addItem(itemStack).values.forEach { world.dropItem(location, it) } } + // CraftInventory.addItem 的执行过程中, 实质上有可能修改ItemStack的amount, 如果不注意这一点, 则会吞物品而不自知 + val preAmount = itemStack.amount + repeat(repeat) { + inventory.addItem(itemStack).values.forEach { world.dropItem(location, it) } + itemStack.amount = preAmount + } } } @@ -48,4 +53,4 @@ fun HumanEntity.feed() { fun HumanEntity.saturate() { saturation = 20F -} \ No newline at end of file +}