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

CompoundTag not supported

Discussion in 'Development' started by DanDen, Jun 13, 2018.

  1. DanDen

    DanDen Spider

    Messages:
    11
    Hi, what's wrong with my code, does not the compound tag seem to work?

    PHP:
        public function getItemTier($id$meta$tier) : Item{
            
    $block = new Item($id$meta);
            
    $nbt $block->getNamedTag() ?? new CompoundTag("", []);
            
    $nbt->tier = new StringTag("tier"$tier);
            
    $block->setCompoundTag($nbt);
            return 
    $block;
        }
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Not sure this will fix it but try

    PHP:
      public function getItemTier($id$meta$tier) : Item{
            
    $block = new Item($id$meta);
            
    $nbt $block->getNamedTag() ?? new CompoundTag("", []);
            
    $nbt->tier $nbt->setString("tier"$tier);
            
    $block->setCompoundTag($nbt);
            return 
    $block;
     
  3. DanDen

    DanDen Spider

    Messages:
    11
    Not work, the problem i think is NBT
     
  4. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Use CompoundTag::setString().
    Also:
    - Always prefer Item::get() over new Item().
    - The ?? operator is not needed because Item::getNamedTag() must always return a CompoundTag.

    PHP:
    public function getItemTier($id$meta$tier) : Item{
        
    $block Item::get($id$meta);
        
    $nbt $block->getNamedTag();
        
    $nbt->setString("tier"$tier);
        return 
    $block;
    }
     
    Last edited: Jun 13, 2018
  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.