Hello. I need help to find how to find the <ID Meta> of a block in a InteractEvent Example with Interact: PHP: public function onInteract(PlayerInteractEvent $e) { $player = $e->getPlayer(); $block = $e->getBlock(); $item = Item::get(0, 0, 1); $i = $e->getItem(); if($block->getId() === 54){ if($i->getCustomName() === "§2§lCub §fCrate Key" && $i->getId() === 131) { $e->setCancelled(); Where it says: PHP: if($block->getId() === 54){ I was wondering if i could get the <ID & Meta>. Hopefully someone has a solution. Please help me. Thanks.
I have a feeling it's like this if I'm correct. PHP: public function onInteract(PlayerInteractEvent $e) { $player = $e->getPlayer(); $block = $e->getBlock(); $item = Item::get(0, 0, 1); $i = $e->getItem(); if($block->getId() === 54) { if($block->getDamage() === 1) { if($i->getCustomName() === "§2§lCub §fCrate Key" && $i->getId() === 131) { $e->setCancelled();
You can do just like this, very simple: PHP: public function onInteract(PlayerInteractEvent $e) { $player = $e->getPlayer(); $block = $e->getBlock(); if($block->getCustomName() === "§2§lCub §fCrate Key" && $block->getId() === 131 && $block->getDamage() === 1) { //whatever you want do to here } } I do not know the reason for executing several 'if' clause, you have to explain if the player interaction in PlayerInteractEvent is clicking on the HotBar or clicking on the map block. What do you really want to do? If you want to detect a block on the ground or floor (map) you should do the variable $block like this: PHP: $block->getBlock(); on the top example that i showed but if you want to detect a block on the hotbar (hand of the player) you should use variable PHP: $block = $player->getInventory()->getItemInHand();
PHP: public function onInteract(PlayerInteractEvent $e) { $player = $e->getPlayer(); $block = $e->getBlock(); if($block->getId() === 54) { $player->sendMessage("Damage from that chest you tapped: ".$block->getDamage()); } }
I want to get the damage of The chest A.K.A "54" so I don't have to use the same chest for multiple crate keys. I want multiple chest and each key has its designated chest.