Created
February 21, 2026 00:07
-
-
Save Azvyl/60cb1b320fd22cba7d42f2d863d2df60 to your computer and use it in GitHub Desktop.
an example of SyncActorPropertyPacket for server -> resourcepack communication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use pocketmine\entity\Entity; | |
| use pocketmine\event\EventPriority; | |
| use pocketmine\event\player\PlayerChatEvent; | |
| use pocketmine\event\player\PlayerItemHeldEvent; | |
| use pocketmine\event\server\DataPacketSendEvent; | |
| use pocketmine\nbt\NBT; | |
| use pocketmine\nbt\tag\CompoundTag; | |
| use pocketmine\nbt\tag\ListTag; | |
| use pocketmine\nbt\tag\StringTag; | |
| use pocketmine\network\mcpe\protocol\AddActorPacket; | |
| use pocketmine\network\mcpe\protocol\ItemRegistryPacket; | |
| use pocketmine\network\mcpe\protocol\SetActorDataPacket; | |
| use pocketmine\network\mcpe\protocol\SyncActorPropertyPacket; | |
| use pocketmine\network\mcpe\protocol\types\CacheableNbt; | |
| use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData; | |
| use pocketmine\plugin\PluginBase; | |
| /** | |
| * @main propertysynctest | |
| * @api 5.0.0 | |
| */ | |
| class propertysynctest extends PluginBase{ | |
| protected function onEnable() : void{ | |
| $this->getServer()->getPluginManager()->registerEvent(DataPacketSendEvent::class, function(DataPacketSendEvent $event) : void{ | |
| foreach($event->getPackets() as $packet){ | |
| if($packet instanceof ItemRegistryPacket){ | |
| foreach($event->getTargets() as $target){ | |
| $target->sendDataPacket(SyncActorPropertyPacket::create( | |
| new CacheableNbt( | |
| CompoundTag::create() | |
| ->setTag( | |
| "properties", | |
| new ListTag( | |
| [ | |
| CompoundTag::create() | |
| ->setTag("enum", new ListTag([ | |
| new StringTag("unrolled"), | |
| new StringTag("rolled_up"), | |
| new StringTag("rolled_up_peeking"), | |
| new StringTag("rolled_up_relaxing"), | |
| new StringTag("rolled_up_unrolling") | |
| ], NBT::TAG_String)) | |
| ->setString("name", "minecraft:armadillo_state") | |
| ->setInt("type", 3) | |
| ], | |
| NBT::TAG_Compound | |
| ) | |
| ) | |
| ->setString("type", "minecraft:armadillo") | |
| ) | |
| ), true); | |
| } | |
| } | |
| } | |
| }, EventPriority::LOWEST, $this); | |
| $id = null; | |
| $this->getServer()->getPluginManager()->registerEvent(PlayerChatEvent::class, function(PlayerChatEvent $event) use (&$id) : void{ | |
| if($event->getMessage() === "a"){ | |
| $player = $event->getPlayer(); | |
| $pos = $player->getPosition(); | |
| $player->getNetworkSession()->sendDataPacket(AddActorPacket::create( | |
| $id = Entity::nextRuntimeId(), | |
| $id, | |
| "minecraft:armadillo", | |
| $pos->asVector3(), | |
| null, | |
| 0.0, | |
| 0.0, | |
| 0.0, | |
| 0.0, | |
| [], | |
| [], | |
| new PropertySyncData([0 => 0], []), | |
| [] | |
| )); | |
| } | |
| }, EventPriority::NORMAL, $this); | |
| $this->getServer()->getPluginManager()->registerEvent(PlayerItemHeldEvent::class, function(PlayerItemHeldEvent $event) use (&$id) : void{ | |
| if($id === null){ | |
| return; | |
| } | |
| $player = $event->getPlayer(); | |
| $session = $player->getNetworkSession(); | |
| $slot = $event->getSlot(); | |
| if($slot >= 0 && $slot <= 4){ | |
| var_dump("PlayerItemHeldEvent slot: $slot, id: $id"); | |
| $session->sendDataPacket(SetActorDataPacket::create( | |
| $id, | |
| [], | |
| new PropertySyncData( | |
| [0 => $slot], | |
| [] | |
| ), | |
| 0 | |
| )); | |
| } | |
| }, EventPriority::NORMAL, $this); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment