A small library for handling camera instructions added in Minecraft Bedrock Edition 1.19.30.
See the official documentation for more information.
To install this library through composer, run the following command:
composer require wolvesfortress/libcamera
The virion for this library can be found on Poggit.
Here is a basic example on how this library is used:
In your main plugin file, register the virion like so:
use muqsit\libcamera\libcamera;
use pocketmine\plugin\PluginBase;
class MyPlugin extends PluginBase{
public function onEnable() : void{
if(!libcamera::isRegistered()){
libcamera::register($this);
}
}
// ...
}
To send instructions to the camera, use the following code:
- Set
use muqsit\libcamera\libcamera;
use muqsit\libcamera\CameraInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraPreset;
use pocketmine\network\mcpe\protocol\types\camera\CameraSetInstructionEase;
use pocketmine\network\mcpe\protocol\types\camera\CameraSetInstructionEaseType;
use pocketmine\network\mcpe\protocol\types\camera\CameraSetInstructionRotation;
use pocketmine\network\mcpe\protocol\types\camera\Vector3;
use pocketmine\player\Player;
// ...
if($player instanceof Player && $player->isOnline()){
/**
* @phpstan-param CameraPreset $preset
* @phpstan-param CameraSetInstructionEase|null $ease
* @phpstan-param Vector3|null $camera_pos
* @phpstan-param CameraSetInstructionRotation|null $rot
* @phpstan-param Vector3|null $facing_pos
*/
CameraInstruction::set(
preset: libcamera::getPresetRegistry()->registered["target"],
ease: new CameraSetInstructionEase(
CameraSetInstructionEaseType::IN_OUT_CUBIC,
(float) 5.0 // duration (sec)
),
camera_pos: null,
rot: new CameraSetInstructionRotation(
(float)20.0, //pitch
(float)180.0 //yaw
),
facing_pos: null
)->send($player);
}
- Fade
use muqsit\libcamera\libcamera;
use muqsit\libcamera\CameraInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionColor;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionTime;
use pocketmine\player\Player;
// ...
if($player instanceof Player && $player->isOnline()){
/**
* @phpstan-param CameraFadeInstructionColor|null $color
* @phpstan-param CameraFadeInstructionTime|null $time
*/
CameraInstruction::fade(
color: new CameraFadeInstructionColor((float)$r,(float)$g,(float)$b),
time: new CameraFadeInstructionTime((float)$fadeInTime,(float)$stayTime,(float)$fadeOutTime)
)->send($player);
}
- Target
use muqsit\libcamera\libcamera;
use muqsit\libcamera\CameraInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraTargetInstruction;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
// ...
if($player instanceof Player && $player->isOnline()){
/**
* @phpstan-param Vector3|null $targetCenterOffset
* @phpstan-param int $actorUniqueId
*/
CameraInstruction::target(
targetCenterOffset: Vector3::zero(), // no offset
actorUniqueId: $player->getId() // for example target the player
)->send($player);
}
- Remove Target
use muqsit\libcamera\libcamera;
use muqsit\libcamera\CameraInstruction;
use pocketmine\player\Player;
// ...
if($player instanceof Player && $player->isOnline()){
CameraInstruction::removeTarget()->send($player);
}
- Clear
use muqsit\libcamera\libcamera;
use muqsit\libcamera\CameraInstruction;
use pocketmine\player\Player;
// ...
if($player instanceof Player && $player->isOnline()){
CameraInstruction::clear()->send($player);
}
- Multi
use muqsit\libcamera\libcamera;
use muqsit\libcamera\CameraInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionColor;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionTime;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
// ...
if($player instanceof Player && $player->isOnline()){
CameraInstruction::multi(
CameraInstruction::target(
targetCenterOffset: Vector3::zero(),
actorUniqueId: $player->getId()
),
CameraInstruction::fade(
color: new CameraFadeInstructionColor((float)$r,(float)$g,(float)$b),
time: new CameraFadeInstructionTime((float)$fadeInTime,(float)$stayTime,(float)$fadeOutTime)
)
)->send($player);
}
At the moment, there are a few improvements that can be/or are being worked on. Here is a list of some of those improvements:
- Allow registering new camera presets
Any issues/suggestion can be reported here.