Last active
July 23, 2020 20:11
-
-
Save PJZ9n/6ef7b03f15acd720c1bc512e1d612502 to your computer and use it in GitHub Desktop.
チェストをプレイヤーが操作したことを検知する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function on(InventoryTransactionEvent $event): void | |
{ | |
$tra = $event->getTransaction(); | |
if (count($tra->getActions()) !== 2) { | |
//TODO | |
return; | |
} | |
//プレイヤーの取得 | |
$player = null; | |
foreach ($tra->getActions() as $act) { | |
if ($act instanceof SlotChangeAction) { | |
$inv = $act->getInventory(); | |
if ($inv instanceof PlayerCursorInventory) { | |
$player = $inv->getHolder(); | |
} | |
} | |
} | |
//インベントリから取ったアイテムを取得 | |
if ($player !== null) { | |
foreach ($tra->getActions() as $act) { | |
if ($act instanceof SlotChangeAction) { | |
$inv = $act->getInventory(); | |
if ($inv instanceof ChestInventory) { | |
$chest = $inv->getHolder(); | |
//$chestはChestのTile、つまりPositionのインスタンスだから適当に使ってね(笑) | |
$player->sendMessage("Chest: " . $chest->asPosition()->__toString()); | |
$player->sendMessage("Source: " . $act->getSourceItem()->__toString()); | |
$player->sendMessage("Target: " . $act->getTargetItem()->__toString()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment