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.

FallableTile.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\math\Vector3;
  15. use pocketmine\nbt\tag\StringTag;
  16. use pocketmine\nbt\tag\DoubleTag;
  17. use pocketmine\nbt\tag\ListTag;
  18. use pocketmine\nbt\tag\IntTag;
  19. use pocketmine\nbt\tag\ByteTag;
  20. use pocketmine\nbt\tag\FloatTag;
  21. use Ad5001\BetterBlocks\CustomBlockData;
  22. class FallableTile extends CustomBlockData {
  23. public function __construct(Chunk $chunk, CompoundTag $nbt){
  24. if(!isset($nbt->Fallable)) $nbt->Fallable = new StringTag("Fallable", "true");
  25. parent::__construct($chunk, $nbt);
  26. }
  27. /*
  28. Sets if the block can fall when a player walks on it.
  29. @param $fallable bool
  30. */
  31. public function setFallable(bool $fallable) {
  32. if($fallable) {
  33. $this->namedtag->Fallable->setValue("true");
  34. } else {
  35. $this->namedtag->Fallable->setValue("false");
  36. }
  37. return $this;
  38. }
  39. /*
  40. Check if the block is fallable.
  41. @return bool
  42. */
  43. public function isFallable() : bool {
  44. if($this->namedtag->Fallable->getValue() == "false") {
  45. return false;
  46. }
  47. return true;
  48. }
  49. /*
  50. Makes the block fall
  51. */
  52. public function fall() {
  53. if($this->level->getBlock($this->getSide(Vector3::SIDE_DOWN))->getId() == 0 || $this->level->getBlock($this->getSide(Vector3::SIDE_DOWN)) instanceof \pocketmine\block\Liquid) {
  54. $fall = \pocketmine\entity\Entity::createEntity("FallingSand", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new CompoundTag("", [
  55. "Pos" => new ListTag("Pos", [
  56. new DoubleTag("", $this->x + 0.5),
  57. new DoubleTag("", $this->y),
  58. new DoubleTag("", $this->z + 0.5)
  59. ]),
  60. "Motion" => new ListTag("Motion", [
  61. new DoubleTag("", 0),
  62. new DoubleTag("", 0),
  63. new DoubleTag("", 0)
  64. ]),
  65. "Rotation" => new ListTag("Rotation", [
  66. new FloatTag("", 0),
  67. new FloatTag("", 0)
  68. ]),
  69. "TileID" => new IntTag("TileID", $this->getBlock()->getId()),
  70. "Data" => new ByteTag("Data", $this->getBlock()->getDamage()),
  71. ]))->spawnToAll();
  72. // $this->getLevel()->setBlock($this, Block::get(0, 0));
  73. }
  74. }
  75. }