Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
}
}
@thebigsmileXD

This comment has been minimized.

Copy link

@thebigsmileXD thebigsmileXD commented Mar 21, 2016

Doesn't work anymore.

@iksaku

This comment has been minimized.

Copy link
Owner Author

@iksaku 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

This comment has been minimized.

Copy link

@ArrowDCA ArrowDCA commented May 9, 2016

can u make a trade system with virtualchest

@File14

This comment has been minimized.

Copy link

@File14 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
You can’t perform that action at this time.