Hey there, for a minigame I have to fill chests with items. I want to get the chests with $level->getTile($chestPos) but that returns null sometimes and I really don't know why, because I am sure that there is a chest at the position. Maybe someone knows this problem or can help me.
That chunk may not be loaded That chunk may be unloaded Some error made the tile be deleted, for example, setting blocks through a world editor.
Say, if your position is saved in a Vector3 $v and Level object in $lv: PHP: $lv->loadChunk($v->x >> 4, $v->z >> 4); >> 4 converts the X coordinate of the block into the X order of the chunk.
I tried to load the chunk but that doesn't seem to be the problem. I will try creating the tile in the code now.
Yes in the line after that. Looks like this: PHP: $level->loadChunk($chestPositions[1]->x >> 4, $chestPositions[1]->z >> 4);$chest1 = $level->getTile($chestPositions[1]);$inv = $chest1->getInventory(); Edit: I have some chests on the same level, where no players are while I'm testing, and there I don't get the error. Maybe it could be because I placed the chests where the error comes with 1.6? Edit2: I changed some of the old chests placed in 1.4 (or something before 1.6) to new chests and there I can get the tile. So that's not the problem. Edit3: When I do getBlockIdAt(the position of the chest) it gives 0, so there seems to be nothing. But why?
#3: that means the chunk is not loaded. Can you answer my question? Did you check it immediately after unloading chink? BTW, is your array an int/float array?
Now I've added this code before the getTile(): PHP: $block = new \pocketmine\block\Chest();$level->setBlock($chestPositions[1], $block, true, true);$this->main->getLogger()->info("TTT: ".$level->getBlockIdAt($chestPositions[1]->x, $chestPositions[1]->y, $chestPositions[1]->z)); $nbt = new Compound("", [ new Enum("Items", []), new String("id", Tile::CHEST), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z) ]);$nbt->Items->setTagType(NBT::TAG_Compound);$tile = Tile::createTile("Chest", $level->getChunk($this->x >> 4, $this->z >> 4), $nbt); So there must be a tile but the getTile() function still return null.
Yes I checked if the chunk is loaded with this: PHP: $chunkLoaded = $level->isChunkLoaded($chestPositions[1]->x >> 4, $chestPositions[1]->z >> 4);if($chunkLoaded) { $this->main->getLogger()->info("Loaded");}$chest1 = $level->getTile($chestPositions[1]); The array is an int => Vector3 array. So $chestPositions[1] is a Vector3.
I really don't understand it. I tried to open the chest and there's no problem with that. There is no difference between all the chests I placed but the new chests can't be getted by getTile().
Just for debug, can you dump or in some way output the return result of getTiles for the level? (We just need the array with the coordinates in it for investigating)
I'm not sure what I have to do so I've printed out var_dump($lv->getTiles()). Then the console logged this: (to long to post here) http://pastebin.com/jgLEqak5 If it's not that what you need, tell me what I have to do so that you can help me.
Thank you soo much! I found out that the tiles have different positions than the positions I was searching for them. But I don't know why I wrote the wrong positions, because I teleported me to the positions and then I was standing in the chest.