1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Many Packets Make Minecraft Crash

Discussion in 'Development' started by tungstenvm, Aug 17, 2020.

  1. tungstenvm

    tungstenvm Witch

    Messages:
    54
    keyword: FloatingText floating text texts floatingtingtexts

    I had been trying to send about 15+ floatingtexts and this made my minecraft crash
    As i see more than 15 packets sending to a player at the same time will make the client crash the game

    I sent those floating text by a foreach loop

    PHP:
        public $array = [];//contains floatingtextparticle class
        
    public function onJoin(PlayerJoinEvent $e)
        {
            foreach (
    $this->array as $ftp) {
                
    #$e->getPlayer()->getLevel()->addParticle($ftp, [$player]);
                
    $pks $ftp->encode();
                foreach(
    $pks as $pk){
                    
    $e->getPlayer()->sendDataPacket($pk);
                }
            }
        }
    Does anyone know how to prevent this or some way to send many floatingtexts to a player
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    I am sending floating text using addplayerpackets. This method works fine and don't crash client. You can check my api here.
     
  3. tungstenvm

    tungstenvm Witch

    Messages:
    54
    ur code work so good, thanks
    but however when i have new a large amount of floatingtexts displaying, some other will be removed automaticaly ,is it from client side
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    How did you use the api?
     
  5. tungstenvm

    tungstenvm Witch

    Messages:
    54
    i created a new floatingtextclass which extends the original one with some extra function

    PHP:
    class FloatingTextParticle extends \pocketmine\level\particle\FloatingTextParticle
    {
        public function 
    sendPk(){
            if(
    $this->entityId === null){
                
    $this->entityId Entity::$entityCount++;
            }

            
    $pk = new AddPlayerPacket();
            
    $pk->username $this->text;
            
    $pk->uuid UUID::fromRandom();
            
    $pk->entityRuntimeId $this->entityId;
            
    $pk->entityUniqueId $this->entityId;
            
    $pk->position $this->asVector3();
            
    $pk->item Item::get(0);
            
    $pk->metadata = [
                
    Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG<< Entity::DATA_FLAG_IMMOBILE],
                
    Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT0.01]
            ];
            return 
    $pk;
        }

        public function 
    removePk(){
            
    $pk = new RemoveActorPacket();
            
    $pk->entityUniqueId $this->entityId;
            return 
    $pk;
        }
    So i dont change any original code for this new change,all i have to do is change these

    PHP:
    //"Add particle" method:
    $level->addParticle($ftp,[$player]);
    //======Replaced into====
    $pk $ftp->sendPk();
    $player->sendDataPacket($pk);

    PHP:
    //"Remove particle" method:
    $ftp->setInvisible();
    $level->addParticle($ftp,[$player]);
    $ftp->setInvisible(false);
    //======Replaced into======
    $pk $ftp->removePk();
    $player->sendDataPacket($pk);
    When i want to change the ftp text, i send the same ftp class with the username changed
     
  6. tungstenvm

    tungstenvm Witch

    Messages:
    54
    with many these packet my mc windows10 dont see any lag but my phone is just going to be paralysed, and sometime it still crash the client but not often like before
     
  7. tungstenvm

    tungstenvm Witch

    Messages:
    54
    by the way with many floating text, the game will also be very laggy, do y know why, , and can it be prevented.
    the game can be quickly more laggy if there are more floating text, i dont think it can be that lag with just a 10-20 floating text
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.