PocketMine-MP
5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
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
22
declare(strict_types=1);
23
24
namespace
pocketmine\block\tile
;
25
26
use
pocketmine\item\Item
;
27
use
pocketmine\item\Record
;
28
use
pocketmine\nbt\tag\CompoundTag
;
29
use
pocketmine\network\mcpe\convert\TypeConverter
;
30
use
pocketmine\world\sound\RecordStopSound
;
31
32
class
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
}
pocketmine\block\tile\Jukebox
Definition
tile/Jukebox.php:32
pocketmine\block\tile\Jukebox\writeSaveData
writeSaveData(CompoundTag $nbt)
Definition
tile/Jukebox.php:54
pocketmine\block\tile\Jukebox\addAdditionalSpawnData
addAdditionalSpawnData(CompoundTag $nbt)
Definition
tile/Jukebox.php:60
pocketmine\block\tile\Jukebox\onBlockDestroyedHook
onBlockDestroyedHook()
Definition
tile/Jukebox.php:67
pocketmine\block\tile\Spawnable
Definition
Spawnable.php:34
pocketmine\item\Item
Definition
Item.php:60
pocketmine\item\Record
Definition
Record.php:28
pocketmine\nbt\tag\CompoundTag
Definition
CompoundTag.php:42
pocketmine\nbt\tag\CompoundTag\getCompoundTag
getCompoundTag(string $name)
Definition
CompoundTag.php:104
pocketmine\nbt\tag\CompoundTag\setTag
setTag(string $name, Tag $tag)
Definition
CompoundTag.php:117
pocketmine\network\mcpe\convert\TypeConverter
Definition
TypeConverter.php:56
pocketmine\world\sound\RecordStopSound
Definition
RecordStopSound.php:30
pocketmine\block\tile
Definition
block/tile/Banner.php:24
src
block
tile
Jukebox.php
Generated by
1.12.0