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

Solved How to add custom name to virtual inventory?

Discussion in 'Development' started by Enes5519, Aug 29, 2017.

  1. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    Code:
    $tile = Tile::createTile("SanalSandik", $level = $o->getLevel(), new CompoundTag("", [
                new StringTag("id", Tile::CHEST),
                new StringTag("CustomName", $isim),
                new IntTag("x", (int) $o->x),
                new IntTag("y", (int) $o->y + 2),
                new IntTag("z", (int) $o->z)
            ]));
            if(!$tile instanceof SanalSandik) return false;
            $this->replacement();
            $inventory = new SanalEnvanter($tile);
            $o->addWindow($inventory);
    Specify custom name, even though the inventory is still the name of "Chest".
     
    Last edited: Aug 29, 2017
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Please read the README of this forum, the very first line of the Don'ts:
     
    Karanpatel567, Muqsit and jasonwynn10 like this.
  3. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    Sorry fixed.
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    You're just looking to rename a chest inventory?
     
  5. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    // create the chest tile
    /** @var \pocketmine\nbt\tag\CompoundTag $nbt */
    $nbt = new \pocketmine\nbt\tag\CompoundTag("", [
       new \
    pocketmine\nbt\tag\ListTag("Items", []),
       new \
    pocketmine\nbt\tag\StringTag("id", \pocketmine\tile\Tile::CHEST),
       new \
    pocketmine\nbt\tag\StringTag("CustomName""Insert Custom Name Here"),
       new \
    pocketmine\nbt\tag\IntTag("x"$this->x),
       new \
    pocketmine\nbt\tag\IntTag("y"$this->y),
       new \
    pocketmine\nbt\tag\IntTag("z"$this->z)
    ]);
    $nbt->Items->setTagType(\pocketmine\nbt\NBT::TAG_Compound);
    /** @var \pocketmine\tile\Chest $chest */
    $chest = \pocketmine\tile\Tile::createTile(\pocketmine\tile\Tile::CHEST$level$nbt);

    // send player the inventory
    /** @var \pocketmine\Player $player */
    $player->addWindow($chest->getInventory());
     
    ProjectInfinity likes this.
  7. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    I know that already. I pointed out that does not work in virtual inventory.

    Code:
    class SanalEnvanter extends ChestInventory
    
    class SanalSandik extends \pocketmine\tile\Chest
     
  8. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    virtual meaning...?
     
  9. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    Fake Tile and Inventory
     
  10. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
    Can I see your fake Tile and Inventory code.
     
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Send SanalSandik and SanalEnvanter classes
     
  12. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    PHP:
    class SanalSandik extends Chest {

        protected 
    $cevir;

        public function 
    __construct(Level $levelCompoundTag $nbt){
            
    parent::__construct($level$nbt);
            
    $this->inventory = new SanalEnvanter($this);
            
    $this->cevir= [$this->getBlock()->getId(), $this->getBlock()->getDamage()];
        }


        public function 
    spawnTo(Player $player){
        }

        public function 
    spawnToAll(){
        }
    }
    PHP:
    class SanalEnvanter extends ChestInventory {

        public function 
    __construct(Chest $tile){
            
    parent::__construct($tile);
        }

        public function 
    onClose(Player $who){
            
    $this->holder->sendReplacement($who);
            
    $this->holder->close();
        }
    }
     
  13. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
    PHP:
    class SanalSandik extends Chest {

        protected 
    $cevir;

        public function 
    __construct(Level $levelCompoundTag $nbt){
            
    parent::__construct($level$nbt);
            
    $this->inventory = new SanalEnvanter($this);
            
    $this->cevir= [$this->getBlock()->getId(), $this->getBlock()->getDamage()];
        }

        private function 
    getReplacement() : Block {
            return 
    Block::get(...$this->cevir);
        }

        public function 
    sendReplacement(Player $player) {
            
    $block $this->getReplacement();
            
    $block->= (int) ($this->x);
            
    $block->= (int) ($this->y);
            
    $block->= (int) ($this->z);
            
    $block->level $this->getLevel();

            if(
    $block->level !== null) {
                
    $block->level->sendBlocks([$player], [$block]);
            }
        }

        public function 
    addAdditionalSpawnData(CompoundTag $nbt) {

        }
    Try this when using Custom Tiles. You didn't have a Replacement inventory, and addAdditionalSpawnData() should add the CustomName NBT.
     
    Enes5519 likes this.
  14. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    SendReplacement already exists. Just not add.
    Can I just addAdditionalSpawnData?
     
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    No, check PlayerVaults again.
     
    SleepSpace9 likes this.
  16. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    Oh thanks. I will try this.
     
  17. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
  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.