Is it possible to set item wearable? i want to set itemID 20 (glass) into the players helmet slot to resemble a space helmet because my server is space themed. the item gets set in the slot but doesn't show.
Here's a plugin made by @Muqsit which allows just what you want. PHP: $hat = new Hat($player);$hat->setBlock($block);/** @var HatPlayer $player*/$player->setHat($hat); There's more then one way to set the player's hat, am just using the player method one for an example.
It uses FallingSand entity to create fake blocks. It isn't that bad but it could be done better with minecarts. If you set a custom block to a minecart and set the minecart invisible, it creates the perfect hat . Here's the result:
Create a Hat entity class with entity ID of minecart. PHP: class HatEntity extends Entity{ const NETWORK_ID = self::MINECART;} Register the class on plugin startup. PHP: Entity::registerEntity(HatEntity::class); You can add the following method in the HatEntity class. PHP: public function setHatBlock(int $blockId, int $blockMeta = 0) : void{ $dpm = $this->getDataPropertyManager(); $dpm->setInt(self::DATA_MINECART_DISPLAY_BLOCK, $blockId | ($blockMeta << 16)); $dpm->setByte(self::DATA_MINECART_HAS_DISPLAY, 1);} Now, if you'd want to set a hat onto a player, you'll need to create the HatEntity entity, call the setHatBlock() method and then set the entity invisible (use the search bar for how to set an entity invisible). PHP: /** @var Player $player */$hat = Entity::createEntity("HatEntity", $player->getLevel(), Entity::createBaseNBT($player));$hat->setHatBlock(Block::GRASS); To make the HatEntity follow the player, you will either have to use PlayerMoveEvent and move the hat everytime the player moves OR (this may be tricky) you can have the HatEntity ride the player... (and still listen to PlayerMoveEvent to update the HatEntity's position).
I have tried the code you gave me but i get this error: Code: Could not pass event 'pocketmine\event\player\PlayerMoveEvent' to 'hats v1.2.2': Argument 2 passed to pocketmine\entity\DataPropertyManager::setFloat() must be of the type float, null given, called in phar://C:/Users/steve/Desktop/server/hub/PocketMine-MP.phar/src/pocketmine/entity/Entity.php on line 545 on hats\Main TypeError: "Argument 2 passed to pocketmine\entity\DataPropertyManager::setFloat() must be of the type float, null given, called in phar://C:/Users/steve/Desktop/server/hub/PocketMine-MP.phar/src/pocketmine/entity/Entity.php on line 545" (EXCEPTION) in "src/pocketmine/entity/DataPropertyManager" at line 115 my code: PHP: class Main extends PluginBase implements Listener{ public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); Entity::registerEntity(HatEntity::class); } public function onMove(PlayerMoveEvent $event){ $player = $event->getPlayer(); /** @var Player $player */ $hat = Entity::createEntity("HatEntity", $player->getLevel(), Entity::createBaseNBT($player)); $hat->setHatBlock(Block::GLASS); }}class HatEntity extends Entity{ const NETWORK_ID = self::MINECART; public function setHatBlock(int $blockId, int $blockMeta = 0) : void{ $dpm = $this->getDataPropertyManager(); $dpm->setInt(self::DATA_MINECART_DISPLAY_BLOCK, $blockId | ($blockMeta << 16)); $dpm->setByte(self::DATA_MINECART_HAS_DISPLAY, 1); }}
your plugin https://github.com/Muqsit/Hats/blob/master/src/muqsit/hats/HatPlayer.php when i /hat it doesn't wear the block im holding