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

Throw items

Discussion in 'Development' started by #A6543, Jan 17, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    Hi. Does someone know how to throw an item onInteract with a stick?
     
  2. Jesse2061

    Jesse2061 Silverfish

    Messages:
    19
    You mean...
    A player, handing a stick, tap the block, and plugin can let him throw his stick?
     
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    I mean what I wrote...

    If a player holds a stick, it will throw an item like a snowball
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

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

    #A6543 Zombie

    Messages:
    267
    I already tried this:
    PHP:
    if($event->getItem()->getId() === 369)
                        {
      
              
                
    $aimPos $player->getDirectionVector();
                            
    $nbt = new CompoundTag("", [
                                
    "Pos" => new Enum("Pos", [
                                    new 
    Double(""$player->x),
                                    new 
    Double(""$player->$player->getEyeHeight()),
                                    new 
    Double(""$player->z)
                                ]),
                                
    "Motion" => new Enum("Motion", [
                                    new 
    Double(""$aimPos->x),
                                    new 
    Double(""$aimPos->y),
                                    new 
    Double(""$aimPos->z)
                                ]),
                                
    "Rotation" => new Enum("Rotation", [
                                    new 
    Float(""$player->yaw),
                                    new 
    Float(""$player->pitch)
                                ]),
                               
    "Health" => new Short("Health"5),
                               
    "Item" => new CompoundTag("Item", [
                                   
    "id" => new Short("id"Item::TNT),
                                   
    "Damage" => new Short("Damage"0),
                                   
    "Count" => new Byte("Count"1),
                               ]),
                               
    "PickupDelay" => new Short("PickupDelay"0x7F),
                            ]);
                            
    $f 1.5;
                            
    $tntEntity::createEntity("Item"$player->getLevel()->getChunk($player->getFloorX() >> 4$player->getFloorZ() >> 4), $nbt$player);
                            
    $tnt->setMotion($tnt->getMotion()->multiply($f));
                            
    /*
                            $player->getLevel()->addSound(new LaunchSound($player), 
                            */
                            
    $player->getViewers();
                            
    $tnt->spawnToAll();
     
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    PHP:
    <?php
    /** 
     * @author robske_110
     * @license GPLv3
     * NO WARRANTY
     */
    #WAY 1
    $aimPos $player->getDirectionVector();
    $nbt = new CompoundTag("", [
        
    "Pos" => new ListTag("Pos", [
            new 
    DoubleTag(""$player->x),
            new 
    DoubleTag(""$player->$player->getEyeHeight()),
            new 
    DoubleTag(""$player->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)
        ]),
    ]);
    $projectile = new Projectile($player->getLevel()->getChunk($player->getX() >> 4$player->getZ() >> 4), $nbt$player);
    $f 1.5#force
    $projectile->setMotion($projectile->getMotion()->multiply($f));
    $this->level->addSound(new LaunchSound($this), $player->getViewers());       
    $projectile->spawnToAll();
    #WAY 2
    $nbt = new CompoundTag("", [
        
    "Pos" => new ListTag("Pos", [
            new 
    DoubleTag(""$player->x),
            new 
    DoubleTag(""$player->$player->getEyeHeight()),
            new 
    DoubleTag(""$player->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)
        ]),
    ]);
    $projectile Entity::createEntity("Snowball"$player->getLevel()->getChunk($player->getX() >> 4$player->getZ() >> 4), $nbt$player);
    $f 1.5;
    $projectile->setMotion($projectile->getMotion()->multiply($f));
    $projectile->spawnToAll();
    threw this together real quick, code is GPLv3
     
    SavionLegendZzz likes this.
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Worth nothing, there a old hack using on packet receive and then constantly shoot the projectile
    FYI OP you need to word your top post better i originally think you meant to throw some item on the ground when player holds a stick
     
  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.