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

Structure Block NBT

Discussion in 'Development' started by NickteeChunky, Oct 31, 2020.

  1. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    So I'm having trouble applying NBT to structure blocks. I've registered the block and the tile with my own NBT and for some reason, whenever I place the block, I see the default 5x5x5 structure block diagram for a split second and then it disappears.

    Thanks in advance.

    Take a look:

    Main File

    PHP:
            Tile::registerTile(StructureTile::class, ["StructureBlock""minecraft:structure_block"]);
            
    BlockFactory::registerBlock(new StructureBlock(), false);
    Tile


    PHP:
    class StructureTile extends Spawnable {

        private 
    $nbt;

        public function 
    __construct(Level $levelCompoundTag $nbt)
        {
            
    parent::__construct($level$nbt);
        }

        protected function 
    readSaveData(CompoundTag $nbt) : void{

        }

        protected function 
    writeSaveData(CompoundTag $nbt) : void{

        }

        protected function 
    addAdditionalSpawnData(CompoundTag $nbt) : void{

        }

        protected static function 
    createAdditionalNBT(CompoundTag $nbtVector3 $pos, ?int $face null, ?Item $item null, ?Player $player null) : void{
            if(
    $item !== null){
                
    $nbt->setByte('keepPacked'1);
                
    $nbt->setString('name''test');
                
    $nbt->setString('author''?');
                
    $nbt->setString('metadata''');

                
    $nbt->setInt('posX'$pos->x);
                
    $nbt->setInt('posY'$pos->y);
                
    $nbt->setInt('posZ'$pos->z);
                
    $nbt->setInt('sizeX'5);
                
    $nbt->setInt('sizeY'5);
                
    $nbt->setInt('sizeZ'5);

                
    $nbt->setString('rotation''NONE');
                
    $nbt->setString('mirror''NONE');
                
    $nbt->setString('mode''DATA');

                
    $nbt->setByte('ignoreEntities'1);
            }
        }
    }
    Block


    PHP:
    class StructureBlock extends Solid {

        protected 
    $id Block::STRUCTURE_BLOCK;

        public function 
    __construct() {
            
    parent::__construct($this->id0'Structure Block'252);
        }

        public function 
    place(Item $itemBlock $blockReplaceBlock $blockClickedint $faceVector3 $clickVectorPlayer $player null): bool {
            
    $this->getLevel()->setBlock($blockReplace$thistruetrue);
            
    $x $blockReplace->getX();
            
    $y $blockReplace->getY();
            
    $z $blockReplace->getZ();
            
    $pos = new Position($x$y$z);
            
    $nbt = new CompoundTag("", [
                new 
    StringTag(Tile::TAG_ID"StructureBlock"),
                new 
    IntTag(Tile::TAG_X, (int)$this->x),
                new 
    IntTag(Tile::TAG_Y, (int)$this->y),
                new 
    IntTag(Tile::TAG_Z, (int)$this->z),

                new 
    ByteTag('keepPacked'1),
                new 
    StringTag('name''test'),
                new 
    StringTag('author''?'),
                new 
    StringTag('metadata'''),

                new 
    IntTag('posX'$pos->x),
                new 
    IntTag('posY'$pos->y),
                new 
    IntTag('posZ'$pos->z),
                new 
    IntTag('sizeX'5),
                new 
    IntTag('sizeY'5),
                new 
    IntTag('sizeZ'5),

                new 
    StringTag('rotation''NONE'),
                new 
    StringTag('mirror''NONE'),
                new 
    StringTag('mode''DATA'),
                new 
    ByteTag('ignoreEntities'1),
            ]);
            
    Tile::createTile("StructureBlock"$this->getLevel(), $nbt);
            return 
    true;
        }
    }
     
  2. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
  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.