Ok, so i spawn a chest with the following code: PHP: if ($block == 54) { // Populate Chest $items = array(); for ($x = 0; $x < 27; $x++) { $chance = rand(0, 9); if ($chance < 3) { // 30% chance of spawning something $items[$x] = $this->getRandomFeastItem(); } } $nbt = new Compound(false, array( new Enum("Items", []), new String("id", Tile::CHEST), new Int("x", $xPos + $xRel), new Int("y", $yPos + $yRel), new Int("z", $zPos + $zRel) )); $nbt->Items->setTagType(NBT::TAG_Compound); $chest = new \pocketmine\tile\Chest($level->getChunk(($xPos + $xRel) >> 4, ($zPos + $xRel) >> 4), $nbt); $level->addTile($chest); $pos = new \pocketmine\level\Position($chest->getFloorX(), $chest->getFloorY(), $chest->getFloorZ(), $chest->getLevel()); $task = new FillChestTask($pos, $items); TruHG::getInstance()->getServer()->getScheduler()->scheduleDelayedTask($task, 1); $chestX = $xPos + $xRel; $chestY = $yPos + $yRel; $chestZ = $zPos + $zRel;} All i've had to go by is existing plugin sources and searching the pocketmine docs. The FillChestTask is as follows: PHP: class FillChestTask extends PluginTask { /** * * @var Position Position */ private $pos; /** * * @var Item[] Items */ private $items; public function __construct($pos, $items) { parent::__construct(\TruDan\TruHG\TruHG::getInstance()); $this->pos = $pos; $this->items = $items; } public function onRun($tick) { $tile = $this->pos->getLevel()->getTile($this->pos); if($tile instanceof Chest) { $inv = $tile->getRealInventory(); foreach($this->items as $slot => $item) { $inv->setItem($slot, $item); } } \TruDan\TruHG\TruHG::getInstance()->getLogger()->info("Filled Chest."); }} I first tried this without the delayed task, but instead just straight away. Yet it has the same results as with the delayed task. However, when it spawns in, the inventory is displayed on the left hand side (where player inventory should be), and not the right. Any Ideas, I'm not sure if this is some kind of bug with chests, or if i have missed something?
I tried it without the task, and doing it directly, which produced the same results. I also tried pre-defining the items in the Items enum. Also no luck. =/
I looked there also, thats actually where i got the idea to do a fill task from. The strange thing is, it appears to put the contents there, because when you open the chest it shows the inventory, its just showing on the players side rather than the chests side.