Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PM5 #7

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: LaunchableTNT
api: 4.0.0
api: 5.0.0
main: Vecnavium\LaunchableTNT\LaunchableTNT
version: 1.0.2
author: Vecnavium
Expand Down
50 changes: 9 additions & 41 deletions src/Vecnavium/LaunchableTNT/LaunchableTNT.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

namespace Vecnavium\LaunchableTNT;

use pocketmine\block\TNT;
use pocketmine\entity\Location;
use pocketmine\plugin\PluginBase;
use pocketmine\event\player\PlayerItemUseEvent;
use pocketmine\entity\Entity;
use pocketmine\item\ItemIds;
use pocketmine\math\Vector3;
use pocketmine\event\Listener;
use pocketmine\event\entity\EntityExplodeEvent;
use pocketmine\entity\object\PrimedTNT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\world\Position;

class LaunchableTNT extends PluginBase implements Listener{

Expand All @@ -28,43 +21,18 @@ public function checkUpdate(bool $isRetry = false): void {
$this->getServer()->getAsyncPool()->submitTask(new CheckUpdateTask($this->getDescription()->getName(), $this->getDescription()->getVersion()));
}


public function onExplode(EntityExplodeEvent $event): void
{
foreach ($event->getBlockList() as $block) {
if ($block->isSolid()) {
$nbt = self::createBaseNBT($block->getPosition());
$nbt->setInt("TileID", $block->getId());
$nbt->setByte("Data", $block->getMeta());
}
}
}

public function onClick(PlayerItemUseEvent $event): void
{
$player = $event->getPlayer();
if ($player->getInventory()->getItemInHand()->getId() === ItemIds::TNT) {
$entity = new PrimedTNT($player->getLocation(), self::createBaseNBT($player->getPosition()));
$item = $player->getInventory()->getItemInHand();
if ($item->getBlock() instanceof TNT) {
if ($player->isSurvival()) {
$item->pop();
$player->getInventory()->setItemInHand($item);
}
$entity = new PrimedTNT(Location::fromObject($player->getPosition()->asVector3(), $player->getWorld()));
$entity->setMotion($player->getDirectionVector()->normalize()->multiply(2));
$entity->spawnToAll();
}
}

private static function createBaseNBT(Position $pos, ?Vector3 $motion = null, float $yaw = 0.0, float $pitch = 0.0): CompoundTag {
return CompoundTag::create()
->setTag("Pos", new ListTag([
new DoubleTag($pos->x),
new DoubleTag($pos->y),
new DoubleTag($pos->z)
]))
->setTag("Motion", new ListTag([
new DoubleTag($motion !== null ? $motion->x : 0.0),
new DoubleTag($motion !== null ? $motion->y : 0.0),
new DoubleTag($motion !== null ? $motion->z : 0.0)
]))
->setTag("Rotation", new ListTag([
new FloatTag($yaw),
new FloatTag($pitch)
]));
}
}