├── .poggit.yml ├── README.md ├── composer.json ├── src └── CameraAPI │ ├── CameraHandler.php │ ├── CameraPresets.php │ └── Instructions │ ├── CameraInstruction.php │ ├── ClearCameraInstruction.php │ ├── FadeCameraInstruction.php │ ├── SetCameraInstruction.php │ ├── ShakeCameraInstruction.php │ └── TargetCameraInstruction.php └── virion.yml /.poggit.yml: -------------------------------------------------------------------------------- 1 | --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/kaxyum/CameraAPI 2 | build-by-default: true 3 | branches: 4 | - main 5 | projects: 6 | CameraAPI: 7 | model: virion 8 | type: library 9 | ... 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CameraAPI 2 | CameraAPI is an API that makes it easy to use the CameraPacket. 3 | 4 | # Usage 5 | Install [SimplePacketHandler](https://github.com/Muqsit/SimplePacketHandler/releases) on your server 6 | 7 | Register CameraHandler 8 | ```php 9 | if(!CameraHandler::isRegistered()) 10 | { 11 | CameraHandler::register($this); 12 | } 13 | ``` 14 | 15 | # Set Camera Instruction 16 | ```php 17 | // only the argument preset is compulsory 18 | $setCameraInstruction = new SetCameraInstruction(); 19 | $setCameraInstruction->setPreset(CameraPresets::FREE()); //CameraPresets::FIRST_PERSON(), CameraPresets::THIRD_PERSON(), CameraPresets::THIRD_PERSON_FRONT(), CameraPresets::FOLLOW_ORBIT(), CameraPresets:FIXED_BOOM() 20 | $setCameraInstruction->setEase(CameraSetInstructionEaseType::LINEAR, 1); 21 | $setCameraInstruction->setCameraPosition(new Vector3(100, 100, 100)); 22 | $setCameraInstruction->setRotation(0, 0); 23 | $setCameraInstruction->setFacingPosition(new Vector3(0, 0, 0)); 24 | $setCameraInstruction->setViewOffset(new Vector2(0, 0)); 25 | $setCameraInstruction->send($player); 26 | ``` 27 | # Fade Camera Instruction 28 | ```php 29 | // no argument is compulsory 30 | $fadeCameraInstruction = new FadeCameraInstruction(); 31 | $fadeCameraInstruction->setTime(1, 5, 1); 32 | $fadeCameraInstruction->setColor(225, 225, 225); 33 | $fadeCameraInstruction->send($player); 34 | ``` 35 | 36 | # Target Camera Instruction 37 | ```php 38 | // only the argument actorUniqueId is compulsory 39 | $targetCameraInstruction = new TargetCameraInstruction(); 40 | $targetCameraInstruction->setTargetCenterOffset(new Vector3(0, 0, 0)); 41 | $targetCameraInstruction->setActorUniqueId(0); 42 | $targetCameraInstruction->send($player); 43 | ``` 44 | 45 | # Shake Camera Instruction 46 | ```php 47 | // all arguments are compulsory 48 | $shakeCameraInstruction = new ShakeCameraInstruction(); 49 | $shakeCameraInstruction->setIntensity(0); 50 | $shakeCameraInstruction->setDuration(0); 51 | $shakeCameraInstruction->setDuration(0); 52 | $shakeCameraInstruction->setShakeType(CameraShakePacket::TYPE_POSITIONAL); //CameraShakePacket::TYPE_ROTATIONAL 53 | $shakeCameraInstruction->setShakeAction(CameraShakePacket::ACTION_ADD); //CameraShakePacket::ACTION_STOP 54 | $shakeCameraInstruction->send($player); 55 | ``` 56 | 57 | # Clear Camera Instruction 58 | ```php 59 | // no argument is compulsory 60 | $clearCameraInstruction = new ClearCameraInstruction(); 61 | $clearCameraInstruction->setClear(true); 62 | $clearCameraInstruction->setRemoveTarget(true); 63 | $clearCameraInstruction->send($player); 64 | ``` 65 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CameraAPI", 3 | "description": "a PocketMine-MP API to use CameraPacket", 4 | "type": "library", 5 | "require": { 6 | "pocketmine/pocketmine-mp": "^5.0.0" 7 | }, 8 | "autoload": { 9 | "classmap": ["src"] 10 | }, 11 | "authors": [ 12 | { 13 | "name": "KaxYum", 14 | "email": "itskaxyum@gmail.com" 15 | } 16 | ], 17 | "extra": { 18 | "virion": { 19 | "spec": "3.0", 20 | "namespace-root": "CameraAPI" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CameraAPI/CameraHandler.php: -------------------------------------------------------------------------------- 1 | plugin))) 27 | { 28 | throw new \Error("Already registered with {$pl->getName()}"); 29 | } 30 | 31 | self::getInstance()->plugin = $plugin; 32 | $interceptor = SimplePacketHandler::createInterceptor($plugin, EventPriority::HIGHEST, false); 33 | $interceptor->interceptIncoming(function (SetLocalPlayerAsInitializedPacket $pk, NetworkSession $target): bool 34 | { 35 | $target->sendDataPacket(CameraPresetsPacket::create(CameraPresets::getAll())); 36 | return true; 37 | }); 38 | } 39 | 40 | public static function isRegistered(): bool 41 | { 42 | return !is_null(self::getInstance()->plugin); 43 | } 44 | 45 | public function getPlugin(): Plugin 46 | { 47 | return $this->plugin; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/CameraAPI/CameraPresets.php: -------------------------------------------------------------------------------- 1 | clear = $clear; 16 | } 17 | 18 | public function setRemoveTarget(bool $removeTarget): void 19 | { 20 | $this->removeTarget = $removeTarget; 21 | } 22 | 23 | public function send(Player $player): void 24 | { 25 | $player->getNetworkSession()->sendDataPacket(CameraInstructionPacket::create(null, $this->clear, null, null, $this->removeTarget)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CameraAPI/Instructions/FadeCameraInstruction.php: -------------------------------------------------------------------------------- 1 | time = new CameraFadeInstructionTime($fadeInTime, $stayInTime, $fadeOutTime); 19 | } 20 | 21 | public function setColor(float $red, float $green, float $blue): void 22 | { 23 | $this->color = new CameraFadeInstructionColor($red, $green, $blue); 24 | } 25 | 26 | public function send(Player $player): void 27 | { 28 | $player->getNetworkSession()->sendDataPacket(CameraInstructionPacket::create(null, null, new CameraFadeInstruction($this->time, $this->color), null, null)); 29 | } 30 | } -------------------------------------------------------------------------------- /src/CameraAPI/Instructions/SetCameraInstruction.php: -------------------------------------------------------------------------------- 1 | cameraPreset = $cameraPreset; 29 | } 30 | 31 | public function setEase(int $type, float $duration): void 32 | { 33 | $this->ease = new CameraSetInstructionEase($type, $duration); 34 | } 35 | 36 | public function setCameraPosition(Vector3 $cameraPosition): void 37 | { 38 | $this->cameraPosition = $cameraPosition; 39 | } 40 | 41 | public function setRotation(float $pitch, float $yaw): void 42 | { 43 | $this->rotation = new CameraSetInstructionRotation($pitch, $yaw); 44 | } 45 | 46 | public function setFacingPosition(Vector3 $facingPosition): void 47 | { 48 | $this->facingPosition = $facingPosition; 49 | } 50 | 51 | public function setViewOffset(Vector2 $viewOffset): void 52 | { 53 | $this->viewOffset = $viewOffset; 54 | } 55 | 56 | public function setEntityOffset(Vector3 $entityOffset): void 57 | { 58 | $this->entityOffset = $entityOffset; 59 | } 60 | 61 | public function send(Player $player): void 62 | { 63 | $player->getNetworkSession()->sendDataPacket(CameraInstructionPacket::create(new CameraSetInstruction(array_search($this->cameraPreset, CameraPresets::getAll(), true), $this->ease, $this->cameraPosition, $this->rotation, $this->facingPosition, $this->viewOffset, $this->entityOffset, null), null, null, null, null)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/CameraAPI/Instructions/ShakeCameraInstruction.php: -------------------------------------------------------------------------------- 1 | intensity = $intensity; 19 | } 20 | 21 | public function setDuration(float $duration): void 22 | { 23 | $this->duration = $duration; 24 | } 25 | 26 | public function setShakeType(int $shakeType): void 27 | { 28 | $this->shakeType = $shakeType; 29 | } 30 | 31 | public function setShakeAction(int $shakeAction): void 32 | { 33 | $this->shakeAction = $shakeAction; 34 | } 35 | 36 | public function send(Player $player): void 37 | { 38 | $player->getNetworkSession()->sendDataPacket(CameraShakePacket::create($this->intensity, $this->duration, $this->shakeType, $this->shakeAction)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CameraAPI/Instructions/TargetCameraInstruction.php: -------------------------------------------------------------------------------- 1 | targetCenterOffset = $targetCenterOffset; 18 | } 19 | 20 | public function setActorUniqueId(int $actorUniqueId): void 21 | { 22 | $this->actorUniqueId = $actorUniqueId; 23 | } 24 | 25 | public function send(Player $player): void 26 | { 27 | $player->getNetworkSession()->sendDataPacket(CameraInstructionPacket::create(null, null, null, new CameraTargetInstruction($this->targetCenterOffset, $this->actorUniqueId), null)); 28 | } 29 | } -------------------------------------------------------------------------------- /virion.yml: -------------------------------------------------------------------------------- 1 | name: CameraAPI 2 | antigen: CameraAPI 3 | version: 1.0.0 4 | api: [5.0.0] 5 | author: KaxYum 6 | softdepend: 7 | - SimplePacketHandler --------------------------------------------------------------------------------