mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Move mob head and note instrument save IDs into pocketmine\data\bedrock
to be consistent, these shouldn't be exposed in the API like this... I'm not very happy with the whole 'type ID map' paradigm (particularly its lack of static analysis guarantees), but the most important thing right now is to get this stuff out of the API so that plugin devs don't try and abuse it. We're not going to change the whole system days before PM5 release.
This commit is contained in:
@ -38,28 +38,15 @@ use pocketmine\utils\EnumTrait;
|
||||
* @method static NoteInstrument SNARE()
|
||||
*/
|
||||
final class NoteInstrument{
|
||||
use EnumTrait {
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
use EnumTrait;
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
new self("piano", 0),
|
||||
new self("bass_drum", 1),
|
||||
new self("snare", 2),
|
||||
new self("clicks_and_sticks", 3),
|
||||
new self("double_bass", 4)
|
||||
new self("piano"),
|
||||
new self("bass_drum"),
|
||||
new self("snare"),
|
||||
new self("clicks_and_sticks"),
|
||||
new self("double_bass")
|
||||
);
|
||||
}
|
||||
|
||||
private function __construct(
|
||||
string $name,
|
||||
private int $magicNumber
|
||||
){
|
||||
$this->Enum___construct($name);
|
||||
}
|
||||
|
||||
public function getMagicNumber() : int{
|
||||
return $this->magicNumber;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\sound;
|
||||
|
||||
use pocketmine\data\bedrock\NoteInstrumentIdMap;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
|
||||
@ -38,6 +39,7 @@ class NoteSound implements Sound{
|
||||
}
|
||||
|
||||
public function encode(Vector3 $pos) : array{
|
||||
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::NOTE, $pos, false, ($this->instrument->getMagicNumber() << 8) | $this->note)];
|
||||
$instrumentId = NoteInstrumentIdMap::getInstance()->toId($this->instrument);
|
||||
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::NOTE, $pos, false, ($instrumentId << 8) | $this->note)];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user