diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c3d4b1ece..a56d9469b 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2910,7 +2910,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } - $tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z)); + $tile = $this->level->getTileAt($packet->x, $packet->y, $packet->z); if($tile instanceof ItemFrame){ $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), null, 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK); $this->server->getPluginManager()->callEvent($ev); diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 604eba574..7bc6d53e0 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -211,7 +211,7 @@ class Explosion{ $this->level->setBlockIdAt($block->x, $block->y, $block->z, 0); - $t = $this->level->getTile($block); + $t = $this->level->getTileAt($block->x, $block->y, $block->z); if($t instanceof Tile){ if($yieldDrops and $t instanceof Container){ if($t instanceof Chest){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 1db236ca1..47a029651 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1962,17 +1962,33 @@ class Level implements ChunkManager, Metadatable{ } /** - * Returns the Tile in a position, or null if not found + * Returns the Tile in a position, or null if not found. + * + * Note: This method wraps getTileAt(). If you're guaranteed to be passing integers, and you're using this method + * in performance-sensitive code, consider using getTileAt() instead of this method for better performance. * * @param Vector3 $pos * * @return Tile|null */ - public function getTile(Vector3 $pos){ - $chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, false); + public function getTile(Vector3 $pos) : ?Tile{ + return $this->getTileAt((int) floor($pos->x), (int) floor($pos->y), (int) floor($pos->z)); + } + + /** + * Returns the tile at the specified x,y,z coordinates, or null if it does not exist. + * + * @param int $x + * @param int $y + * @param int $z + * + * @return Tile|null + */ + public function getTileAt(int $x, int $y, int $z) : ?Tile{ + $chunk = $this->getChunk($x >> 4, $z >> 4); if($chunk !== null){ - return $chunk->getTile($pos->x & 0x0f, $pos->y, $pos->z & 0x0f); + return $chunk->getTile($x & 0x0f, $y, $z & 0x0f); } return null; diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index a902a9dcc..8f2a01a3b 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -136,7 +136,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ */ public function getPair() : ?Chest{ if($this->isPaired()){ - $tile = $this->getLevel()->getTile(new Vector3($this->namedtag->getInt(self::TAG_PAIRX), $this->y, $this->namedtag->getInt(self::TAG_PAIRZ))); + $tile = $this->getLevel()->getTileAt($this->namedtag->getInt(self::TAG_PAIRX), $this->y, $this->namedtag->getInt(self::TAG_PAIRZ)); if($tile instanceof Chest){ return $tile; }