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

Throw snowball

Discussion in 'Development' started by #A6543, Mar 4, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    I know how I can spawn a snowball. But how can I throw it?
    PHP:
    $pos $player->getPosition();
            
    $nbt = new CompoundTag("",[
                new 
    ListTag("Pos",[
                    new 
    DoubleTag("",$pos->getX()),
                    new 
    DoubleTag("",$pos->getY()+$player->getEyeHeight()),
                    new 
    DoubleTag("",$pos->getZ()),
                    ]),
                new 
    ListTag("Motion", [
                    new 
    DoubleTag(""2*-sin($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)),
                    new 
    DoubleTag(""2*-sin($player->pitch 180 M_PI)),
                    new 
    DoubleTag(""2*cos($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)),
                    ]),
                new 
    ListTag("Rotation", [
                    new 
    FloatTag(""lcg_value() * 360),
                    new 
    FloatTag("",0),
                    ])
                ]);
      
    $entity Entity::createEntity('Snowball'$pos->getLevel()->getChunk($pos->getX() >> 4$pos->getZ() >> 4), $nbt);
            
    $entity->spawnToAll();
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    let me throw a blind guess, setmotion
     
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    How? If I use for example Pig in my code, it works. But I want to throw a snowball
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    use setmotion on $entity?
    ($entity->setMotion(%args%);
    if that is what you want to know?
     
  5. #A6543

    #A6543 Zombie

    Messages:
    267
    And how can I check if it hits the ground? (And get cords)
     
  6. #A6543

    #A6543 Zombie

    Messages:
    267
    The snowball despawns instantly
    PHP:
    $nbt = new CompoundTag("",[
                new 
    ListTag("Pos",[
                    new 
    DoubleTag("",$pos->getX()),
                    new 
    DoubleTag("",$pos->getY()+$player->getEyeHeight()),
                    new 
    DoubleTag("",$pos->getZ()),
                    ]),
                new 
    ListTag("Motion", [
                    new 
    DoubleTag(""2*-sin($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)),
                    new 
    DoubleTag(""2*-sin($player->pitch 180 M_PI)),
                    new 
    DoubleTag(""2*cos($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)),
                    ]),
                new 
    ListTag("Rotation", [
                    new 
    FloatTag(""lcg_value() * 360),
                    new 
    FloatTag("",0),
                    ])
                ]);
      
    $entity Entity::createEntity('Snowball'$pos->getLevel()->getChunk($pos->getX() >> 4$pos->getZ() >> 4), $nbt);
    $entity->setMotion($entity->getMotion()->multiply(2));   
            
    $entity->spawnToAll();
     
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    entity despawn event?
     
  8. #A6543

    #A6543 Zombie

    Messages:
    267
    It doesn't throw the snowball. It only spawns and despawns. I want to throw in it
     
  9. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    use @Thunder33345 method for throwing it
    use the EntityDespawnEvent for checking if it despawns
     
  10. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    what about entity collide event? (not exact)
    you can add a custom NBT to be able to determine if it's custom snowball spawned when you check for the NBT
     
  11. #A6543

    #A6543 Zombie

    Messages:
    267
    Lol look at my code -_-

    It isn't working. Or am I using setMotion wrong?
     
  12. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
  13. #A6543

    #A6543 Zombie

    Messages:
    267
    I don't know why, but it isn't working

    PHP:
    $pos $player->getPosition();

    $aimPos = new Vector3(
          -
    sin($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI),
          -
    sin($player->pitch 180 M_PI),
          
    cos($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)
         );
    $nbt = new CompoundTag("", [
           
    "Pos" => new ListTag("Pos", [
            new 
    DoubleTag(""$pos->x),
            new 
    DoubleTag(""$pos->$player->getEyeHeight()),
            new 
    DoubleTag(""$pos->z)
           ]),
           
    "Motion" => new ListTag("Motion", [
            new 
    DoubleTag(""$aimPos->x),
            new 
    DoubleTag(""$aimPos->y),
            new 
    DoubleTag(""$aimPos->z)
           ]),
           
    "Rotation" => new ListTag("Rotation", [
            new 
    FloatTag(""$player->yaw),
            new 
    FloatTag(""$player->pitch)
           ]),
          ]);
          
    $f 1.5;
          
    $snowball Entity::createEntity("Snowball"$pos->getLevel()->getChunk($pos->getX() >> 4$pos->getZ() >> 4), $nbt);
          
    $snowball->setMotion($snowball->getMotion()->multiply($f));
            
    $snowball->spawnToAll();
     
  14. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    WTF? $pos->getLevel()->getChunk($pos->getX() >> 4, $pos->getZ() >> 4) is that anywhere in the code i showed you? no. and there is a reason for that https://github.com/pmmp/PocketMine-MP/commit/c21197ef176166b1c2c19b091cf84664aa878c00
     
  15. #A6543

    #A6543 Zombie

    Messages:
    267
  16. #A6543

    #A6543 Zombie

    Messages:
    267
    Oh I had an old version. Now it works! And how can I check the cord where the snowball despawns?
     
  17. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    On EntityDespawnEvent, get the Entity, check if it is an instance of Snowball, then get the position of it.
     
  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.