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; }
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;
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;}