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

Tamed Wolf Collar Colors

Discussion in 'Plugin Help' started by FiberglassCivic, Sep 27, 2017.

  1. FiberglassCivic

    FiberglassCivic Spider Jockey

    Messages:
    39
    GitHub:
    95civicsi
    Hello all. I'm working on Wolves in PureEntitiesX and keep running into issues when setting collar colors. Everything looks correct when the interaction happens, but when you log out and back in the wolf is shaded the color of the collar.

    Minecraft 9_27_2017 7_55_08 AM.png Minecraft 9_27_2017 7_57_21 AM.png

    PHP:
    public function setCollarColor($collarColor) {
            if (
    $this->isTamed()) {
                
    $this->collarColor $collarColor;

                
    // ID may be the reason for collar color bug.
                
    $this->setDataProperty(self::DATA_COLOURself::DATA_TYPE_BYTE$collarColor); // collar color RED (because it's tamed!)
            
    }
        }
    Code can be found here:

    https://github.com/RevivalPMMP/Pure.../pureentities/entity/monster/walking/Wolf.php
     
    TheShinPin likes this.
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Save the colour code in the form of ByteTag in the entity's NBT. Set the colour during Entity::initEntity() from the entity's NBT.
     
    jasonwynn10 and EdwardHamHam like this.
  3. FiberglassCivic

    FiberglassCivic Spider Jockey

    Messages:
    39
    GitHub:
    95civicsi
    Thanks for the info Muqsit. I read through the NBT thread started by Thunder33345.
    https://forums.pmmp.io/threads/how-do-you-properly-set-nbt.1182/

    I'm not sure about how to apply the info you've given me.

    Here are the relevant sections of code:

    PHP:
    public function initEntity() {
            
    parent::initEntity();
            
    $this->fireProof false;
            
    $this->setDamage([0346]);
            
    $this->breedableClass = new BreedingComponent($this);
            
    $this->loadFromNBT();
            
    $this->setAngry($this->isAngry() ? $this->angryValue 0true);
            
    $this->setSitting($this->isSitting());
            
    $this->setTamed($this->isTamed());
            if (
    $this->isTamed()) {
                
    $this->mapOwner();
                if (
    $this->owner === null) {
                    
    PureEntities::logOutput("Wolf($this): is tamed but player not online. Cannot set tamed owner. Will be set when player logs in .."PureEntities::NORM);
                }
            }
            
    $this->setCollarColor($this->getCollarColor());
            
    $this->breedableClass->init();
            
    $this->teleportDistance PluginConfiguration::getInstance()->getTamedTeleportBlocks();
            
    $this->followDistance PluginConfiguration::getInstance()->getTamedPlayerMaxDistance();
        }
    PHP:
    public function loadFromNBT() {
            if (
    PluginConfiguration::getInstance()->getEnableNBT()) {
                if (isset(
    $this->namedtag->Angry)) {
                    
    $this->angryValue = (int)$this->namedtag[self::NBT_KEY_ANGRY];
                }
                if (isset(
    $this->namedtag->CollarColor)) {
                    
    $this->collarColor $this->namedtag[self::NBT_KEY_COLLAR_COLOR];
                }
                if (isset(
    $this->namedtag->Sitting)) {
                    
    $this->sitting $this->namedtag[self::NBT_KEY_SITTING] === 1;
                }
                if (isset(
    $this->namedtag->OwnerName)) {
                    
    $this->ownerName $this->namedtag[self::NBT_SERVER_KEY_OWNER_NAME];
                    
    $this->tamed true;
                }
                if (
    $this->ownerName !== null) {
                    foreach (
    $this->getLevel()->getPlayers() as $levelPlayer) {
                        if (
    strcasecmp($levelPlayer->getName(), $this->namedtag->OwnerName) == 0) {
                            
    $this->owner $levelPlayer;
                            break;
                        }
                    }
                }
            }
            
    $this->breedableClass->saveNBT();
        }
    PHP:
    public function saveNBT() {
            if (
    PluginConfiguration::getInstance()->getEnableNBT()) {
                
    parent::saveNBT();
                
    $this->namedtag->Angry = new IntTag(self::NBT_KEY_ANGRY$this->angryValue);
                
    $this->namedtag->CollarColor = new ByteTag(self::NBT_KEY_COLLAR_COLOR$this->collarColor); // set collar color
                
    $this->namedtag->Sitting = new IntTag(self::NBT_KEY_SITTING$this->sitting 0);
                if (
    $this->getOwnerName() !== null) {
                    
    $this->namedtag->OwnerName = new StringTag(self::NBT_SERVER_KEY_OWNER_NAME$this->getOwnerName()); // only for our own (server side)
                
    }
                if (
    $this->owner !== null) {
                    
    $this->namedtag->OwnerUUID = new StringTag(self::NBT_KEY_OWNER_UUID$this->owner->getUniqueId()->toString()); // set owner UUID
                
    }
            }
            
    $this->breedableClass->saveNBT();
        }
    This is what I currently have with the addition of the code provided in the first post. Should I be doing something different?
     
  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.