From fea4de802717bfbe9ac176be87a1c0292038c1ef Mon Sep 17 00:00:00 2001 From: "Taylor.R" Date: Mon, 15 May 2023 20:54:42 +0700 Subject: [PATCH] The amount of TNT will gradually decrease when the player uses it in survival mode --- src/Vecnavium/LaunchableTNT/LaunchableTNT.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Vecnavium/LaunchableTNT/LaunchableTNT.php b/src/Vecnavium/LaunchableTNT/LaunchableTNT.php index a256f03..b5d026c 100644 --- a/src/Vecnavium/LaunchableTNT/LaunchableTNT.php +++ b/src/Vecnavium/LaunchableTNT/LaunchableTNT.php @@ -43,7 +43,12 @@ public function onExplode(EntityExplodeEvent $event): void public function onClick(PlayerItemUseEvent $event): void { $player = $event->getPlayer(); - if ($player->getInventory()->getItemInHand()->getId() === ItemIds::TNT) { + $item = $player->getInventory()->getItemInHand(); + if ($item->getId() === ItemIds::TNT) { + if ($player->isSurvival()) { + $item->setCount($item->getCount() - 1); + $player->getInventory()->setItemInHand($item); + } $entity = new PrimedTNT($player->getLocation(), self::createBaseNBT($player->getPosition())); $entity->setMotion($player->getDirectionVector()->normalize()->multiply(2)); $entity->spawnToAll();