Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BetterEnderPearl extends EPearl
- {
- public $width = 0.25;//0.25
- public $height = 0.25;//0.25
- public $level;
- /**
- * BetterEnderPearl constructor.
- * @param Level $level
- * @param CompoundTag $nbt
- * @param Entity|null $shootingEntity
- */
- public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null)
- {
- parent::__construct($level, $nbt, $shootingEntity);
- $this->level = $level;
- }
- private function generateTestingZombie(Vector3 $pos): Entity
- {
- $nbt = Entity::createBaseNBT($pos);
- $zombie = new Zombie($this->level, $nbt);
- return $zombie;
- }
- private function isInsideOfBlock(Entity $entity)
- {
- $block = $entity->level->getBlockAt((int)floor($entity->x), (int)floor($y = ($entity->y + $entity->getEyeHeight())), (int)floor($entity->z));
- return $block->isSolid() and $block->collidesWithBB($entity->getBoundingBox());
- }
- protected function onHit(ProjectileHitEvent $event) : void
- {
- $result = $event->getRayTraceResult();
- $owner = $this->getOwningEntity();
- $facing = $result->getHitFace();
- $hit = $result->getHitVector();
- if ($event instanceof ProjectileHitBlockEvent) {
- $pos = $event->getBlockHit();
- } elseif ($event instanceof ProjectileHitEntityEventct) {
- $pos = $event->getEntityHit();
- } else $hit = null;
- if (!$owner instanceof LNPlayer || $hit === null) {
- return;
- }
- $distance = sqrt((($owner->x - $hit->x) ** 2) + ((($owner->y + 1) - $hit->y) ** 2) + (($owner->z - $hit->z) ** 2));
- if (!$hit instanceof Air and $distance < 2.25 and $facing !== 1) {
- $owner->sendMessage(TextFormat::RED . "You cannot pearl inside this block");
- $owner->getInventory()->addItem(Item::get(Item::ENDER_PEARL, 0, 1));
- $owner->setEndertime(0);
- return;
- }
- $zombie = $this->generateTestingZombie($pos);
- if($facing === 2) $pos = $pos->subtract(0, 0, 0.2);
- if($facing === 4) $pos = $pos->subtract(0.2);
- if($this->isInsideOfBlock($zombie) && $hit instanceof Block){
- $zombie->flagForDespawn();
- $owner->sendMessage(TextFormat::RED . "You cannot pearl inside this block");
- $owner->getInventory()->addItem(Item::get(Item::ENDER_PEARL, 0, 1));
- $owner->setEndertime(0);
- return;
- }
- $zombie->flagForDespawn();
- $this->level->broadcastLevelEvent($owner, LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT);
- $this->level->addSound(new EndermanTeleportSound($owner));
- $owner->teleport($pos);
- $this->level->addSound(new EndermanTeleportSound($owner));
- $owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_FALL, 2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement