Hello, I'm looking how to apply a custom skin to a MOB_HEAD. I know it's possible to give a player head this way (PlayerHead plugin): PHP: (ItemFactory::get(Item::MOB_HEAD, 3)) ->setCustomBlockData(new CompoundTag('Skin', [ new StringTag('Name', $name), new ByteArrayTag('Data', $skin->getSkinData()) ])); But, from what i've see, it take the head from a full player skin. Is it possible to apply to item only the head skin ? (https://minecraft-heads.com/) Thanks a lot for you time
I'm sorry, but i'm not able to understand your answer. Maybe you miss the part of my post, when i said i know PlayerHead should do it, but it seems it use the full player skin. I've post an issue on the plugin GitHub, and hope to have an answer soon, but i'll be happy if i could do it myself, and maybe send a PR to him
Are you on about replacing a player’s head with a preset one? (Kind of like Java edition wearing a player’s head)
Hello, (sorry for the delay, haven't received notification mail ...) The final is to be able to give to a player, a 'head' with a custom Skin. So i can place, where i want : (Why ? To add many more item to my child on the server ! See possibilities on minecraft-heads) The PlayerHead plugin already do it, just need to find how to send a custom Skin file. It seems everything (almost) is possible with entity, and geometry, and skin (Turtle, Melon Launcher, Pets, Car, HotAirBalloon ...)
Is it possible? Get the skin in-game, save it using file_put_contents("skin.txt", $player->getSkin()->getSkinData()); and then use file_get_contents("skin.txt"); to get the skin. You kinda got the point, I'd save it in an array when the plugin enables.
The idea is perfect, and should work, but: It do not use skin as image (So most people won't be able to use it) It use the full skin, instead of the head only My original question was how should i can apply a custom texture to the head. From what i've read, it seems he create a head by extending Human and creating a custom geometry: PHP: public const HEAD_GEOMETRY = '{"geometry.player_head":{"texturewidth":64,"textureheight":64,"bones":[{"name":"head","pivot":[0,24,0],"cubes":[{"origin":[-4,0,-4],"size":[8,8,8],"uv":[0,0]}]}]}}'; And override? the setSkin function : PHP: parent::setSkin(new Skin($skin->getSkinId(), $skin->getSkinData(), '', 'geometry.player_head', self::HEAD_GEOMETRY)); I think my problem is near, and maybe need to find information about Skin function. I've done some research while writing this message, and it seems easy as just passing the Skin Data (Of the Head ?) to the 2nd argument. But, it seems he send the whole skin. I'm perplex... Will try tonight to pass only the HeadSkin in 2nd argument of the setSkin, but it won't work...
I've try to import the geometry on BlockBench, no errror message, but nothing show up. I was hopping to be ablke to apply a headskin a see what's happen. EDIT to prevent Spam [1] I've been able to load the Geometry and skin at Home, on BlockBench ! Seems to take only the head on Full Player Skin It can load texture from file, but the render is not correct, working on it ! [2] Geometry: OK (Hard to use BlockBench) Integration in plugin will be tried after eating [3] Where not able to copy/modify the plugin to load skin. I'm stuck with " $this->getDataFolder() " not working, my knowledge is small. Geometry availaible here: https://pastebin.com/8bFxAue5
Still working on it: I was wrong with the Gemotry Json, going to work with : Code: { "geometry.player_headObj": { "texturewidth": 16, "textureheight": 16, "visible_bounds_width": 2, "visible_bounds_height": 1, "visible_bounds_offset": [0, 0.5, 0], "bones": [ { "name": "bone", "pivot": [0, 0, 0], "cubes": [ {"origin": [-4, 0, -4], "size": [8, 8, 8], "uv": [1.99, 1.99], "mirror": true}, {"origin": [-4.5, 0, -4.5], "size": [9, 9, 9], "uv": [9.99, 1.99], "mirror": true} ] } ] } } And i'm stuck with my code : Code: [21:31:05] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\Server::getDataFolder()" (EXCEPTION) in "plugins/PlayerHeadObj/src/Enes5519/PlayerHeadObj/commands/PHCommand" at line 60 Source is: PHP: <?phpdeclare(strict_types=1);namespace Enes5519\PlayerHeadObj\commands;use Enes5519\PlayerHeadObj\PlayerHeadObj;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\utils\InvalidCommandSyntaxException;use pocketmine\Player;use pocketmine\utils\TextFormat;use pocketmine\utils\Config;use pocketmine\plugin\PluginBase;class PHCommand extends Command{ /** @var array */ private $messages; public function __construct(array $messages){ $this->messages = $messages; parent::__construct('PlayerHeadObj', 'Give a player head', '/PlayerHeadObj <playerName:string>', ['pho']); $this->setPermission('PlayerHeadObj.give'); } public function execute(CommandSender $sender, string $commandLabel, array $args){ if(!$this->testPermission($sender) or !($sender instanceof Player)){ return true; } if(empty($args)){ throw new InvalidCommandSyntaxException(); } unset($args[0]); $skinName = $sender->getServer()->getPlayer($name = implode(' ', $args)); if(file_exists($sender->getServer()->getDataFolder() . $skinName . ".png")) { // new Skin("Standard_Custom", $this->createSkin($skin)) // $sender->getInventory()->addItem(PlayerHeadObj::getPlayerHeadItem($player->getSkin(), $player->getName())); $sender->getInventory()->addItem(PlayerHead::getPlayerHeadItem($player->getSkin(), $skinName)); $sender->sendMessage(PlayerHeadObj::PREFIX . TextFormat::colorize(sprintf($this->messages['message-head-added'], $skinName))); } else { $player->sendMessage("Error: Skin do not exist !"); } return true; }} Error line is: PHP: if(file_exists($sender->getServer()->getDataFolder() . $skinName . ".png")) {
Its actually: PHP: PluginBase::getDataFolder(); So the solution is to use your PluginBase's class and directly use getDataFolder(). You can create an instance variable on your main class and call it from PHCommand class. Here are some examples of how you can implement: Main class (a class that extends PluginBase) PHP: class Main extends PluginBase { /** @var Main */ private static $instance; public function onEnable() { if (self::$instance === null) { self::$instance = $this; } } public static function getInstance() : Main { return self::$instance; }} Command class (or any classes that need to call PluginBase's API) * Use the main class. PHP: use namespaces\Main; * Call the API: PHP: Main::getInstance()->getDataFolder(); // plugin's folder.
Thanks, You Are Insane ! I've been able to do some little modifications and it works as you said. (And i've learn something) Skin loading is working very well, and apply to the model : But my model is not really the same as in BlockBench, don't know why: Model source: https://pastebin.com/6ULPiWeR Code: { "geometry.player_headObj": { "texturewidth": 64, "textureheight": 64, "visible_bounds_width": 2, "visible_bounds_height": 1, "visible_bounds_offset": [0, 0.5, 0], "bones": [ { "name": "head", "pivot": [0, 0, 0], "cubes": [ {"origin": [-4, 0, -4], "size": [8, 8, 8], "uv": [0, 0], "mirror": true}, {"origin": [-4, 0, -4], "size": [8, 8, 8], "uv": [32, 0], "inflate": 0.5, "mirror": true} ] } ] } }
## Beta 1 ## Yes, it's working (it seems) ! I've encountered some strange bug, like removing the geometry from source code, it's still working. PHP: public const HEAD_GEOMETRY = ''; This is why i was having old head geometry ... Don't know why and how it's possible (I don't know why, but geometry seems near correct, but seems not correct too ... Maybe just me or my eyes ...) Source on my GitHub or: https://github.com/benda95280/PlayerHeadObj Please, this is first attempt, code is ugly. If someone want to try it and tell me if it's working for him.
I've been stared by my idol, soooo Happyy Thank you so much ! ## Beta 2 ## New update pushed: - Remove usless thing - Readme Updated - Some functions removed or changed - Item message and name change ... But i'm back with some questions: - Is it possible to change animation when item breaked (dead) ? - Isn't it too big ? (Thiking to add possibility to choice small or normal (Or normal and big ...) - How should i manage the 'Yaw' of the item ? (Item are always having strange/wrong position) PHP: public function onPlace(BlockPlaceEvent $event) : void{ $player = $event->getPlayer(); if($player->hasPermission('PlayerHeadObj.spawn') and ($item = $player->getInventory()->getItemInHand())->getId() === Item::MOB_HEAD and ($blockData = $item->getCustomBlockData()) !== null){ $nbt = Entity::createBaseNBT($event->getBlock()->add(0.5, 0, 0.5), null, self::getYaw($event->getBlock(), $player)); $blockData->setName('Skin'); $nbt->setTag($blockData); (new HeadEntityObj($player->level, $nbt))->spawnToAll(); if(!$player->isCreative()){ $player->getInventory()->setItemInHand($item->setCount($item->getCount() - 1)); } $event->setCancelled(); } } private static function getYaw(Vector3 $pos, Vector3 $target) : float{ $yaw = atan2($target->z - $pos->z, $target->x - $pos->x) / M_PI * 180 - 90; if($yaw < 0){ $yaw += 360.0; } foreach([45, 90, 135, 180, 225, 270, 315, 360] as $direction){ if($yaw <= $direction){ return $direction; } } return $yaw; } [ Entity placed in front of me ]
You could add some particles. I think it's fine That's be cool, or just let the user input a scale? I don't see what's wrong with the jaw
Sorry, was thinking about the dead animation (Red, and rotation) because it don't apply to it, possible to cancel it or change it ? I was thinking to add size option inside the name of the skin, like: book-1.medium.png book-2.normal.png Working to add support by command line, to be compatible with plugin like Shop. I'm looking to check why it's not in facing me, but it's placed with +45°. (It you try to place a radio, it will be placed not facing you) Maybe just remove this part of the code. Looking too, to add support for 'mask', by looking the code/source of EverybodyThonk script
I'm stuck I'm looking how to handle the size of the Entity. What i've think think / tried was: HardCode it in the Entity (entities\HeadEntityObj) Seems impossible, because how to know it size inside the Entity code (Line 72) ? Create a new entity Tried, but in the OnPlace, how to know my size, to switch to the other entity ? Right Click to change the size Not tried, but how to handle right click on my entity and switch geometry inside the code of the entity?
Here: https://github.com/benda95280/PlayerHeadObj/pull/1 tbh I wouldn't move away from standard head sizes, that way you could later add a feature that can automatically download a player's head. Fixed it: https://github.com/benda95280/PlayerHeadObj/pull/1