Separate names with a comma.
Comments in 'Plugin Development' started by Svile, Apr 7, 2016.
how can i get the block the player is looking at , having the yaw and pitch ? thanks
You are not really answering the question. How can you use getDirectionVector() to get the position?
Entity::getDirectionVector() returns a normalized vector, which is the distance from the entity to one meter in front of the entity with respect to the entity's rotation. In other words, using $entity->add($entity->getDirectionVector()) returns one block in front of the player. However, you have to count it block by block, and sometimes you would miss some blocks.
PocketMine has a class called BlockIterator, which can help in this case. However, the most straightforward way is to use Living::getTargetBlock(). You can use $Living->getTargetBlock($maxDist, $transparent) to get the block that the player is looking at. $maxDist is the maximum distance to search for - if there are no non-transparent blocks found within $maxDist at the player's direction, the player is considered as not looking at any blcoks, and the function will return null. $transparent is an array of block IDs in the keys, with arbitrary value. For example, you can pass [0 => true, 8 => true, 9 => true, 10 => true, 11 => true] as $transparent, so PocketMine will consider blocks with ID 0, 8, 9, 10 or 11 as transparent. If you don't pass the $transparent parameter, or pass an empty array, only air blocks are considered as transparent
wonderful answer, thanks
When a question is interesting, it deserves more attention and more effort for answering. (unlike those that have been asked for tens of times on the forums; they don't help future readers at all because they are duplicated) (I think this is duplicated too, but I can't find the duplicated link)