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

Items

Discussion in 'Facepalm' started by LucGamesDE, May 31, 2017.

  1. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    How can I spawn Items in a level and give them nametags?
     
  2. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
    PHP:
    public function onJoin(PlayerJoinEvent $event){
           
    $this->Items($player);
    }


    public function 
    $items ($player){
      if(
    $player->getLevel()->getName() == "/**level name**/"){
         
    $player->getInventory()->addItem(Item::get(34501)->setCustomName(C::GREEN "/**Custom name here*/"));
            }
    }
    P.S. It's a little messy and I could've written it better though.
     
    Last edited: May 31, 2017
  3. DayKoala

    DayKoala Silverfish

    Messages:
    22
    GitHub:
    daykoala
    public function onJoin(PlayerJoinEvent $event) {

    $player = $event->getPlayer();
    if($player->getLevelByName() == "world") {
    $this->Items($player);
    }
    }

    public function Items(Player $player){

    $item = Item::get(Id,Damage,Count);
    $item->setCustomName("Epic");
    $player->getInventory()->addItem($item);
    }
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    To spawn an Item Entity, you can use $level->dropItem. It requires a Vector3 parameter and an Item parameter. Optionally, you can add Motion to the item and/or a pickup delay. The Item object you use will retain it's NBT tags. If you want to spawn a visible name above the entity, you can use a floating text particle.
     
  5. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    Example?
     
  6. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    PHP:
    //Item
    $player->getLevel()->dropItem(Vector3($player->x$player->y$player-z), Item;;get(Item;;PAPER,0,1));

    //Floating Text
    $player->getLevel()->addParticle(new FloatingTextParticle(Vector3($player->x$player->2$player-z); "This is an example");
     
    LucGamesDE likes this.
  7. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    And how can I remove the 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.