Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Created December 4, 2020 21:21
Show Gist options
  • Save PJZ9n/3c4a77285b7dbbbbf19f76649d2af739 to your computer and use it in GitHub Desktop.
Save PJZ9n/3c4a77285b7dbbbbf19f76649d2af739 to your computer and use it in GitHub Desktop.
見ているブロックを取得する
<?php
/**
* @name TargetBlock
* @version 1.0.0
* @main pjz9n\test\targetblock\Main
* @api 3.0.0
*/
declare(strict_types=1);
namespace pjz9n\test\targetblock;
use pocketmine\plugin\PluginBase;
use pocketmine\scheduler\ClosureTask;
use pocketmine\Server;
class Main extends PluginBase
{
public function onEnable(): void
{
$this->getScheduler()->scheduleRepeatingTask(new ClosureTask(function (int $currentTick): void {
foreach (Server::getInstance()->getOnlinePlayers() as $player) {
$block = $player->getTargetBlock($player->getViewDistance());
if ($block === null) {
$player->sendMessage("TargetBlock: null");
} else {
$player->sendMessage("TargetBlock: " . $block->__toString() . " " . $block->asPosition()->__toString());
}
}
}), 5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment