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

addWindow() isn't working?

Discussion in 'Development' started by Jons, Nov 27, 2016.

  1. Jons

    Jons Spider

    Messages:
    14
    GitHub:
    jonsmc
    i recently working on a plugin project related to chest
    But when i try
    PHP:
    $tile $this->getServer()->getPlayer($pname)->getLevel()->getTile(new Vector3($conf->get("x"), $conf->get("y"), $conf->get("z")));
             
    $tile $this->getServer()->getPlayer($pname)->getLevel()->getTile(new Vector3($conf->get("x"), $conf->get("y"), $conf->get("z")));
             
    $this->getServer()->getPlayer("Jons"))->addWindow($tile->getInventory());
    //tile has been confirmed as a chest so i can use $tile->getInventory()
    Nothing happen, none chest window open or any console errors
    Please help
     
  2. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    tell $tile what is $pname
     
  3. Jons

    Jons Spider

    Messages:
    14
    GitHub:
    jonsmc
    $pname is the player name and $tile has explained
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Why is there a double closing bracket? Are you sure the code got executes at all?
     
    Sandertv likes this.
  5. Jons

    Jons Spider

    Messages:
    14
    GitHub:
    jonsmc
    Sorry, that's typo but i fixed, the code has been ran but nothing happen
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It is always good to simplify your code in your question if you are sure about certain values so that others can concentrate on the part that is not working. For example, the part about
    PHP:
    $tile $this->getServer()->getPlayer($pname)->getLevel()->getTile(new Vector3($conf->get("x"), $conf->get("y"), $conf->get("z")));
    is meaningless to us if you have already confirmed that it is working correctly, since you are asking about particular code.

    (Of course, if your problem is related to the rest of your plugin, you should show more information)
     
  7. Jons

    Jons Spider

    Messages:
    14
    GitHub:
    jonsmc
    PHP:
    public function openChest($playername) {

              
    $conf = new Config($this->getDataFolder() ."players/"strtolower($playername) .".yml"Config::YAML, [
             
    "x" => 10000,
             
    "y" => 78,
             
    "z" => 10000,
             
    "level" => "world"
             
    ]);
             
             
    $tile $this->getServer()->getPlayer("Jons")->getLevel()->getTile(new Vector3($conf->get("x"), $conf->get("y"), $conf->get("z")));
             
    $this->getServer()->getPlayer("Jons")->addWindow($tile->getInventory());
    }
     
  8. Aviv

    Aviv Baby Zombie

    Messages:
    156
    You cant addWindow() on a chest that is more than 6 blocks far from the player, id recommend setting a chest 3 blocks under the player and removing it when he closes it, most efficient way
    kinda wish there was a plugin that controls that and you can use its functions to add chest or remove:)
     
    HimbeersaftLP and Sandertv like this.
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    is there any way to add window without adding a chest ex using packets since it is quite inconvenient to add chest below player ex some other player can open it(just because it is under dosent mean it cant be accessed)
    and what would happen if TWO players use it in the same place wont that interfere with it?
     
  10. Aviv

    Aviv Baby Zombie

    Messages:
    156
    you can just disable playerinteractevent on the chest position
     
  11. Aviv

    Aviv Baby Zombie

    Messages:
    156
    and unfortunetly, there is no fake inventory in mcpe like mcpc
     
  12. imYannic

    imYannic Baby Zombie

    Messages:
    113
    You mean 30 blocks? Or did the MCPE devs decrease the distance again?
     
  13. TutoGamerWalid

    TutoGamerWalid Spider Ban Evader

    Messages:
    11
    GitHub:
    wiligangster
    PHP:
      public function openChest($player,$playername){
        
    $block Block::get(54);
        
    $config = new Config($this->getDataFolder() ."players/"strtolower($playername) .".yml"Config::YAML);
        
    $player->getLevel()->setBlock(new Vector3($config['x'], $config['y'], $config['z']), $blocktruetrue);
        
    $nbt = new CompoundTag("", [
          new 
    ListTag("Items", []),
          new 
    StringTag("id"Tile::CHEST),
          new 
    IntTag("x"$config['x']),
          new 
    IntTag("y"$config['y']),
          new 
    IntTag("z"$config['z'])
        ]);
        
    $nbt->Items->setTagType(NBT::TAG_Compound);
        
    $tile Tile::createTile("Chest"$player->getLevel()->getChunk($config['x'] >> 4$config['z'] >> 4), $nbt);

        if(
    $player->getName() === $playername){
        
    $player->addWindow($tile->getInventory());
        }
      }
     
  14. Jons

    Jons Spider

    Messages:
    14
    GitHub:
    jonsmc
    I think it wont work since the code might ran before it set block and add tile, tried this before but failed
     
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
  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.