Im trying to spawn a falling sand at the foot of the player, but the client crashes. What am i doing wrong? $player is the player object and $blockId = 1 PHP: $pk = new AddEntityPacket(); $pk->type = FallingSand::NETWORK_ID; $pk->eid = $player->getId(); $pk->x = $player->x; $pk->y = $player->y; $pk->z = $player->z; $pk->did = -$blockId; $pk->metadata = [ DATA_FLAGS => [DATA_TYPE_BYTE, 0], DATA_AIR => [DATA_TYPE_SHORT, 300], DATA_NAMETAG => [DATA_TYPE_STRING, ""], DATA_SHOW_NAMETAG => [DATA_TYPE_BYTE, 1], DATA_SILENT => [DATA_TYPE_BYTE, 0], DATA_NO_AI => [DATA_TYPE_BYTE, 0], ]; foreach($player->getLevel()->getPlayers() as $p) { $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); }
Actually i didnt know what $pk->did sets I got the piece of code from BlockMan, but then it doesnt work, so i added the $pk->metadata part, but still cant get it to work Do you know what it means?
if I dont add this: PHP: $pk->metadata = [ DATA_FLAGS => [DATA_TYPE_BYTE, 0], DATA_AIR => [DATA_TYPE_SHORT, 300], DATA_NAMETAG => [DATA_TYPE_STRING, ""], DATA_SHOW_NAMETAG => [DATA_TYPE_BYTE, 1], DATA_SILENT => [DATA_TYPE_BYTE, 0], DATA_NO_AI => [DATA_TYPE_BYTE, 0], ]; This happens: Code: [18:17:12] [Server thread/CRITICAL]: Unhandled exception executing command 'bh s' in bh: Argument 1 passed to pocketmine\utils\Binary::writeMetadata() must be of the type array, null given, called in phar://C:/Pocketmine servers/ColorMatch3/PocketMine-MP.phar/src/pocketmine/network/protocol/AddEntityPacket__32bit.php on line 68 and defined [18:17:12] [Server thread/NOTICE]: InvalidArgumentException: "Argument 1 passed to pocketmine\utils\Binary::writeMetadata() must be of the type array, null given, called in phar://C:/Pocketmine servers/ColorMatch3/PocketMine-MP.phar/src/pocketmine/network/protocol/AddEntityPacket__32bit.php on line 68 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/utils/Binary" at line 84 [18:17:12] [Server thread/DEBUG]: #0 /src/pocketmine/network/protocol/AddEntityPacket__32bit(68): pocketmine\utils\Binary::writeMetadata(NULL ) [18:17:12] [Server thread/DEBUG]: #1 /src/pocketmine/network/RakLibInterface(203): pocketmine\network\protocol\AddEntityPacket->encode() [18:17:12] [Server thread/DEBUG]: #2 /src/pocketmine/Player__32bit(896): pocketmine\network\RakLibInterface->putPacket(pocketmine\Player Player(1), pocketmine\network\protocol\AddEntityPacket object, boolean , boolean ) [18:17:12] [Server thread/DEBUG]: #3 /BlockMan_v1.0.0/src/supermarcus/blockman/BlockMan(158): pocketmine\Player->dataPacket(pocketmine\network\protocol\AddEntityPacket object) [18:17:12] [Server thread/DEBUG]: #4 /BlockHunt_v1.0.0/src/blockhunt/blockhunt/BlockHunt(101): supermarcus\blockman\BlockMan->spawnBlockMan(pocketmine\Player Player(1), integer 170) [18:17:12] [Server thread/DEBUG]: #5 /BlockHunt_v1.0.0/src/blockhunt/blockhunt/BlockHunt(78): blockhunt\BlockHunt\BlockHunt->Start() [18:17:12] [Server thread/DEBUG]: #6 /src/pocketmine/command/PluginCommand(57): blockhunt\BlockHunt\BlockHunt->onCommand(pocketmine\Player Player(1), pocketmine\command\PluginCommand bh, string bh, array Array()) [18:17:12] [Server thread/DEBUG]: #7 /src/pocketmine/command/SimpleCommandMap(191): pocketmine\command\PluginCommand->execute(pocketmine\Player Player(1), string bh, array Array()) [18:17:12] [Server thread/DEBUG]: #8 /src/pocketmine/Server__32bit(2021): pocketmine\command\SimpleCommandMap->dispatch(pocketmine\Player Player(1), string bh s) [18:17:12] [Server thread/DEBUG]: #9 /src/pocketmine/Player__32bit(2472): pocketmine\Server->dispatchCommand(pocketmine\Player Player(1), string bh s) [18:17:12] [Server thread/DEBUG]: #10 /src/pocketmine/network/RakLibInterface(140): pocketmine\Player->handleDataPacket(pocketmine\network\protocol\TextPacket object) [18:17:12] [Server thread/DEBUG]: #11 /src/raklib/server/ServerHandler__32bit(90): pocketmine\network\RakLibInterface->handleEncapsulated(string 192.168.1.2:40819, raklib\protocol\EncapsulatedPacket `p ▒ace/bh s, integer 0) [18:17:12] [Server thread/DEBUG]: #12 /src/pocketmine/network/RakLibInterface(79): raklib\server\ServerHandler->handlePacket() [18:17:12] [Server thread/DEBUG]: #13 /src/pocketmine/network/Network(146): pocketmine\network\RakLibInterface->process() [18:17:12] [Server thread/DEBUG]: #14 /src/pocketmine/Server__32bit(2491): pocketmine\network\Network->processInterfaces() [18:17:12] [Server thread/DEBUG]: #15 /src/pocketmine/Server__32bit(2306): pocketmine\Server->tick() [18:17:12] [Server thread/DEBUG]: #16 /src/pocketmine/Server__32bit(2184): pocketmine\Server->tickProcessor() [18:17:12] [Server thread/DEBUG]: #17 /src/pocketmine/Server__32bit(1784): pocketmine\Server->start() [18:17:12] [Server thread/DEBUG]: #18 /src/pocketmine/PocketMine(464): pocketmine\Server->__construct(pocketmine\CompatibleClassLoader object, pocketmine\utils\MainLogger object, string phar://C:/Pocketmine servers/ColorMatch3/PocketMine-MP.phar/, string C:\Users\NPStudent\Pocketmine servers\ColorMatch3\, string C:\Users\NPStudent\Pocketmine servers\ColorMatch3\plugins\) [18:17:12] [Server thread/DEBUG]: #19 (1): require(string phar://C:/Pocketmine servers/ColorMatch3/PocketMine-MP.phar/src/pocketmine/PocketMine.php) if I add it, the client crashes, what am i doing wrong?
You are setting the "eid" as the player's eid. Try using PHP: $pk->eid = Entity::$entityCount++; And to set the block, add this to $pk->metadata: PHP: 20 => [2, 1 /* 1 is the ID of stone *\]
I guess thats the point. Because if entity packet has same eid with player, falling sand will follow player motion/movement. And thats necesary for BlockHunt minigames.
I am not sure, but i don't think thats correct. The server would try to spawn 2 entities with the same id and gives an error or crash. I guess $pk->x = $player->getX() (or $player->x) and so on would make the entity spawning at the same position. But again, i am not sure, maybe you can override the id.