record !== null){ $this->ejectRecord(); }elseif($item instanceof Record){ $player->sendJukeboxPopup("record.nowPlaying", [$player->getLanguage()->translate($item->getRecordType()->getTranslatableName())]); $this->insertRecord($item->pop()); } } $this->position->getWorld()->setBlock($this->position, $this); return true; } public function getRecord() : ?Record{ return $this->record; } public function ejectRecord() : void{ if($this->record !== null){ $this->getPosition()->getWorld()->dropItem($this->getPosition()->add(0.5, 1, 0.5), $this->record); $this->record = null; $this->stopSound(); } } public function insertRecord(Record $record) : void{ if($this->record === null){ $this->record = $record; $this->startSound(); } } public function startSound() : void{ if($this->record !== null){ $this->getPosition()->getWorld()->addSound($this->getPosition(), new RecordSound($this->record->getRecordType())); } } public function stopSound() : void{ $this->getPosition()->getWorld()->addSound($this->getPosition(), new RecordStopSound()); } public function onBreak(Item $item, ?Player $player = null) : bool{ $this->stopSound(); return parent::onBreak($item, $player); } public function getDropsForCompatibleTool(Item $item) : array{ $drops = parent::getDropsForCompatibleTool($item); if($this->record !== null){ $drops[] = $this->record; } return $drops; } public function readStateFromWorld() : void{ parent::readStateFromWorld(); $jukebox = $this->position->getWorld()->getTile($this->position); if($jukebox instanceof JukeboxTile){ $this->record = $jukebox->getRecord(); } } public function writeStateToWorld() : void{ parent::writeStateToWorld(); $jukebox = $this->position->getWorld()->getTile($this->position); if($jukebox instanceof JukeboxTile){ $jukebox->setRecord($this->record); } } //TODO: Jukebox has redstone effects, they are not implemented. }