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

Set Custom Name to a chest.

Comments in 'Plugin Development' started by RumDaDuMCPE, Oct 20, 2016.

  1. RumDaDuMCPE
    Offline

    RumDaDuMCPE New Member

    Joined:
    Oct 18, 2016
    Posts:
    12
    Minecraft User:
    RumDaDuMCPE
    PHP:
    class Main extends PluginBase implements Listener{
            public function 
    onEnable() {
                    
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }
            public function 
    onMove(PlayerMoveEvent $e) {
                    
    $p $e->getPlayer();
                    if (
    $p->isOp()) {
                            
    $p->getLevel()->setBlock(new Vector3($p->x$p->2$p->z), Block::get(Block::CHEST),true,false);
                            
    $nbt = new CompoundTag("", [
                            new 
    ListTag("Items", []),
                            new 
    StringTag("id"Tile::CHEST),
                            new 
    IntTag("x"floor($p->x)),
                            new 
    IntTag("y"floor($p->2)),
                            new 
    IntTag("z"floor($p->z))
                            ]);
                            
    $nbt->Items->setTagType(NBT::TAG_Compound);
                            
    $tile Tile::createTile("Chest"$p->getLevel()->getChunk($p->>> 4$p->>> 4), $nbt);
                            
    $p->addWindow($tile->getInventory());
                    }
            }
    }
    This works like a charm, but I can't find a way to set a Custom Name to the chest.
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Just add a StringTag for the custom name.
    PHP:
    new StringTag("CustomName""My custom chest")
    PocketKiller likes this.
  3. RumDaDuMCPE
    Offline

    RumDaDuMCPE New Member

    Joined:
    Oct 18, 2016
    Posts:
    12
    Minecraft User:
    RumDaDuMCPE
    Hey! Thanks, Bukkit! I appreciate it :D

    I updated the code and now it doesn't work, any idea why? it gives no errors on console as well.

    PHP:
    class Main extends PluginBase implements Listener{
            public function 
    onEnable() {
                    
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }
            public function 
    onMove(PIE $e) { //PlayerInteractEvent as PIE
                    
    $p $e->getPlayer();
                    if (
    $e->getAction() == PIE::RIGHT_CLICK_AIR || $e->getAction() == PIE::LEFT_CLICK_AIR) {
                                    if (
    $e->getItem()->getId() == 176) {
                                            
    $p->getLevel()->setBlock(new Vector3($p->x$p->2$p->z), Block::get(Block::CHEST),true,false);
                                            
    $nbt = new CompoundTag("", [
                                            new 
    ListTag("Items", []),
                                            new 
    StringTag("CustomName""My custom chest"),
                                            new 
    StringTag("id"Tile::CHEST),
                                            new 
    IntTag("x"floor($p->x)),
                                            new 
    IntTag("y"floor($p->2)),
                                            new 
    IntTag("z"floor($p->z))
                                            ]);
                                            
    $nbt->Items->setTagType(NBT::TAG_Compound);
                                            
    $tile Tile::createTile("Chest"$p->getLevel()->getChunk($p->>> 4$p->>> 4), $nbt);
                                            
    $p->addWindow($tile->getInventory());
                                    }
                            }
                    }
            }
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit

Share This Page

Advertisement