How can i drop item with names?

Discussion in 'Development' started by RiseMCPE, May 19, 2021.

  1. RiseMCPE

    RiseMCPE Creeper

    Messages:
    3
    I maked one rate plugin. When players break cobblestone or stone this plugin drops ores and cases. But I couldn't edit the item names. How can i change dropping item names?

    Code:
          case 5:
            $dusur->dropItem($blok,Item::get(131):setCustomName("test"));
            $oyuncu->sendPopup("dropped case!");
            break;
     
  2. RiseMCPE

    RiseMCPE Creeper

    Messages:
    3
    Any help?
     
  3. ErikX

    ErikX Baby Zombie

    Messages:
    116
    GitHub:
    ErikPDev

    Attached Files:

  4. RiseMCPE

    RiseMCPE Creeper

    Messages:
    3
    I dont understand. I am new. Pls fix and send me. :(

    PHP:
    <?php

    namespace androcyber;

    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\entity\object\ItemEntity;

    class 
    oran extends PluginBase implements Listener {

      public function 
    onEnable() : void{
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
      }

      public function 
    onBreak(BlockBreakEvent $event){
        
    $oyuncu $event->getPlayer();
        
    $blok $event->getBlock();
        
    $dusur $oyuncu->getLevel();
        
    $item $event->getItem();
          if(
    $blok->getId() == "4" || $blok->getId() == "1"){

        
    $oran rand(0,270);

        switch(
    $oran){
          case 
    0:
          
    $dusur->dropItem($blok,Item::get(264));
          
    $oyuncu->sendPopup("elmas düşürdün!");
          break;
          case 
    1:
          
    $dusur->dropItem($blok,Item::get(265));
          
    $oyuncu->sendPopup("demir düşürdün!");
          break;
          case 
    2:
          
    $dusur->dropItem($blok,Item::get(266));
          
    $oyuncu->sendPopup("altın düşürdün!");
          break;
          case 
    3:
          
    $dusur->dropItem($blok,Item::get(388));
          
    $oyuncu->sendPopup("zümrüt düşürdün!");
          break;
          case 
    4:
          
    $dusur->dropItem($blok,Item::get(263));
          
    $oyuncu->sendPopup("kömür düşürdün!");
          break;
          case 
    5:
            
    $dusur->dropItem($blok,Item::get(131));
            
    $this->setNameTag("Hi!");
            
    $this->setNameTagVisible(true);
            
    $this->setNameTagAlwaysVisible(true);
            
    $oyuncu->sendPopup("kasa anahtarı düşürdün!");
            break;
          }
        }
      }
    }

     
    ?>
     
  5. ErikX

    ErikX Baby Zombie

    Messages:
    116
    GitHub:
    ErikPDev
    You want to set the item name? Extend the ItemEntity from Class Item and modify the function named entityBaseTick,
    Then you can set the nametag since it's an entity.

    On the main file you'll need to register it like this
    PHP:
    Entity::registerEntity(Item::class, true, ["Item""minecraft:item"]);
    It's pretty simple.
    An example is on this github page.
    https://github.com/ErikPDev/ItemsDropped/tree/main/src/ErikPDev/ItemsDropped
     
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    536
    dropItem will return the item entity, this will do
    PHP:
    $entity=$dusur->dropItem($blok,Item::get(131));
            
    $entity->setNameTag("Hi!");
            
    $entity->setNameTagVisible(true);
            
    $entity->setNameTagAlwaysVisible(true);
     
    ErikX likes this.

Share This Page

  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.