Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tile orientation

Comments in 'Plugin Development' started by udwarf, May 7, 2016.

  1. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    Hi, guys!

    I'm trying to clone one part of map to another place and stuck with tiles;
    On my map I have some WallSigns. I know how to clone them but I cant find how to define their orientation

    My tile cloning looks like:
    PHP:
        $tile $level->getTile($old_pos);
        
    $level->addTile(cloneTile($new_pos$tile));
        .......
        static function 
    cloneTile(Position $posSign $tile){

                
    $txt $tile->getText();
                
    $nbt = new CompoundTag("", [
                    
    "id" => new StringTag("id"Tile::SIGN),
                    
    "x" => new IntTag("x"$pos->getX()),
                    
    "y" => new IntTag("y"$pos->getY()),
                    
    "z" => new IntTag("z"$pos->getZ()),
                    
    "Text1" => new StringTag("Text1"$txt[0]),
                    
    "Text2" => new StringTag("Text2"$txt[1]),
                    
    "Text3" => new StringTag("Text3"$txt[2]),
                    
    "Text4" => new StringTag("Text4"$txt[3])
                ]);
            }

            return 
    Tile::createTile("Sign"Server::getInstance()->getDefaultLevel()->getChunk($pos->getX() >> 4$pos->getZ() >> 4), $nbt);
        }

    But I guess, that not enough. After such cloning, all wallsigns turned to the one side and often just hangs near the wall in air.
    2f0a8-clip-291kb.jpg
    Does anyone know how to deal with WallSign orientaion?

    Thank you.
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Save signs meta data
    PHP:
    \pocketmine\block\Sign::getDamage()
    To get block from tile it's
    PHP:
    \pocketmine\tile\Tile::getBlock();
    You can save the return into NBT tag and get it back later.
    PHP:
    /** @var \pocketmine\tile\Sign $sign */
    $sign->getBlock()->setDamage($sign->namedtag->Meta);
    Last edited: May 7, 2016
    udwarf likes this.
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Well, the Minecraft Wiki is very useful. http://minecraft.gamepedia.com/Sign#Block_state
  4. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    In this particular case MC Wiky total usless. There are no answers HOW and WHERE to set that facing values

    Wow! What a nasty hack to use Damage for storing Orientation
    Now it works, TY!
    PHP:
    static function cloneTile(Position $posSign $tile){

                
    $meta $tile->getBlock()->getDamage();

                
    $txt $tile->getText();
                
    $nbt = new CompoundTag("", [
                    
    "id" => new StringTag("id"Tile::SIGN),
                    
    "x" => new IntTag("x"$pos->getX()),
                    
    "y" => new IntTag("y"$pos->getY()),
                    
    "z" => new IntTag("z"$pos->getZ()),
                    
    "Text1" => new StringTag("Text1"$txt[0]),
                    
    "Text2" => new StringTag("Text2"$txt[1]),
                    
    "Text3" => new StringTag("Text3"$txt[2]),
                    
    "Text4" => new StringTag("Text4"$txt[3])
                ]);


            
    $new_tile Tile::createTile("Sign"Server::getInstance()->getDefaultLevel()->getChunk($pos->getX() >> 4$pos->getZ() >> 4), $nbt);
            
    $new_tile->getBlock()->setDamage($meta);
            return 
    $new_tile;
        }
    Primus likes this.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Why don't you just use
    PHP:
    $newTile = clone $tile
    Legoboy0215 likes this.
  6. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    This was my first attempt and it doesn't work. The new tile simple doesn't appear in the world.
    PHP:
    $new_tile = clone $tile;
    $new_tile->setComponents($new_pos->getX(), $new_pos->getY(), $new_pos->getZ());
    $level->addTile($new_tile);
    May be I just missed some additional initialisation
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Tile isn't physical object but a meta data holder instead. Tile must be paired with block.
    PHP:
    $level->setBlock($new_pos$new_tile->getBlock()); 
  8. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    I doubt that this will work, because, as I see in the PM sources, that string is equal to $level->setBlock($new_pos, $level->getBlock($old_pos));
    But, I'll try this way.

    As I understood tiles coordinates are stored in CompoundTags in tile's NBT. And after tile cloning these tags are still pointing to the old tile position.
    SetComponents method doesn't modify these tags
    Primus likes this.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    That makes sense. But you can change them anyway
    PHP:
    $new_tile->namedtag->$new_pos->x;

Share This Page

Advertisement