Added Level->getTileAt()

This commit is contained in:
Dylan K. Taylor 2017-10-30 13:36:42 +00:00
parent 93443992be
commit 91c256f1a9
4 changed files with 23 additions and 7 deletions

View File

@ -2910,7 +2910,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return true; 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){ if($tile instanceof ItemFrame){
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), null, 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK); $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), null, 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK);
$this->server->getPluginManager()->callEvent($ev); $this->server->getPluginManager()->callEvent($ev);

View File

@ -211,7 +211,7 @@ class Explosion{
$this->level->setBlockIdAt($block->x, $block->y, $block->z, 0); $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($t instanceof Tile){
if($yieldDrops and $t instanceof Container){ if($yieldDrops and $t instanceof Container){
if($t instanceof Chest){ if($t instanceof Chest){

View File

@ -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 * @param Vector3 $pos
* *
* @return Tile|null * @return Tile|null
*/ */
public function getTile(Vector3 $pos){ public function getTile(Vector3 $pos) : ?Tile{
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, false); 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){ if($chunk !== null){
return $chunk->getTile($pos->x & 0x0f, $pos->y, $pos->z & 0x0f); return $chunk->getTile($x & 0x0f, $y, $z & 0x0f);
} }
return null; return null;

View File

@ -136,7 +136,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
*/ */
public function getPair() : ?Chest{ public function getPair() : ?Chest{
if($this->isPaired()){ 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){ if($tile instanceof Chest){
return $tile; return $tile;
} }