Skip to content

Instantly share code, notes, and snippets.

@DavyCraft648
Last active June 24, 2025 21:05
Show Gist options
  • Select an option

  • Save DavyCraft648/5666506e9184f8c4e70daadcba7ec8be to your computer and use it in GitHub Desktop.

Select an option

Save DavyCraft648/5666506e9184f8c4e70daadcba7ec8be to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
use pocketmine\data\bedrock\item\ItemTypeNames;
use pocketmine\data\bedrock\item\SavedItemData;
use pocketmine\entity\Entity;
use pocketmine\event\EventPriority;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemIdentifier;
use pocketmine\item\ItemTypeIds;
use pocketmine\network\mcpe\protocol\AddActorPacket;
use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\world\format\io\GlobalItemDataHandlers;
/**
* @name mobarmorexample
* @version 1.0.0
* @api 5.0.0
* @main mobarmorexample
*/
class mobarmorexample extends \pocketmine\plugin\PluginBase{
protected function onEnable() : void{
$id = null;
$iron_horse_armor = new Item(new ItemIdentifier(ItemTypeIds::newId()), "Iron Horse Armor");
GlobalItemDataHandlers::getDeserializer()->map(ItemTypeNames::IRON_HORSE_ARMOR, fn() => clone $iron_horse_armor);
GlobalItemDataHandlers::getSerializer()->map($iron_horse_armor, fn() => new SavedItemData(ItemTypeNames::IRON_HORSE_ARMOR));
$this->getServer()->getPluginManager()->registerEvent(PlayerChatEvent::class, function(PlayerChatEvent $event) use ($iron_horse_armor, &$id) : void{
if($event->getMessage() === "a"){
$player = $event->getPlayer();
$pos = $player->getPosition();
$player->getNetworkSession()->sendDataPacket(AddActorPacket::create(
$id = Entity::nextRuntimeId(),
$id,
"minecraft:horse",
$pos->asVector3(),
null,
0.0,
0.0,
0.0,
0.0,
[],
[],
new PropertySyncData([], []),
[]
));
}elseif($event->getMessage() === "b" && $id !== null){
$player = $event->getPlayer();
$session = $player->getNetworkSession();
$session->sendDataPacket(MobArmorEquipmentPacket::create(
$id,
ItemStackWrapper::legacy(ItemStack::null()),
ItemStackWrapper::legacy(ItemStack::null()),
ItemStackWrapper::legacy(ItemStack::null()),
ItemStackWrapper::legacy(ItemStack::null()),
ItemStackWrapper::legacy($session->getTypeConverter()->coreItemStackToNet($iron_horse_armor)),
));
}
}, EventPriority::LOW, $this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment