Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.31 KB | None | 0 0
  1. <?php
  2. namespace mysterybox\entity;
  3.  
  4. /**
  5.  * MysteryBox: Advanced and customisable crates plugin for PMMP
  6.  * CopyRight (C)  2018 CubePM (TheAz928)
  7.  *
  8.  * This program is free software: you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation, either version 3 of the License, or
  11.  * any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20.  */
  21.  
  22. use pocketmine\Player;
  23.  
  24. use pocketmine\entity\Entity;
  25.  
  26. use pocketmine\math\Vector3;
  27.  
  28. use pocketmine\level\particle\LavaParticle;
  29. use pocketmine\level\particle\HugeExplodeSeedParticle;
  30. use pocketmine\level\particle\FloatingTextParticle;
  31.  
  32. use pocketmine\event\entity\EntityDamageEvent;
  33.  
  34. use pocketmine\level\sound\FizzSound;
  35.  
  36. use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
  37. use pocketmine\network\mcpe\protocol\AddItemEntityPacket;
  38. use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
  39.  
  40. use mysterybox\tile\MysteryTile;
  41.  
  42. use mysterybox\MysteryBox;
  43.  
  44. class MysterySkull extends Entity{
  45.    
  46.     public const NETWORK_ID = Entity::WITHER_SKULL;
  47.    
  48.     /** @var float */
  49.     public $height = 0.4;
  50.    
  51.     /** @var float */
  52.     public $width = 0.4;
  53.    
  54.     /** @var MysteryTile */
  55.     protected $tile;
  56.    
  57.     /** @var MysteryBox */
  58.     protected $mysterybox;
  59.    
  60.     /** @var Player */
  61.     protected $player;
  62.        
  63.     /* @var float */
  64.     protected $max_y = 5;
  65.    
  66.     /** @var int */
  67.     protected $stay_time = 0;
  68.    
  69.     /** @var FloatingTextParticle */
  70.     protected $ftp;
  71.    
  72.     /** @var int */
  73.     protected $item_eid = -1;
  74.    
  75.     /**
  76.      * @param Player $player
  77.      * @param MysteryTile $tile
  78.      * @param MysteryBox $mysterybox
  79.      */
  80.    
  81.     public function __construct(Player $player, MysteryTile $tile, MysteryBox $mysterybox){
  82.         $this->tile = $tile;
  83.         $this->mysterybox = $mysterybox;
  84.         $this->player = $player;
  85.        
  86.         parent::__construct($tile->getLevel(), self::createBaseNBT($tile->asVector3()->add(0.5, 0, 0.5)));
  87.     }
  88.    
  89.     /**
  90.      * @param void
  91.      */
  92.  
  93.     protected function applyGravity() : void{
  94.    
  95.     }
  96.    
  97.     /**
  98.      * @param EntityDamageEvent $source
  99.      */
  100.    
  101.     public function attack(EntityDamageEvent $source) : void{
  102.         $source->setCancelled();
  103.        
  104.     }
  105.    
  106.     /**
  107.      * @param int $diff
  108.      *
  109.      * @return bool
  110.      */
  111.    
  112.     public function entityBaseTick(int $diff = 1) : bool{
  113.         $return = parent:: entityBaseTick($diff);
  114.        
  115.         if($this->tile->isClosed() or $this->player->isClosed()){
  116.             $this->flagForDespawn();
  117.            
  118.             if($this->tile->isClosed() == false){
  119.                 $this->tile->in_use = false;
  120.             }
  121.            
  122.             if($this->item_eid !== -1){
  123.                 $pk = new RemoveEntityPacket;
  124.                 $pk->entityUniqueId = $this->item_eid;
  125.                
  126.                 $this->getLevel()->addChunkPacket($this->x >> 4, $this->z >> 4, $pk);
  127.             }
  128.            
  129.             if($this->ftp !== null){
  130.                 $this->ftp->setInvisible(true);
  131.                
  132.                 foreach($this->ftp->encode() as $pk){
  133.                     $this->getLevel()->addChunkPacket($this->x >> 4, $this->z >> 4, $pk);
  134.                 }
  135.             }
  136.            
  137.             return true;
  138.         }
  139.        
  140.         $this->getLevel()->addSound(new FizzSound($this->asVector3()));
  141.        
  142.         if($this->max_y > 0 and $this->stay_time == 0){
  143.             $this->motion->y = 0.05;
  144.             $this->max_y -= 0.1;
  145.         }else{
  146.             if($this->motion->y > 0){
  147.                 $this->motion->y = 0;
  148.             }
  149.            
  150.             $this->stay_time++;
  151.         }
  152.        
  153.         $this->getLevel()->addParticle(new LavaParticle($this->asVector3()));
  154.        
  155.         if($this->stay_time >= 60){
  156.             $this->motion->y = -0.05;
  157.             $this->max_y  += 0.1;
  158.            
  159.             if($this->max_y == 5){
  160.                 $this->flagForDespawn();
  161.                 $this->mysterybox->displayAnimation($this->tile, false);
  162.                
  163.                 $this->ftp->setInvisible(true);
  164.                
  165.                 if($this->item_eid !== -1){
  166.                     $pk = new RemoveEntityPacket;
  167.                     $pk->entityUniqueId = $this->item_eid;
  168.                
  169.                     $this->getLevel()->addChunkPacket($this->x >> 4, $this->z >> 4, $pk);
  170.                 }
  171.                
  172.                 foreach($this->ftp->encode() as $pk){
  173.                     $this->getLevel()->addChunkPacket($this->x >> 4, $this->z >> 4, $pk);
  174.                 }
  175.                
  176.                 $this->tile->in_use = false;
  177.             }
  178.         }elseif($this->stay_time == 1){
  179.             $data = $this->mysterybox->grantItem($this->player);
  180.            
  181.             $this->getLevel()->addParticle(new HugeExplodeSeedParticle($this->asVector3()));
  182.            
  183.             $this->ftp = new FloatingTextParticle($this->tile->add(0.5, 1, 0.5), $data[1]);
  184.            
  185.             $this->getLevel()->addParticle($this->ftp);
  186.             $this->getLevel()->broadcastLevelSoundEvent($this->asVector3(), LevelSoundEventPacket::SOUND_PORTAL_TRAVEL);
  187.            
  188.             $this->item_eid = Entity::$entityCount++;
  189.            
  190.             $pk->entityRuntimeId = $this->item_eid;
  191.             $pk->item = $data[0];
  192.             $pk->position = $this->ftp->asVector3();
  193.            
  194.             $this->getLevel()->addChunkPacket($this->x >> 4, $this->z >> 4, $pk);
  195.         }
  196.        
  197.         if($this->yaw > 360){
  198.             $this->yaw = 0;
  199.         }else{
  200.             $this->yaw += 15;
  201.         }
  202.      
  203.         return $return;
  204.     }
  205.    
  206.     /**
  207.      * @return bool
  208.      */
  209.    
  210.     public function canSaveWithChunk() : bool{
  211.         return false;
  212.     }
  213.    
  214.     /**
  215.      * @param void
  216.      */
  217.    
  218.     public function close() : void{
  219.         parent::close();
  220.        
  221.         if(is_null($this->tile) == false){
  222.             $this->tile->in_use = false;
  223.         }
  224.     }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement