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

Open chest/enderchest inventory

Discussion in 'Development' started by xBeastMode, Mar 5, 2017.

  1. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    How can I open a chest or an enderchest window on a players screen? Although there's no errors when executing the "/ender" command which is supposed to open an enderchest window, the enderchest window does not open at all.

    Here's my latest code:
    PHP:
    /**
         * @param Player $p
         */
        
    public function openWindow(Player $p){
            
    $eChestCfg PocketLegionCore::getInstance()->getConfig()->getAll()["ender_chest_position"];
            
    $x = (int)$eChestCfg["x"];
            
    $y = (int)$eChestCfg["y"];
            
    $z = (int)$eChestCfg["z"];
            
    $level PocketLegionCore::getInstance()->getServer()->getLevelByName($eChestCfg["level"]);

            
    $eChest = new EnderChestInventory($p);

            
    $eChest->openAt(new Position($x$y$z$level));
        }
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    What is EnderChestInventory?
     
  3. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    EnderChestInventory is a class for the ender chest invetory. It's not implemented in PocketMine though so I'm wondering if there is another way to open an enderchest window to a player's screen. :D
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    The code you sent isn't causing the problem. The only real method being called is inside EnderChestInventory, which we know absolutely nothing about, therefore we can't point out whatever may be wrong with it.
     
  5. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    It's a class from Genisys but there's no support for that here so I want to know a different way.
     
    Muqsit likes this.
  6. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Okay. This post exemplifies a lot, but you can use $player->addWindow($chest); with $player being an instance of pocketmine\Player, and $chest being an instance of pocketmine\tile\Chest.
     
  7. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Are there currently any API or Class that automatically saves items? It's a struggle having to create a database and having to write all that code for just for private vaults; obviously I'm not going to save items in a YAML file it would be stupid.
     
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I don't think there is.
     
  9. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Actually it should be $chest being an instance of pocketmine\inventory\ChestInventory
    To use this method you need to spawn a chest block to the player, either setblock or use sendblocks
    If you want to save items in yaml that is completely possible, see https://github.com/diamond-gold/MiniBosses/blob/master/src/MiniBosses/Main.php#L105, to convert from string to Item https://github.com/diamond-gold/MiniBosses/blob/master/src/MiniBosses/Boss.php#L59
     
    corytortoise likes this.
  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.