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

Storing Items

Discussion in 'Help' started by DiamondGamer30, Sep 8, 2018.

  1. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    Hi, I was wondering how do I store items. I'm making an auction house plugin and I'm storing items the following way. I don't know if it's the correct way nor the best way. Just need any tips or fixes if it's incorrect.

    PHP:
    /** @var BigEndianNBTStream */
    public static $nbtWriter;

    public static function 
    encode(Item $item): string {
        return 
    self::$nbtWriter->writeCompressed($item->nbtSerialize());
    }

    public static function 
    decode(string $compression): Item {
        
    $tag self::$nbtWriter->readCompressed($compression);
        if(!
    $tag instanceof CompoundTag) {
            throw new 
    PluginException("Expected a CompoundTag, got " get_class($tag));
        }
        return 
    Item::nbtDeserialize($tag);
    }
     
  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.