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

setItemInHand on Human

Comments in 'Plugin Development' started by Cristalix, Jul 25, 2016.

  1. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    Can't setItemInHand on Human :(
    Armor is creating, but Hand is empty
    PHP:
            $player $event->getPlayer();
             
               
    $npc = new Human($player->chunk,
    new 
    CompoundTag("", [
      
    "Pos" => new ListTag("Pos", [
           new 
    DoubleTag(""$player->getX()),
           new 
    DoubleTag(""$player->getY()),
           new 
    DoubleTag(""$player->getZ())
       ]),
       
    "Motion" => new ListTag("Motion", [
           new 
    DoubleTag(""0),
           new 
    DoubleTag(""0),
            new 
    DoubleTag(""0)
        ]),
        
    "Rotation" => new ListTag("Rotation", [
             new 
    FloatTag(""$player->getYaw()),
             new 
    FloatTag(""$player->getPitch())
         ]),
         
    "Skin" => new CompoundTag("Skin", [
                
    "Data" => new StringTag("Data"$player->getSkinData())
         ])
    ]
    ));
    $npc->setNameTag(TextFormat::GOLD.'Hunger Game');
    $npc->spawnToAll();
    $this->getServer()->broadcastMessage($npc->getInventory()->getItemInHand()->getId());
    $npc->getInventory()->setHelmet(Item::get(298));
    $npc->getInventory()->setChestplate(Item::get(299));
    $npc->getInventory()->setLeggings(Item::get(300));
    $npc->getInventory()->setBoots(Item::get(301));
    $npc->getInventory()->setItemInHand(Item::get(276));
              }
  2. Extreme_Heat
    Offline

    Extreme_Heat Active Member

    Joined:
    Apr 19, 2016
    Posts:
    76
    Minecraft User:
    Extreme_Heat
    This probably has to do with getHotbarSlotIndex() returning -1 (not holding anything). Try setting the item manually to a slot and changing the player's selected hotbar slot to the item's index.

Share This Page

Advertisement