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() : string{ 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->getValue() >> 4, $this->namedtag->z->getValue() >> 4, false); assert($this->chunk !== null); $this->name = ""; $this->lastUpdate = microtime(true); $this->id = Tile::$tileCount++; $this->x = $this->namedtag->x->getValue(); $this->y = $this->namedtag->y->getValue(); $this->z = $this->namedtag->z->getValue(); $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->setValue($this->getSaveId()); $this->namedtag->x->setValue($this->x); $this->namedtag->y->setValue($this->y); $this->namedtag->z->setValue($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 Block */ public function getBlock() : Block{ return $this->level->getBlock($this); } /** * @return bool */ public function onUpdate() : bool{ return false; } final public function scheduleUpdate(){ $this->level->updateTiles[$this->id] = $this; } public function isClosed() : bool{ return $this->closed; } 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; } }