The same blocks, simply better. For PocketMine & forks.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SoundHolderTile.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. # ____ _ _ ____ _ _
  3. # | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
  4. # | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
  5. # | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
  6. # |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
  7. #
  8. # Extends your Minecraft PE blocks palette ! For PocketMine.
  9. namespace Ad5001\BetterBlocks\CustomBlockData;
  10. use pocketmine\Server;
  11. use pocketmine\Player;
  12. use pocketmine\level\format\Chunk;
  13. use pocketmine\nbt\tag\CompoundTag;
  14. use pocketmine\nbt\tag\StringTag;
  15. use Ad5001\BetterBlocks\Main;
  16. use Ad5001\BetterBlocks\CustomBlockData;
  17. class SoundHolderTile extends CustomBlockData {
  18. const SOUNDS = [
  19. "AnvilFallSound",
  20. "AnvilUseSound",
  21. "BatSound",
  22. "BlazeShootSound",
  23. "ClickSound",
  24. "DoorBumpSound",
  25. "DoorCrashSound",
  26. "EndermanTeleportSound",
  27. "FizzSound",
  28. "GhastShootSound",
  29. "GhastSound",
  30. "LaunchSound",
  31. "PopSound",
  32. "ZombieHealSound",
  33. "ZombieInfectSound"
  34. ];
  35. public function __construct(Chunk $chunk, CompoundTag $nbt){
  36. if(!isset($nbt->Sound)) $nbt->Sound = new StringTag("Sound", self::SOUNDS[rand(0, count(self::SOUNDS) - 1)]); // TODO: Customize the sound
  37. parent::__construct($chunk, $nbt);
  38. }
  39. /*
  40. Sets the sound of the Block
  41. @param $sound string
  42. @return bool
  43. */
  44. public function setSound(string $sound) : bool {
  45. if(in_array($sound, self::SOUNDS)) {
  46. $this->namedtag->Sound->setValue($sound);
  47. return true;
  48. }
  49. return false;;
  50. }
  51. /*
  52. Gets the current used sound
  53. @return string
  54. */
  55. public function getSound() : string {
  56. return $this->namedtag->Sound->getValue();
  57. }
  58. /*
  59. Plays the sound
  60. */
  61. public function play() {
  62. $s = "\\pocketmine\\level\\sound\\" . $this->namedtag->Sound->getValue();
  63. $this->getLevel()->addSound(new $s($this));
  64. }
  65. }