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

namedTag makes Item unusable ?

Discussion in 'Development' started by instantlyta, Jan 8, 2017.

  1. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
    PHP:
    public function test(PlayerLoginEvent $event) {
            
    $item = (new Item(Item::SNOWBALL016"Testy"))->setCustomName("Testy");
            
    $namedTag $item->getNamedTag();
            
    $namedTag->offsetSet("Test", new FloatTag("Test"0.05));
            
    $item->setNamedTag($namedTag);
            
    $p->getInventory()->setItem(0$item);
        }
    This FloatTag makes the Snowball unusable. Please help!
    EDIT: Sometimes (float) 0.0 works!, switched to (float) 0.05
    Using PocketMine #4ace4b9
     
    Last edited: Jan 8, 2017
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    public function test(PlayerLoginEvent $event) {
            
    $item Item::get(Item::SNOWBALL01);
            
    $namedTag = new CompoundTag("", []);
            
    $namedTag->display = new CompoundTag("display", [
                
    "Name" => new StringTag("Name""Testy")
            ]);
            
    $namedTag->Test = new FloatTag("Test"0.05);
            
    $item->setNamedTag($namedTag);
            
    $p->getInventory()->setItem(0$item);
        }
     
  3. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
    This made Windows 10 Edition couldn't hold the item (Air instead), and unshootable Snowball on PE.
     
  4. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
    I've just solved this by using this hack before the setItem() function:
    PHP:
    $item->setCompoundTag($item->getCompoundTag());
    This release the cachedNBT and it works. Now i need an explaination for this (and more convenient code if available).
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Glad you solved it.
    I use the code that I just provided in many cases and it works fine for me.
     
  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.