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

Wither bar

Discussion in 'Development' started by Ragnok123, Nov 18, 2016.

  1. Ragnok123

    Ragnok123 Silverfish

    Messages:
    22
    GitHub:
    Ragnok123
    Hello guys. How make wither bar with custom name? In n*kkit is somethink like BossEventPacket, but how in PM?
     
    Jesse2061 likes this.
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    XenialDan and HimbeersaftLP like this.
  3. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    that's a plugin. which uses the api above...
     
    applqpak, HimbeersaftLP and SOFe like this.
  5. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    yes, he can use bossbar api and by bossannouncement change bossbar text
     
  6. imYannic

    imYannic Baby Zombie

    Messages:
    113
    PMMP doesn't have the BossEventPacket implemented yet, so you need to make the packets by yourself.
    I show you how to make a bossbar:

    1. Make a file, BossEventPacket.php
    PHP:
    <?php
    namespace Core;
    use 
    pocketmine\network\protocol\DataPacket;
    class 
    BossEventPacket extends DataPacket{
        const 
    NETWORK_ID 0x4a;
        public 
    $eid;
        public 
    $state;
        public function 
    decode(){
            
    $this->eid $this->getUUID();
            
    $this->state $this->getUnsignedVarInt();
        }
        public function 
    encode(){
            
    $this->reset();
            
    $this->putEntityId($this->eid);
            
    $this->putUnsignedVarInt($this->state);
        }
    }
    Change the Core namespace to your plugin's namespace

    2. Add these things to your main plugin:
    PHP:
    public function addWitherBar($p){
    $title "§bMy special wither bar text";

    $pk = new AddEntityPacket();
            
    $pk->eid 9272;
            
    $pk->type 12;
       
    $pk->$p->x;
            
    $pk->$p->2;
            
    $pk->$p->z;
       
    $pk->yaw 0;
       
    $pk->pitch 0;
        
    $pk->metadata = [Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG, -1], Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG<< Entity::DATA_FLAG_SILENT << Entity::DATA_FLAG_INVISIBLE], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT0], 
                    
    Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING$title], Entity::DATA_BOUNDING_BOX_WIDTH => [Entity::DATA_TYPE_FLOAT0], Entity::DATA_BOUNDING_BOX_HEIGHT => [Entity::DATA_TYPE_FLOAT0]];
       

    $p->dataPacket($pk);

    $pk2 = new BossEventPacket();
    $pk2->eid 9272;
    $pk2->state 0;
    $p->dataPacket($pk2);

    }
    It will display a wither bar by spawning an invisible entity to you, used as your boss (keep in mind that MCPE accepts every living entity as your boss)
    $p is a Player object and the eid is 9272 because I want, you can use another random entity ID, but it shouldn't conflict with other entities' IDs.

    3. If your lobby or whereever you want to spawn is is bigger than 32 blocks, then implement this code, this will prevent that the wither bar despawns after a distance of 32.

    PHP:
    public function moveWitherBar($p){
    $pk = new MoveEntityPacket();
    $pk->eid 9272;
    $pk->$p->x;
    $pk->$p->2;
    $pk->$p->z;
    $pk->yaw 0;
    $pk->headYaw 0;
    $pk->pitch 0;
    $p->dataPacket($pk);
    }
    When this function is called, the boss entity will be teleported right above you. I recommend you to call it in a task of 1 - 5 seconds.

    Simply add the wither bar on join:
    PHP:
    public function onPlayerJoin(PlayerJoinEvent $event){
    $this->addWitherBar($event->getPlayer());
    }
    Some credits go to thebigsmileXD.
     
    BEcraft, XenialDan, Skullex and 3 others like this.
  7. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    how to make bossbar with full hp?
     
  8. imYannic

    imYannic Baby Zombie

    Messages:
    113
    It always has full HP when you spawn an entity.
     
    applqpak likes this.
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    maybe he meant not full then
     
  10. imYannic

    imYannic Baby Zombie

    Messages:
    113
    If the entity has no HP:

    1. Create a new class and change the namespace

    PHP:
    <?php
    namespace Core;
    class 
    BossHealth{

      public function 
    getMinValue(){
        return 
    0;
      }
      public function 
    getMaxValue(){
        return 
    10;
      }
      public function 
    getValue(){
        return 
    10;
      }
      public function 
    getName(){
        return 
    "minecraft:health";
      }
      public function 
    getDefaultValue(){
        return 
    0;
      }
    }
    The getValue() function returns 10 because the pig I use as boss has a maxhealth of 10


    2. Paste this right after the AddEntityPacket code in the class where you spawn the wither:

    PHP:
    $pk2 = new UpdateAttributesPacket();
    $pk2->entries[] = new BossHealth();
    $pk2->entityId 9272// here goes your wither id

    $p->dataPacket($pk2);
    Credits still go to thebigsmileXD.
     
    Last edited: Dec 19, 2016
    XenialDan, Skullex and applqpak like this.
  11. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    why not just use: ?
    PHP:
    $id Entity::$entityCount++; 
    BTW @Ragnok123, nukkit is not swear.
     
  12. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    But it is a fork and member treat fork like swear
     
  13. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    its not a fork
     
    Last edited: Dec 14, 2016
  14. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    spoon or whatever you call but lets not get too offtopic
     
  15. SergeyIvanov

    SergeyIvanov Witch

    Messages:
    59
    GitHub:
    sergeyivanov14
    Can you give full plugin?C
     
  16. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Its in my Core plugin so I cant.
    Try XenialDan's bossbar plugin on github
     
  17. XenialDan

    XenialDan Baby Zombie

    Messages:
    141
    GitHub:
    thebigsmilexd
    Great thanks for referring me so often!
    BossBarAPI is fully core/spoon independ, it should work on all cores, because: It adds the network classes itself, it has attribute stuff (currently missing in pmmp) to set health, you can set he name etc etc.
     
    HimbeersaftLP likes this.
  18. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    I did exactly what is written but the wither spawn without life and $title :(
    Please help me :p
     
  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.