Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. <?php
  2.  
  3. namespace friscowz\hc\entities;
  4.  
  5. use friscowz\hc\entities\projectile\BetterThrowable;
  6. use friscowz\hc\MDPlayer;
  7. use friscowz\hc\Luna;
  8. use pocketmine\block\Air;
  9. use pocketmine\block\Block;
  10. use pocketmine\block\FenceGate;
  11. use pocketmine\block\Slab;
  12. use pocketmine\entity\Entity;
  13. use pocketmine\entity\projectile\EnderPearl;
  14. use pocketmine\entity\projectile\Throwable;
  15. use pocketmine\entity\Zombie;
  16. use pocketmine\event\entity\EntityDamageEvent;
  17. use pocketmine\event\entity\ProjectileHitEvent;
  18. use pocketmine\item\Item;
  19. use pocketmine\item\ItemIds;
  20. use pocketmine\level\Level;
  21. use pocketmine\level\sound\EndermanTeleportSound;
  22. use pocketmine\math\AxisAlignedBB;
  23. use pocketmine\math\RayTraceResult;
  24. use pocketmine\math\Vector3;
  25. use pocketmine\nbt\tag\CompoundTag;
  26. use pocketmine\network\mcpe\protocol\LevelEventPacket;
  27. use pocketmine\scheduler\Task;
  28. use pocketmine\Server;
  29. use pocketmine\utils\TextFormat;
  30.  
  31. class BetterEnderPearl extends Throwable//EnderPearl
  32. {
  33. public const WHITELISTED_BLOCKS = [
  34. Block::AIR, Block::LADDER, Block::TRAPDOOR, Block::WATER, Block::LAVA,
  35. Block::WALL_BANNER, Block::FRAME_BLOCK, Block::FIRE, Block::TALL_GRASS,
  36. Block::TALLGRASS, Block::RED_FLOWER, Block::YELLOW_FLOWER, Block::RAIL,
  37. Block::ACTIVATOR_RAIL, Block::DETECTOR_RAIL, Block::GOLDEN_RAIL,
  38. Block::POWERED_RAIL, Block::CARPET, Block::CARROT_BLOCK, Block::CARROTS,
  39. Block::POTATO_BLOCK, Block::POTATOES, Block::LEVER, Block::HEAVY_WEIGHTED_PRESSURE_PLATE,
  40. Block::LIGHT_WEIGHTED_PRESSURE_PLATE, Block::STONE_PRESSURE_PLATE, Block::WOODEN_PRESSURE_PLATE,
  41. Block::TORCH, Block::VINE, Block::VINES, Block::WALL_SIGN, Block::SIGN_POST, Block::STANDING_SIGN,
  42. ];
  43.  
  44. const NOREALBLOCKS =
  45. [
  46. Block::STONE_SLAB,
  47. Block::WOODEN_SLAB,
  48. Block::STONE_SLAB2,
  49. Block::OAK_STAIRS,
  50. Block::COBBLESTONE_STAIRS,
  51. Block::BRICK_STAIRS,
  52. Block::STONE_BRICK_STAIRS,
  53. Block::NETHER_BRICK_STAIRS,
  54. Block::SPRUCE_STAIRS,
  55. Block::BIRCH_STAIRS,
  56. Block::JUNGLE_STAIRS,
  57. Block::QUARTZ_STAIRS,
  58. Block::ACACIA_STAIRS,
  59. Block::DARK_OAK_STAIRS,
  60. Block::RED_SANDSTONE_STAIRS,
  61. Block::PURPUR_STAIRS,
  62. 53,
  63. ];
  64.  
  65. const NETWORK_ID = self::ENDER_PEARL;
  66. public $width = 0.015;//0.25
  67. public $height = 0.015;//0.25
  68. public $level;
  69. //protected $gravity = 0.03;
  70. //protected $drag = 0.01;
  71.  
  72.  
  73. /**
  74. * BetterEnderPearl constructor.
  75. * @param Level $level
  76. * @param CompoundTag $nbt
  77. * @param Entity|null $shootingEntity
  78. */
  79. public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null)
  80. {
  81. parent::__construct($level, $nbt, $shootingEntity);
  82. $this->level = $level;
  83. }
  84.  
  85.  
  86. private function generateTestingZombie(Vector3 $pos): Entity
  87. {
  88. $nbt = Entity::createBaseNBT($pos);
  89. $zombie = new Zombie($this->level, $nbt);
  90. return $zombie;
  91. }
  92.  
  93. private function isInsideOfBlock(Entity $entity)
  94. {
  95. $block = $entity->level->getBlockAt((int)floor($entity->x), (int)floor($y = ($entity->y + $entity->getEyeHeight())), (int)floor($entity->z));
  96.  
  97. return $block->isSolid() and $block->collidesWithBB($entity->getBoundingBox());
  98. }
  99.  
  100.  
  101. protected function onHit(ProjectileHitEvent $event): void
  102. {
  103. $owner = $this->getOwningEntity();
  104. $hit = $event->getRayTraceResult()->getHitVector();
  105. $facing = $event->getRayTraceResult()->getHitFace();
  106.  
  107. if (!is_null($owner)) {
  108.  
  109. if ($owner instanceof LNPlayer) {
  110.  
  111. $zombie = $this->generateTestingZombie(new Vector3($hit->x, $hit->y, $hit->z));
  112.  
  113. if($facing === 2) $hit = $hit->subtract(0, 0, 0.2); //Fixes weird pearl thing that stops you from being able to pearl on walls
  114. if($facing === 4) $hit = $hit->subtract(0.2); //Fixes weird pearl thing that stops you from being able to pearl on walls
  115.  
  116. if ($this->isInsideOfBlock($zombie) && $hit instanceof Block) { //Checks if zombie is inside block then cancelling if it is$owner->getLevel()));
  117. $zombie->flagForDespawn();
  118. $owner->sendMessage(C::RED . "You cannot pearl inside this block");
  119. $owner->getInventory()->addItem(Item::get(Item::ENDER_PEARL, 0, 1));
  120. $owner->setEndertime(0);
  121. return;
  122. }
  123.  
  124.  
  125. if ($this->getLevel()->getName() === $owner->getServer()->getDefaultLevel()->getName()) {
  126. if (Luna::getFactionsManager()->isSpawnClaim($this->getPosition())) {
  127. $owner->sendPopup($owner->messageToTranslate('error_try_ender_pearl_spawn'));
  128. $owner->sendMessage($owner->messageToTranslate('error_try_ender_pearl_spawn'));
  129. $owner->getInventory()->addItem(Item::get(ItemIds::ENDER_PEARL, 0, 1));
  130. $owner->setEndertime(0);
  131. return;
  132. }
  133. }
  134.  
  135. if (($owner->isInvincibility() || $owner->isPvp()) && Luna::getFactionsManager()->isFactionClaim($this, $this->getLevel()->getName())) {
  136. $owner->sendPopup($owner->messageToTranslate('error_try_ender_pearl_to_claim'));
  137. $owner->sendMessage($owner->messageToTranslate('error_try_ender_pearl_to_claim'));
  138. $owner->getInventory()->addItem(Item::get(ItemIds::ENDER_PEARL, 0, 1));
  139. $owner->setEndertime(0);
  140. return;
  141. }
  142.  
  143.  
  144. $distance = sqrt((($owner->x - $hit->x) ** 2) + ((($owner->y + 1) - $hit->y) ** 2) + (($owner->z - $hit->z) ** 2)); //Gets the distance between the block/entity hit and player from head height of player
  145. if (!$hit instanceof Air and $distance < 2.25 and $facing !== 1) {//Checks if the pearl landed is to close to the player then cancelling if it is
  146. $owner->sendMessage(TextFormat::RED . "You cannot pearl inside this block");
  147. $owner->getInventory()->addItem(Item::get(Item::ENDER_PEARL, 0, 1));
  148. $owner->setEndertime(0);
  149. return;
  150. }
  151.  
  152.  
  153. $this->level->broadcastLevelEvent($owner, LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT);
  154. $this->level->addSound(new EndermanTeleportSound($owner));
  155. $pos = $event->getRayTraceResult()->getHitVector();
  156. $owner->teleport($hit);
  157.  
  158. $this->level->addSound(new EndermanTeleportSound($owner));
  159. $owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_CONTACT, 0.5));
  160. }
  161. }
  162. }
  163.  
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement