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

Solved Setting An Item In Hotbar

Comments in 'Plugin Development' started by Tethered_, Jul 1, 2015.

  1. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    How can I get and set the contents of a player's hotbar? I can't figure out how to do anything but move the highlighted slot.
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $human->getInventory()->setItem($indexItem::get($id$damage$amount));
    $index is the slot, starts from 0(first Slot)
    TheBison_ likes this.
  3. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    this is not hotbar, try this: $human->getInventory()->setHotbarSlotIndex($index,$slot);
    index is the slot # of your inventory, $slot is the slot # of your hotbar
    PEMapModder and Tethered_ like this.
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Well, it works for me.
    TheBison_ likes this.
  5. Jon
    Offline

    Jon Active Member Plugin Developer

    Joined:
    Sep 1, 2013
    Posts:
    201
    Plugins:
    3
    Minecraft User:
    Heromine14
    Maybe because if you have an empty inventory the first object of the inventory is automatically the first of the hotbar (if by adding and item to the inventory it adds also to the hotbar)
    CrazedMiner likes this.
  6. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    I made a test plugin to try this out, and I did this:

    PHP:
            $event->getPlayer()->getInventory()->setItem(1Item::get(388));
            
    $event->getPlayer()->getInventory()->setHotbarSlotIndex(14);
    and it still doesn't work...
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why ...->setHotbarSlotIndex(1, 4);? The fourth slot of your inventory is empty.. You set the item on slot 1: ...->setItem(1, Item::get(388));
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I usually just use
    PHP:
    $player->getInventory()->addItem(Item::get($id$damage$amount));
    This would automatically set the item to the players first hotbar slot.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Because the test is wrong. Your second slot in hotbar links to the second slot (1) in the inventory, so inventory changes will directly affect hotbar.
    The problem is, he wants to change the reference inventory slot for the hotbar, not the item of the hotbar.

Share This Page

Advertisement