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

Enderchests

Discussion in 'Development' started by #A6543, Feb 17, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    Can I use the normal ChestInventory for Enderchests? Because I can't set Items in the EnserInv
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    I don't think ender chests are implemented yet
     
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    I implemented it myself to pmmp from a fork
     
  4. #A6543

    #A6543 Zombie

    Messages:
    267
    I want to use the ChestInventory like if you use an emerald as an snowball or enderpearl
     
    StuntzCo likes this.
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    If you are running a custom build, then we aren't going to be able to help on this forum
     
    StuntzCo, Muqsit and InspectorGadget like this.
  6. StuntzCo

    StuntzCo Baby Zombie

    Messages:
    197
    so like if i downloaded pmmp from poggit and changed i dunno a couple lines of code pertaining to an item u guys automatically opt out of helping said person persay
     
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    When they ask for help pertaining to said edit only, yes. We have no idea what may be changed/possibly broken in his software. Pocketmine is open source for a reason. Supporting unofficial edits of PM has caused the creation of forks and spoons, which have themselves created enmity. If you want something reasonable added to the software, you have the option to create a pull request and add it yourself, or ask somebody else to.

    On a helpful note, you could use ChestInventory(AFAIK), however, you would need to implement a method of saving and loading the inventory for each player, and this requires a lot of data management. If you are certain that you want to do this, I strongly suggest you implement the Ender Chest in a plugin rather than the software. This would provide several advantages over editing the software.
     
    StuntzCo, jasonwynn10 and Muqsit like this.
  8. StuntzCo

    StuntzCo Baby Zombie

    Messages:
    197
    no i understand what your saying is completely logical since messing with a few lines of code could screw up the server completely
     
    jasonwynn10 likes this.
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    At least tell us what you've changed :/
     
  10. SuperDude36

    SuperDude36 Spider Jockey

    Messages:
    26
    GitHub:
    superdude36
    Genysis supports EnderChests fine.
     
  11. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    This is not a support forum for Genisys is it? If said spoons implementation works fine why not port it to a plugin or make a pr to add it directly to PMMP?
     
    xXSirButterXx and corytortoise like this.
  12. SuperDude36

    SuperDude36 Spider Jockey

    Messages:
    26
    GitHub:
    superdude36
    Can't you just replace Genisys's EnderChest.php with PMMP's?
     
  13. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    No, you can't. A lot of files are intertwined in the software. You need to register the class, add use statements, etc. in other files, so it isn't nearly as simple as just copying a file in. You also have to consider the differences in the rest of the software that may break/change things.
     
  14. SuperDude36

    SuperDude36 Spider Jockey

    Messages:
    26
    GitHub:
    superdude36
    Oh, sorry, I thought I was being helpful, I should've known I'm a noob at code XD
     
  15. Aviv

    Aviv Baby Zombie

    Messages:
    156
    Well heres my code for pvs (player vaults: like multiple enderchests inventories that can be accessed with a command)
    to save the items:
    PHP:
        public function savePv(Player $player$pvnumberInventory $inventory){
            
    $cfg $this->getPvConfig($player);
            
    $content = [];
            for(
    $i 0;$i $inventory->getSize();$i++){
                
    $item $inventory->getItem($i);
                
    $cfg->setNested($pvnumber.".".$i, [$item->getId(), $item->getDamage(), $item->getCount(), utf8_encode($item->getCompoundTag())]); // utf8_encode is required because some item names hasnt utf8 supported symbols so this fixed it, reverse it with utf8_decode
            
    }
            
    $cfg->save();
            return 
    true;
        }
    Also, you gotta make the getPvConfig function. just make a config for each player when they join and get it using this function.
    yes, maybe its too much to store in 1 config, lol.
    to open the inventory with items:
    PHP:
        public function getPv(Player $player$pvnumber){
            if(!
    is_numeric($pvnumber)){
                
    $pvnumber 1;
            }
            
    $cfg $this->getPvConfig($player);
            if(isset(
    $cfg->getAll()[$pvnumber])){
                return 
    $cfg->get($pvnumber);
            }else{
                
    $cfg->set($pvnumber, []);
                
    $cfg->save();
                
    $player->sendMessage(TF::RESET.TF::YELLOW."PV {$pvnumber} has been created!");
            }
            return [];
        }

        public function 
    getItemFromArray(Array $array){
            
    $itemId $array[0];
            
    $itemDamage $array[1];
            
    $itemCount $array[2];
            
    $itemNbt utf8_decode($array[3]); // reverting the utf8_encode, item's nbt is back to normal
            
    $item Item::get($itemId$itemDamage$itemCount);
            
    $item->setCompoundTag($itemNbt);
            return 
    $item;
        }

        public function 
    openPv(Player $player$pvnumber){
            
    $inventory $this->getPv($player$pvnumber);
            
    $block Block::get(54);
            
    $block->floor($player->x);
            
    $block->floor($player->y)-2;
            
    $block->floor($player->z);
            
    $block->level $player->level;
            
    $player->level->sendBlocks([$player],[$block]);
            
    $nbt = new CompoundTag("", [
                new 
    ListTag("Items", []),
                new 
    StringTag("id"Tile::CHEST),
                new 
    IntTag("x"$block->x),
                new 
    IntTag("y"$block->y),
                new 
    IntTag("z"$block->z)
            ]);
            
    $nbt->Items->setTagType(NBT::TAG_Compound);
            
    $tile Tile::createTile('Chest'$player->chunk$nbt);
            
    $customInv = new ChestInventory($tile);
            
    $tile->setName(TF::DARK_GRAY."Vault #".$pvnumber);
            
    $customInv->setSize(54);
            
    $this->openingPV[$player->getName()] = $pvnumber;
            foreach(
    $inventory as $slot=>$itemArray){
                
    $customInv->setItem($slot$this->getItemFromArray($itemArray));
            }
            
    $player->addWindow($customInv);
        }
     
        public function 
    onopenPV(InventoryOpenEvent $event){
            if(isset(
    $this->openingPV[$event->getPlayer()->getName()])){
                
    $this->openingPVInventory[$event->getPlayer()->getName()] = $event->getInventory();
            }
        }
     
        public function 
    onclosePV(InventoryCloseEvent $event){
            if(isset(
    $this->openingPV[$event->getPlayer()->getName()])){
                unset(
    $this->openingPVInventory[$event->getPlayer()->getName()]);
                
    $this->savePv($event->getPlayer(), $this->openingPV[$event->getPlayer()->getName()], $event->getInventory());
                unset(
    $this->openingPV[$event->getPlayer()->getName()]);
            }
        }
     
        public function 
    onpvQuit(PlayerQuitEvent $event){
            if(isset(
    $this->openingPV[$event->getPlayer()->getName()])){
                
    $this->savePv($event->getPlayer(), $this->openingPV[$event->getPlayer()->getName()], $this->openingPVInventory[$event->getPlayer()->getName()]);
                unset(
    $this->openingPV[$event->getPlayer()->getName()]);
                unset(
    $this->openingPVInventory[$event->getPlayer()->getName()]);
            }
        }
     
  16. Aviv

    Aviv Baby Zombie

    Messages:
    156
    thats just an example if you wanna make enderchests with plugins
     
    Jackins likes this.
  17. Jackins

    Jackins Slime

    Messages:
    92
    Can i have all the plugin? Phar or zip... Doesn't matter... Please
     
  18. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    This isn't the plugin request section. The provided code should assist you in your project.
     
    jasonwynn10 likes this.
  19. Jackins

    Jackins Slime

    Messages:
    92
    Ookk...
     
  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.