Advertisement
PEMapModder

Untitled

Apr 13th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.01 KB | None | 0 0
  1. <?php
  2.  
  3. namespace legionpe\utils;
  4.  
  5. use legionpe\LegionPE;
  6. use legionpe\session\Session;
  7. use pocketmine\entity\Human;
  8. use pocketmine\event\entity\EntityDamageByEntityEvent;
  9. use pocketmine\event\entity\EntityDamageEvent;
  10. use pocketmine\inventory\PlayerInventory;
  11. use pocketmine\level\format\FullChunk;
  12. use pocketmine\level\Location;
  13. use pocketmine\nbt\tag\Byte;
  14. use pocketmine\nbt\tag\Compound;
  15. use pocketmine\nbt\tag\Double;
  16. use pocketmine\nbt\tag\Enum;
  17. use pocketmine\nbt\tag\Float;
  18. use pocketmine\nbt\tag\Short;
  19. use pocketmine\Player;
  20.  
  21. abstract class SlappableHuman extends Human{
  22.     private $main;
  23.     public function __construct(LegionPE $main, Location $vectors, $displayName){
  24.         $this->main = $main;
  25.         $nbt = new Compound;
  26.         $nbt->Pos = new Enum("Pos", [
  27.             new Double(0, $vectors->x),
  28.             new Double(1, $vectors->y),
  29.             new Double(2, $vectors->z)
  30.         ]);
  31.         $nbt->Motion = new Enum("Motion", [
  32.             new Double(0, 0),
  33.             new Double(1, 0),
  34.             new Double(2, 0)
  35.         ]);
  36.         $nbt->Rotation = new Enum("Rotation", [
  37.             new Float(0, $vectors->yaw),
  38.             new Float(1, $vectors->pitch)
  39.         ]);
  40.         $nbt->FallDistance = new Float("FallDistance", 0);
  41.         $nbt->Fire = new Short("Fire", 0);
  42.         $nbt->Air = new Short("Air", 0);
  43.         $nbt->OnGround = new Byte("OnGround", 1);
  44.         $nbt->Invulnerable = new Byte("Invulnerable", 1);
  45.         $nbt->Health = new Short("Health", 20);
  46.         $nbt->NameTag = $displayName;
  47.         $nbt->Inventory = new Enum("Inventory", [new Compound(false, [
  48.             new Short("id", 0),
  49.             new Short("Damage", 0),
  50.             new Byte("Count", 0),
  51.             new Byte("Slot", 9),
  52.             new Byte("TrueSlot", 9)
  53.         ])]);
  54.         $X = ($vectors->getFloorX()) >> 4;
  55.         $Z = ($vectors->getFloorZ() >> 4);
  56.         if(!$vectors->getLevel()->isChunkLoaded($X, $Z)){
  57.             $vectors->getLevel()->loadChunk($X, $Z);
  58.         }
  59.         $chunk = $vectors->getLevel()->getChunk($X, $Z);
  60.         $this->inventory = new PlayerInventory($this);
  61.         parent::__construct($chunk, $nbt);
  62.         $this->setRotation($vectors->yaw, $vectors->pitch);
  63.         $this->nameTag = $displayName;
  64.     }
  65.     public function attack($damage, EntityDamageEvent $source){
  66.         if(!($source instanceof EntityDamageByEntityEvent)){
  67.             return;
  68.         }
  69.         $damager = $source->getDamager();
  70.         if(!($damager instanceof Player)){
  71.             return;
  72.         }
  73.         $session = $this->main->getSessions()->getSession($damager);
  74.         if($session instanceof Session){
  75.             $this->onSlap($session);
  76.         }
  77.     }
  78.     protected abstract function onSlap(Session $session);
  79.     /**
  80.      * @return LegionPE
  81.      */
  82.     public function getMain(){
  83.         return $this->main;
  84.     }
  85.     public function _kill(){
  86.         $this->getLevel()->removeEntity($this);
  87.     }
  88.     public function badConstruct($chunk){
  89.         if($chunk instanceof FullChunk){
  90.             $this->inventory = new PlayerInventory($this);
  91.             $this->server = $chunk->getProvider()->getLevel()->getServer();
  92.             $this->setLevel($chunk->getProvider()->getLevel());
  93.             $chunk->getProvider()->getLevel()->removeEntity($this);
  94.         }
  95.         else{
  96.             echo "What? SlappableHuman::badConstruct() receives parameter 1 as " . is_object($chunk) ? get_class($chunk):gettype($chunk);
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement