Advertisement
TungstenVn

MadSwing save tạm bợ

May 5th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tungsten\MadSwing\chair;
  4.  
  5. use pocketmine\entity\Human;
  6.  
  7. use pocketmine\level\Level;
  8. use pocketmine\nbt\tag\CompoundTag;
  9.  
  10. class Chair extends Human{
  11.     /** @var Entity $player */
  12.     public $player = "";
  13.     public $timer = 10;
  14.     public function __construct(Level $level,CompoundTag $nbt){
  15.         parent::__construct($level,$nbt);
  16.     }
  17.     public function entityBaseTick(int $tickDiff = 20) : bool{     
  18.           // $this->yaw = 0;
  19.           // $this->pitch = 0;
  20.           return true;
  21.           $this->timer -= 1;
  22.           if($this->timer <= -10){
  23.             $this->timer = 10;
  24.           }
  25.           if($this->timer <= -5){
  26.             $this->motion->x = 1;
  27.             $this->motion->y = -1;
  28.             var_dump("4");
  29.             #-5,-6,-7,-8,-9
  30.           }else if($this->timer <= 0){
  31.             $this->motion->x = -1;
  32.             $this->motion->y = 1;
  33.             var_dump("3");
  34.             #0,-1,-2,-3,-4
  35.           }else if($this->timer <= 5){
  36.              $this->motion->x = -1;
  37.              $this->motion->y = -1;
  38.              var_dump("2");
  39.              #5,4,3,2,1
  40.           }else if($this->timer > 5){
  41.              $this->motion->x = 1;
  42.              $this->motion->y = 1;
  43.              #10,9,8,7,6
  44.              var_dump("1");
  45.           }
  46.           $this->updateMovement();
  47.           return true;
  48.     }
  49.     public function follow($target, float $xOffset = 0.0, float $yOffset = 0.0, float $zOffset = 0.0): void {
  50.         $x = $target->x + $xOffset - $this->x;
  51.         $y = $target->y + $yOffset - $this->y;
  52.         $z = $target->z + $zOffset - $this->z;
  53.  
  54.         $xz_sq = $x * $x + $z * $z;
  55.         $xz_modulus = sqrt($xz_sq);
  56.  
  57.         if($xz_sq < 1) {
  58.             $this->motion->x = 0;
  59.             $this->motion->z = 0;
  60.         } else{
  61.             $speed_factor = 1 * 0.15;
  62.             $this->motion->x = $speed_factor * ($x / $xz_modulus);
  63.             $this->motion->z = $speed_factor * ($z / $xz_modulus);
  64.         }
  65.         $this->yaw = rad2deg(atan2(-$x, $z));
  66.         $this->pitch = rad2deg(-atan2($y, $xz_modulus));
  67.  
  68.         $this->move($this->motion->x, $this->motion->y, $this->motion->z);
  69.     }
  70.    
  71.     public function getName(): string{
  72.                 return "Chair";
  73.     }
  74.    
  75.     public function getShortName() :string{
  76.         return "Chair";
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement