PocketMine-MP 5.15.1 git-ed158f8a1b0cfe334ac5f45febc0f633602014f2
tile/Jukebox.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block\tile;
25
31
32class Jukebox extends Spawnable{
33 private const TAG_RECORD = "RecordItem"; //Item CompoundTag
34
35 private ?Record $record = null;
36
37 public function getRecord() : ?Record{
38 return $this->record;
39 }
40
41 public function setRecord(?Record $record) : void{
42 $this->record = $record;
43 }
44
45 public function readSaveData(CompoundTag $nbt) : void{
46 if(($tag = $nbt->getCompoundTag(self::TAG_RECORD)) !== null){
47 $record = Item::nbtDeserialize($tag);
48 if($record instanceof Record){
49 $this->record = $record;
50 }
51 }
52 }
53
54 protected function writeSaveData(CompoundTag $nbt) : void{
55 if($this->record !== null){
56 $nbt->setTag(self::TAG_RECORD, $this->record->nbtSerialize());
57 }
58 }
59
60 protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
61 //this is needed for the note particles to show on the client side
62 if($this->record !== null){
63 $nbt->setTag(self::TAG_RECORD, TypeConverter::getInstance()->getItemTranslator()->toNetworkNbt($this->record));
64 }
65 }
66
67 protected function onBlockDestroyedHook() : void{
68 $this->position->getWorld()->addSound($this->position, new RecordStopSound());
69 }
70}
writeSaveData(CompoundTag $nbt)
addAdditionalSpawnData(CompoundTag $nbt)
static nbtDeserialize(CompoundTag $tag)
Definition: Item.php:740
setTag(string $name, Tag $tag)