Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace friscowz\hc\entities;
- use friscowz\hc\entities\projectile\BetterThrowable;
- use friscowz\hc\MDPlayer;
- use friscowz\hc\Luna;
- use pocketmine\block\Air;
- use pocketmine\block\Block;
- use pocketmine\block\FenceGate;
- use pocketmine\block\Slab;
- use pocketmine\entity\Entity;
- use pocketmine\entity\projectile\EnderPearl;
- use pocketmine\entity\projectile\Throwable;
- use pocketmine\entity\Zombie;
- use pocketmine\event\entity\EntityDamageEvent;
- use pocketmine\event\entity\ProjectileHitEvent;
- use pocketmine\item\Item;
- use pocketmine\item\ItemIds;
- use pocketmine\level\Level;
- use pocketmine\level\sound\EndermanTeleportSound;
- use pocketmine\math\AxisAlignedBB;
- use pocketmine\math\RayTraceResult;
- use pocketmine\math\Vector3;
- use pocketmine\nbt\tag\CompoundTag;
- use pocketmine\network\mcpe\protocol\LevelEventPacket;
- use pocketmine\scheduler\Task;
- use pocketmine\Server;
- use pocketmine\utils\TextFormat;
- class BetterEnderPearl extends Throwable//EnderPearl
- {
- public const WHITELISTED_BLOCKS = [
- Block::AIR, Block::LADDER, Block::TRAPDOOR, Block::WATER, Block::LAVA,
- Block::WALL_BANNER, Block::FRAME_BLOCK, Block::FIRE, Block::TALL_GRASS,
- Block::TALLGRASS, Block::RED_FLOWER, Block::YELLOW_FLOWER, Block::RAIL,
- Block::ACTIVATOR_RAIL, Block::DETECTOR_RAIL, Block::GOLDEN_RAIL,
- Block::POWERED_RAIL, Block::CARPET, Block::CARROT_BLOCK, Block::CARROTS,
- Block::POTATO_BLOCK, Block::POTATOES, Block::LEVER, Block::HEAVY_WEIGHTED_PRESSURE_PLATE,
- Block::LIGHT_WEIGHTED_PRESSURE_PLATE, Block::STONE_PRESSURE_PLATE, Block::WOODEN_PRESSURE_PLATE,
- Block::TORCH, Block::VINE, Block::VINES, Block::WALL_SIGN, Block::SIGN_POST, Block::STANDING_SIGN,
- ];
- const NOREALBLOCKS =
- [
- Block::STONE_SLAB,
- Block::WOODEN_SLAB,
- Block::STONE_SLAB2,
- Block::OAK_STAIRS,
- Block::COBBLESTONE_STAIRS,
- Block::BRICK_STAIRS,
- Block::STONE_BRICK_STAIRS,
- Block::NETHER_BRICK_STAIRS,
- Block::SPRUCE_STAIRS,
- Block::BIRCH_STAIRS,
- Block::JUNGLE_STAIRS,
- Block::QUARTZ_STAIRS,
- Block::ACACIA_STAIRS,
- Block::DARK_OAK_STAIRS,
- Block::RED_SANDSTONE_STAIRS,
- Block::PURPUR_STAIRS,
- 53,
- ];
- const NETWORK_ID = self::ENDER_PEARL;
- public $width = 0.015;//0.25
- public $height = 0.015;//0.25
- public $level;
- //protected $gravity = 0.03;
- //protected $drag = 0.01;
- /**
- * 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
- {
- $owner = $this->getOwningEntity();
- $hit = $event->getRayTraceResult()->getHitVector();
- $facing = $event->getRayTraceResult()->getHitFace();
- if (!is_null($owner)) {
- if ($owner instanceof LNPlayer) {
- $zombie = $this->generateTestingZombie(new Vector3($hit->x, $hit->y, $hit->z));
- if($facing === 2) $hit = $hit->subtract(0, 0, 0.2); //Fixes weird pearl thing that stops you from being able to pearl on walls
- if($facing === 4) $hit = $hit->subtract(0.2); //Fixes weird pearl thing that stops you from being able to pearl on walls
- if ($this->isInsideOfBlock($zombie) && $hit instanceof Block) { //Checks if zombie is inside block then cancelling if it is$owner->getLevel()));
- $zombie->flagForDespawn();
- $owner->sendMessage(C::RED . "You cannot pearl inside this block");
- $owner->getInventory()->addItem(Item::get(Item::ENDER_PEARL, 0, 1));
- $owner->setEndertime(0);
- return;
- }
- if ($this->getLevel()->getName() === $owner->getServer()->getDefaultLevel()->getName()) {
- if (Luna::getFactionsManager()->isSpawnClaim($this->getPosition())) {
- $owner->sendPopup($owner->messageToTranslate('error_try_ender_pearl_spawn'));
- $owner->sendMessage($owner->messageToTranslate('error_try_ender_pearl_spawn'));
- $owner->getInventory()->addItem(Item::get(ItemIds::ENDER_PEARL, 0, 1));
- $owner->setEndertime(0);
- return;
- }
- }
- if (($owner->isInvincibility() || $owner->isPvp()) && Luna::getFactionsManager()->isFactionClaim($this, $this->getLevel()->getName())) {
- $owner->sendPopup($owner->messageToTranslate('error_try_ender_pearl_to_claim'));
- $owner->sendMessage($owner->messageToTranslate('error_try_ender_pearl_to_claim'));
- $owner->getInventory()->addItem(Item::get(ItemIds::ENDER_PEARL, 0, 1));
- $owner->setEndertime(0);
- return;
- }
- $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
- 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
- $owner->sendMessage(TextFormat::RED . "You cannot pearl inside this block");
- $owner->getInventory()->addItem(Item::get(Item::ENDER_PEARL, 0, 1));
- $owner->setEndertime(0);
- return;
- }
- $this->level->broadcastLevelEvent($owner, LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT);
- $this->level->addSound(new EndermanTeleportSound($owner));
- $pos = $event->getRayTraceResult()->getHitVector();
- $owner->teleport($hit);
- $this->level->addSound(new EndermanTeleportSound($owner));
- $owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_CONTACT, 0.5));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement