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.

66 lines
2.1 KiB

  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\IntTag;
  16. use Ad5001\BetterBlocks\CustomBlockData;
  17. class VacuumTile extends CustomBlockData {
  18. public function __construct(Chunk $chunk, CompoundTag $nbt){
  19. if(!isset($nbt->AttractRadius)) $nbt->AttractRadius = new IntTag("AttractRadius", 5);
  20. parent::__construct($chunk, $nbt);
  21. }
  22. /*
  23. Sets the attracting radius of the vacuum hopper
  24. @param $radius int
  25. */
  26. public function setAttractRadius(int $radius) {
  27. $this->namedtag->AttractRadius->setValue($radius);
  28. return $this;
  29. }
  30. /*
  31. Get the radius of attractivity of the Vacuum Hopper.
  32. @return int
  33. */
  34. public function getAttractRadius() : int {
  35. return (int) $this->namedtag->AttractRadius->getValue();
  36. }
  37. /*
  38. Attracts all blocks in the defined radius.
  39. */
  40. public function attract() {
  41. foreach ($this->getLevel()->getEntities() as $et) {
  42. if($et->x < $this->x + $this->namedtag->AttractRadius->getValue() && $et->x > $this->x - $this->namedtag->AttractRadius->getValue() &&
  43. $et->y < $this->y + $this->namedtag->AttractRadius->getValue() && $et->y > $this->y - $this->namedtag->AttractRadius->getValue() &&
  44. $et->z < $this->z + $this->namedtag->AttractRadius->getValue() && $et->z > $this->z - $this->namedtag->AttractRadius->getValue()) {
  45. $et->teleport(new Vector3($this->x, $this->y + 1, $this->z));
  46. }
  47. }
  48. }
  49. }