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

Need help with drop items in NEW API!

Comments in 'Plugin Development' started by jerlegoman, Jan 18, 2015.

  1. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Hi Im in a bit of a pickle currently. Im starting to begin with NEW API (I know its kinda really late :confused:o_O) but I wanted to update a plugin i was working on in the past called partyinastick and what it basically does is that when put a stick in your hand and then it drops a lot of diamond. Like a drop party in a stick I don't know how to add that in to NEW API.
    if you want to see the OLD API code of this (even though i highly doubt you want to see it) go to my github
    https://github.com/jerlegoman/Party-in-A-Stick. Thanks!
  2. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Im trying to look for the answer. If anyone wants to help you can!
  3. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    ok this is what i got so far
    PHP:
    <?php

    namespace jerlegoman\GuessMyBuildGame;

    use 
    pocketmine\plugin\PluginBase;

    class 
    GuessMyBuildGame extends PluginBase{
        public function 
    onCommand(CommandSender $sender,$playerCommand $command$label, array $args){
        if(
    strtolower($command->getName()) === "test"){
                
    /* @var $player type */
                
    $addItem $player->getInventory()->addItem("200");
            return 
    true;
        }

        return 
    false;
    }
    }
    Any Tips?!
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    use pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\item\Stick;

    public function 
    onEquip(PlayerItemHeldEvent $e){
        if(
    $e->getItem() instanceof Stick){
           
    $e->getPlayer()->getInventory()->addItem(Item::get(Item::DIAMOND0$count /* how many diamonds you want to give */));
        }
    }
    Also, you shouldn't be using "quotes" for numbers.
  5. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Ok but how do I make it that it drops as an entity not that it goes directly in to the inventory
  6. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    ok I have been looking through the PocketMine-NEW API and i found this
    PHP:
        public function spawnTo(Player $player){
            
    $pk = new AddItemEntityPacket();
            
    $pk->eid $this->getId();
            
    $pk->$this->x;
            
    $pk->$this->y;
            
    $pk->$this->z;
            
    $pk->yaw $this->yaw;
            
    $pk->pitch $this->pitch;
            
    $pk->roll 0;
            
    $pk->item $this->getItem();
            
    $player->dataPacket($pk);
            
    $player->addEntityMotion($this->getId(), $this->motionX$this->motionY$this->motionZ);
            
    parent::spawnTo($player);
        }
    }
    How would i do this to make the item drop any tips?
  7. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    NVM I'm going to see if i can do it with this from the pocket mine api
    PHP:
        public function kill(){
            if(
    $this->dead){
                return;
            }
            
    parent::kill();
            
    $this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this$this->getDrops()));
            foreach(
    $ev->getDrops() as $item){
                
    $this->getLevel()->dropItem($this$item);
  8. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Ok is this correct
    PHP:
    <?php

    namespace jerlegoman\PartyInAStick;

    use 
    pocketmine\plugin\PluginBase;

    class 
    PartyInAStick extends PluginBase{
    public function 
    onEquip(PlayerItemHeldEvent $e){
        if(
    $e->getItem() instanceof Stick){
           
    $e->getLevel()->dropItem(264);
        }
    }
  9. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Why does no one want to help?
  10. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Hello? lol
  11. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    251
    Minecraft User:
    RekkuzaRage
    Hi.
    jerlegoman likes this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Because nobody who is online knows how to help maybe?
    Don't you think you didn't pass some info to dropItem()?
    where to drop?
    jerlegoman likes this.
  13. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Lol I was thinking there was something off
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $e->getLevel()->dropItem($e->getPlayer(), Item::get(264));
  15. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    ok i tried that but it didn't work
    when i try turning on the server with devtools the server displays an error that says an error with the main class
    and i checked everything and i couldn't find it
    if you want to see the full code with the folders and plugin.yml
    go to this link: https://github.com/jerlegoman/PartyInAStick-NEW-API
  16. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    699
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    error :

    PHP:
    namePartyInAStick
    main
    jerlegoman/PartyInAStick/PartyInAStick
    version
    1.0
    api
    1.0.0

    solved :

    PHP:
    namePartyInAStick
    main
    jerlegoman\PartyInAStick\PartyInAStick
    version
    1.0
    api
    1.0.0
    PEMapModder likes this.
  17. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Thanks i will test it out soon!

Share This Page

Advertisement