Skip to content

Instantly share code, notes, and snippets.

@iksaku
Created June 11, 2015 21:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save iksaku/a4c3948c41cb4a21d17d to your computer and use it in GitHub Desktop.
Save iksaku/a4c3948c41cb4a21d17d to your computer and use it in GitHub Desktop.
Way to open virtual custom inventories in MCPE :D (Work in progress...) Special thanks to @alejandroliu and @PEMapModder for a previous research :3
<?php
/**
* @name VirtualInventories
* @main VirtualInventories\Loader
* @version 1.0.0
* @api 1.12.0
* @description Way to open virtual custom inventories
* @author iksaku
*/
namespace VirtualInventories{
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginIdentifiableCommand;
use pocketmine\inventory\ChestInventory;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\String;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\tile\Chest;
use pocketmine\tile\Tile;
class Loader extends PluginBase{
public function onEnable(){
$this->getServer()->getCommandMap()->register("VirtualInventories", new VirtualCommand($this));
$this->virtualChest();
}
/** @var null|Chest */
private $fakeChest = null;
/**
* @return Chest
*/
private function fakeChestTile(){
if($this->fakeChest === null){
$this->fakeChest = new Chest($this->getServer()->getDefaultLevel()->getChunk(0 >> 4, 0>> 4), new Compound("VirtualChest", [
new Enum("Items", []),
new String("id", Tile::CHEST),
new Int("x", 0),
new Int("y", 0),
new Int("z", 0)
]));
}
return $this->fakeChest;
}
/** @var null|ChestInventory */
private $virtualChest = null;
/**
* @return ChestInventory
*/
public function virtualChest(){
if($this->virtualChest === null){
$this->virtualChest = new ChestInventory($this->fakeChestTile());
}
return $this->virtualChest;
}
}
class VirtualCommand extends Command implements PluginIdentifiableCommand{
/** @var Loader */
private $plugin;
/**
* @param Loader $plugin
*/
public function __construct(Loader $plugin){
parent::__construct("virtual", "Opens a virtual chest", null, ["v", "chest"]);
$this->plugin = $plugin;
}
/**
* @return Loader
*/
public function getPlugin(){
return $this->plugin;
}
/**
* @param CommandSender $sender
* @param string $alias
* @param array $args
* @return bool
*/
public function execute(CommandSender $sender, $alias, array $args){
if(!$sender instanceof Player){
return false;
}
$sender->addWindow($this->getPlugin()->virtualChest());
return true;
}
}
}
@inxomnyaa
Copy link

Doesn't work anymore.

@iksaku
Copy link
Author

iksaku commented May 5, 2016

I haven't tried to update this script, but in prior versions, you needed to put a physical chest at coordinates (0,0,0) where the virtual compound is located, open it and then you would be able to acces it

@ArrowDCA
Copy link

ArrowDCA commented May 9, 2016

can u make a trade system with virtualchest

@File14
Copy link

File14 commented Jun 25, 2016

Is this working? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment