Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help spawning falling sand

Comments in 'Plugin Development' started by wolfdale, Aug 20, 2015.

  1. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    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->$player->x;
            
    $pk->$player->y;
            
    $pk->$player->z;
            
    $pk->did = -$blockId;
            
    $pk->metadata = [
            
    DATA_FLAGS => [DATA_TYPE_BYTE0],
            
    DATA_AIR => [DATA_TYPE_SHORT300],
            
    DATA_NAMETAG => [DATA_TYPE_STRING""],
            
    DATA_SHOW_NAMETAG => [DATA_TYPE_BYTE1],
            
    DATA_SILENT => [DATA_TYPE_BYTE0],
            
    DATA_NO_AI => [DATA_TYPE_BYTE0],
            ];

            foreach(
    $player->getLevel()->getPlayers() as $p)
            {
                
    $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
            }
  2. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    656
    Plugins:
    1
    Minecraft User:
    jojoe77777
    What does
    do?
  3. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    I guess it sets the blockid of the falling sand entity?
  4. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    656
    Plugins:
    1
    Minecraft User:
    jojoe77777
    But why does it have "-"?
  5. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Actually i didnt know what $pk->did sets :p
    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? :)
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Because that's the MCPE protocol. No reason. Because tommo likes it.
    CrazedMiner likes this.
  7. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    656
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Ok.. that's strange.
    Legoboy0215 likes this.
  8. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    if I dont add this:
    PHP:
    $pk->metadata = [
            
    DATA_FLAGS => [DATA_TYPE_BYTE0],
            
    DATA_AIR => [DATA_TYPE_SHORT300],
            
    DATA_NAMETAG => [DATA_TYPE_STRING""],
            
    DATA_SHOW_NAMETAG => [DATA_TYPE_BYTE1],
            
    DATA_SILENT => [DATA_TYPE_BYTE0],
            
    DATA_NO_AI => [DATA_TYPE_BYTE0],
            ];
    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?
    Legoboy0215 likes this.
  9. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    656
    Plugins:
    1
    Minecraft User:
    jojoe77777
    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 is the ID of stone *\]

    Legoboy0215 and CrazedMiner like this.
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    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.
  11. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    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.
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    I've made Disquise plugin so i know. And im not spawning an entity but only the packet.

Share This Page

Advertisement