isAbstract()){ self::$knownTiles[$class->getShortName()] = $className; self::$shortNames[$className] = $class->getShortName(); return true; } return false; } /** * Returns the short save name * * @return string */ public function getSaveId(){ return self::$shortNames[static::class]; } public function __construct(Level $level, CompoundTag $nbt){ $this->timings = Timings::getTileEntityTimings($this); $this->namedtag = $nbt; $this->server = $level->getServer(); $this->setLevel($level); $this->chunk = $level->getChunk($this->namedtag["x"] >> 4, $this->namedtag["z"] >> 4, false); assert($this->chunk !== null); $this->name = ""; $this->lastUpdate = microtime(true); $this->id = Tile::$tileCount++; $this->x = (int) $this->namedtag["x"]; $this->y = (int) $this->namedtag["y"]; $this->z = (int) $this->namedtag["z"]; $this->chunk->addTile($this); $this->getLevel()->addTile($this); $this->tickTimer = Timings::getTileEntityTimings($this); } public function getId(){ return $this->id; } public function saveNBT(){ $this->namedtag->id = new StringTag("id", $this->getSaveId()); $this->namedtag->x = new IntTag("x", $this->x); $this->namedtag->y = new IntTag("y", $this->y); $this->namedtag->z = new IntTag("z", $this->z); } public function getCleanedNBT(){ $this->saveNBT(); $tag = clone $this->namedtag; unset($tag->x, $tag->y, $tag->z, $tag->id); if($tag->getCount() > 0){ return $tag; }else{ return null; } } /** * @return \pocketmine\block\Block */ public function getBlock(){ return $this->level->getBlock($this); } public function onUpdate(){ return false; } final public function scheduleUpdate(){ $this->level->updateTiles[$this->id] = $this; } public function __destruct(){ $this->close(); } public function close(){ if(!$this->closed){ $this->closed = true; unset($this->level->updateTiles[$this->id]); if($this->chunk instanceof Chunk){ $this->chunk->removeTile($this); $this->chunk = null; } if(($level = $this->getLevel()) instanceof Level){ $level->removeTile($this); $this->setLevel(null); } $this->namedtag = null; } } public function getName(){ return $this->name; } }