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:
usemuqsit\libcamera\libcamera;
usepocketmine\plugin\PluginBase;
class MyPlugin extends PluginBase{
publicfunctiononEnable() : void{
if(!libcamera::isRegistered()){
libcamera::register($this);
}
}
// ...
}To send instructions to the camera, use the following code:
- Set
usemuqsit\libcamera\libcamera;
usemuqsit\libcamera\CameraInstruction;
usepocketmine\network\mcpe\protocol\types\camera\CameraPreset;
usepocketmine\network\mcpe\protocol\types\camera\CameraSetInstructionEase;
usepocketmine\network\mcpe\protocol\types\camera\CameraSetInstructionEaseType;
usepocketmine\network\mcpe\protocol\types\camera\CameraSetInstructionRotation;
usepocketmine\network\mcpe\protocol\types\camera\Vector3;
usepocketmine\player\Player;
// ...if($playerinstanceof 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: newCameraSetInstructionEase(
CameraSetInstructionEaseType::IN_OUT_CUBIC,
(float) 5.0// duration (sec)
),
camera_pos: null,
rot: newCameraSetInstructionRotation(
(float)20.0, //pitch
(float)180.0//yaw
),
facing_pos: null
)->send($player);
}- Fade
usemuqsit\libcamera\libcamera;
usemuqsit\libcamera\CameraInstruction;
usepocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionColor;
usepocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionTime;
usepocketmine\player\Player;
// ...if($playerinstanceof Player && $player->isOnline()){
/** * @phpstan-param CameraFadeInstructionColor|null $color * @phpstan-param CameraFadeInstructionTime|null $time */
CameraInstruction::fade(
color: newCameraFadeInstructionColor((float)$r,(float)$g,(float)$b),
time: newCameraFadeInstructionTime((float)$fadeInTime,(float)$stayTime,(float)$fadeOutTime)
)->send($player);
}- Target
usemuqsit\libcamera\libcamera;
usemuqsit\libcamera\CameraInstruction;
usepocketmine\network\mcpe\protocol\types\camera\CameraTargetInstruction;
usepocketmine\math\Vector3;
usepocketmine\player\Player;
// ...if($playerinstanceof 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
usemuqsit\libcamera\libcamera;
usemuqsit\libcamera\CameraInstruction;
usepocketmine\player\Player;
// ...if($playerinstanceof Player && $player->isOnline()){
CameraInstruction::removeTarget()->send($player);
}- Clear
usemuqsit\libcamera\libcamera;
usemuqsit\libcamera\CameraInstruction;
usepocketmine\player\Player;
// ...if($playerinstanceof Player && $player->isOnline()){
CameraInstruction::clear()->send($player);
}- Multi
usemuqsit\libcamera\libcamera;
usemuqsit\libcamera\CameraInstruction;
usepocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionColor;
usepocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionTime;
usepocketmine\math\Vector3;
usepocketmine\player\Player;
// ...if($playerinstanceof Player && $player->isOnline()){
CameraInstruction::multi(
CameraInstruction::target(
targetCenterOffset: Vector3::zero(),
actorUniqueId: $player->getId()
),
CameraInstruction::fade(
color: newCameraFadeInstructionColor((float)$r,(float)$g,(float)$b),
time: newCameraFadeInstructionTime((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.
